<commit_before>Base = require '../argumenta/base'
Auth = require '../argumenta/auth'
User = require '../argumenta/user'

#
# Users models user accounts.
# It integrates the Storage, Auth, and User modules.
#
class Users extends Base

  ### Errors ###

  Error: @Error = @Errors.Users
  ValidationError: @ValidationError = @Errors.Validation
  StorageConflictError: @StorageConflictError = @Errors.StorageConflict
  StorageError: @StorageError = @Errors.Storage

  ### Constructor ###

  # Inits a Users instance.
  #
  # @param [Argumenta] argumenta An argumenta instance.
  # @param [Storage] storage A storage instance.
  constructor: (@argumenta, @storage) ->

  ### Instance Methods ###

  # Creates a user account.
  #
  # Example:
  #
  #     users.create username, password, email, (err, user) ->
  #       console.log "created account for #{user.username}!" unless err
  #
  # @param [String] username The user's username.
  # @param [String] password The user's password.
  # @param [String] email The user's email.
  # @param [Function] callback(err, user) Called on error or success.
  # @param [Error] err Any error.
  # @param [User] user The new user.
  create: (username, password, email, callback) ->

    try User.validatePassword password
    catch err
      return callback err, null

    Auth.hashPassword password, (err, hash) =>
      return callback err, null if err

      user = new User { username, password_hash: hash, email }

      @storage.addUser user, (err) =>
        return callback err, null if err
        return callback null, user

module.exports = Users<commit_msg>update users docs<commit_after>Base = require '../argumenta/base'
Auth = require '../argumenta/auth'
User = require '../argumenta/user'

#
# Users models user accounts.  
# It integrates the Storage, Auth, and User modules.
#
class Users extends Base

  ### Errors ###

  Error: @Error = @Errors.Users
  ValidationError: @ValidationError = @Errors.Validation
  StorageConflictError: @StorageConflictError = @Errors.StorageConflict
  StorageError: @StorageError = @Errors.Storage

  ### Constructor ###

  # Inits a Users instance.
  #
  # @api public
  # @param [Argumenta] argumenta An argumenta instance.
  # @param [Storage] storage A storage instance.
  constructor: (@argumenta, @storage) ->

  ### Instance Methods ###

  # Creates a user account.
  #
  # Example:
  #
  #     users.create username, password, email, (err, user) ->
  #       console.log "created account for #{user.username}!" unless err
  #
  # @api public
  # @param [String] username The user's username.
  # @param [String] password The <PASSWORD>'s password.
  # @param [String] email The user's email.
  # @param [Function] callback(err, user) Called on error or success.
  # @param [Error] err Any error.
  # @param [User] user The new user instance.
  create: (username, password, email, callback) ->

    try User.validatePassword password
    catch err
      return callback err, null

    Auth.hashPassword password, (err, hash) =>
      return callback err, null if err

      user = new User { username, password_hash: hash, email }

      @storage.addUser user, (err) =>
        return callback err, null if err
        return callback null, user

module.exports = Users
{'fraction_non_alphanumeric': 0.11714198098742717, 'fraction_numerical': 0.0, 'mean_word_length': 3.3377659574468086, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7526956', 'n_tokens_mistral': 954, 'n_tokens_neox': 921, 'n_words': 330}