Example #1
0
 def change_password(self, user_id, password, new_password):
   user_id = user_id.lower()
   account = self.db.get("select account_id, user_id, password from account where user_id = %s", user_id)
   if not account or not secret.verify_password(password, account['password']):
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   self.db.execute("update account set password = %s where account_id = %s", secret.password_hash(new_password), account['account_id'])
   self.clear_sessions(user_id)
Example #2
0
 def create_account(self, user_id, password, additional_values={}, **values):
   if self.db.accounts.find_one({'user_id': user_id}):
     raise TotoException(ERROR_USER_ID_EXISTS, "User ID already in use.")
   values.update(additional_values)
   values['user_id'] = user_id
   values['password'] = secret.password_hash(password)
   self.db.accounts.insert(values)
Example #3
0
 def change_password(self, user_id, password, new_password):
   user_id = user_id.lower()
   account_key = _account_key(user_id)
   account = self.db.hmget(account_key, 'user_id', 'password')
   if account[0] != user_id or not secret.verify_password(password, account[1]):
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   self.db.hset(account_key, 'password', secret.password_hash(new_password))
Example #4
0
 def create_account(self, user_id, password, additional_values={}, **values):
   user_id = user_id.lower()
   if self.db.get("select account_id from account where user_id = %s", (user_id,)):
     raise TotoException(ERROR_USER_ID_EXISTS, "User ID already in use.")
   values.update(additional_values)
   values['user_id'] = user_id
   values['password'] = secret.password_hash(password)
   self.db.execute("insert into account (" + ', '.join([k for k in values]) + ") values (" + ','.join(['%s' for k in values]) + ")", [values[k] for k in values])
Example #5
0
 def generate_password(self, user_id):
   user_id = user_id.lower()
   account_key = _account_key(user_id)
   if self.db.hget(account_key, 'user_id') != user_id:
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   pass_chars = string.ascii_letters + string.digits 
   new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
   self.db.hset(account_key, 'password', secret.password_hash(new_password))
   return new_password
Example #6
0
 def generate_password(self, user_id):
   account = self.db.accounts.find_one({'user_id': user_id})
   if not account:
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   pass_chars = string.ascii_letters + string.digits 
   new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
   self.db.accounts.update({'user_id': user_id}, {'$set': {'password': secret.password_hash(new_password)}})
   self.clear_sessions(user_id)
   return new_password
Example #7
0
 def create_account(self, user_id, password, additional_values={}, **values):
   user_id = user_id.lower()
   account_key = _account_key(user_id)
   if self.db.exists(account_key):
     raise TotoException(ERROR_USER_ID_EXISTS, "User ID already in use.")
   values.update(additional_values)
   values['user_id'] = user_id
   values['password'] = secret.password_hash(password)
   self.db.hmset(account_key, values)
Example #8
0
 def change_password(self, user_id, password, new_password):
   '''Updates the password for the account with the given ``user_id`` and ``password`` to match
   ``new_password`` for all future requests.
   '''
   user_id = user_id.lower()
   account = self._get_account(user_id)
   if not account or not secret.verify_password(password, account['password']):
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   self._update_password(user_id, account, secret.password_hash(new_password))
Example #9
0
 def generate_password(self, user_id):
   user_id = user_id.lower()
   account = self.db.get("select account_id, user_id from account where user_id = %s", user_id)
   if not account:
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID")
   pass_chars = string.ascii_letters + string.digits
   new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
   self.db.execute("update account set password = %s where account_id = %s", secret.password_hash(new_password), account['account_id'])
   self.clear_sessions(user_id)
   return new_password
Example #10
0
 def change_password(self, user_id, password, new_password):
     user_id = user_id.lower()
     account_key = _account_key(user_id)
     account = self.db.hmget(account_key, 'user_id', 'password')
     if account[0] != user_id or not secret.verify_password(
             password, account[1]):
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     self.db.hset(account_key, 'password',
                  secret.password_hash(new_password))
Example #11
0
 def generate_password(self, user_id):
     user_id = user_id.lower()
     account_key = _account_key(user_id)
     if self.db.hget(account_key, 'user_id') != user_id:
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     pass_chars = string.ascii_letters + string.digits
     new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
     self.db.hset(account_key, 'password',
                  secret.password_hash(new_password))
     return new_password
Example #12
0
 def change_password(self, user_id, password, new_password):
     account = self.db.accounts.find_one({'user_id': user_id})
     if not account or not secret.verify_password(password,
                                                  account['password']):
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     self.db.accounts.update(
         {'user_id': user_id},
         {'$set': {
             'password': secret.password_hash(new_password)
         }})
     self.clear_sessions(user_id)
Example #13
0
 def change_password(self, user_id, password, new_password):
     '''Updates the password for the account with the given ``user_id`` and ``password`` to match
 ``new_password`` for all future requests.
 '''
     user_id = user_id.lower()
     account = self._get_account(user_id)
     if not account or not secret.verify_password(password,
                                                  account['password']):
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     self._update_password(user_id, account,
                           secret.password_hash(new_password))
Example #14
0
 def generate_password(self, user_id):
   '''Generates a new password for the account with the given ``user_id`` and makes it active
   for all future requests. The new password will be returned. This method is designed to
   support "forgot password" functionality.
   '''
   user_id = user_id.lower()
   account = self._get_account(user_id)
   if not account:
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID")
   pass_chars = string.ascii_letters + string.digits
   new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
   self._update_password(user_id, account, secret.password_hash(new_password))
   return new_password
Example #15
0
 def create_account(self, user_id, password, additional_values={}, **values):
   if not user_id:
     raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
   user_id = user_id.lower()
   if self.db.get("select account_id from account where user_id = %s", user_id):
     raise TotoException(ERROR_USER_ID_EXISTS, "User ID already in use.")
   additional_values.pop('account_id', None)
   values.update(additional_values)
   values['user_id'] = user_id
   values['password'] = secret.password_hash(password)
   if self.uuid_account_id:
     values['account_id'] = uuid4().bytes
   self.db.execute("insert into account (" + ', '.join([k for k in values]) + ") values (" + ','.join(['%s' for k in values]) + ")", *[values[k] for k in values])
Example #16
0
 def change_password(self, user_id, password, new_password):
     user_id = user_id.lower()
     account = self.db.get(
         "select account_id, user_id, password from account where user_id = %s",
         user_id)
     if not account or not secret.verify_password(password,
                                                  account['password']):
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     self.db.execute(
         "update account set password = %s where account_id = %s",
         secret.password_hash(new_password), account['account_id'])
     self.clear_sessions(user_id)
Example #17
0
 def create_account(self,
                    user_id,
                    password,
                    additional_values={},
                    **values):
     if not user_id:
         raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
     if self.db.accounts.find_one({'user_id': user_id}):
         raise TotoException(ERROR_USER_ID_EXISTS,
                             "User ID already in use.")
     values.update(additional_values)
     values['user_id'] = user_id
     values['password'] = secret.password_hash(password)
     self.db.accounts.insert(values)
Example #18
0
 def generate_password(self, user_id):
     user_id = user_id.lower()
     account = self.db.get(
         "select account_id, user_id from account where user_id = %s",
         user_id)
     if not account:
         raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID")
     pass_chars = string.ascii_letters + string.digits
     new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
     self.db.execute(
         "update account set password = %s where account_id = %s",
         secret.password_hash(new_password), account['account_id'])
     self.clear_sessions(user_id)
     return new_password
Example #19
0
 def generate_password(self, user_id):
     '''Generates a new password for the account with the given ``user_id`` and makes it active
 for all future requests. The new password will be returned. This method is designed to
 support "forgot password" functionality.
 '''
     user_id = user_id.lower()
     account = self._get_account(user_id)
     if not account:
         raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID")
     pass_chars = string.ascii_letters + string.digits
     new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
     self._update_password(user_id, account,
                           secret.password_hash(new_password))
     return new_password
Example #20
0
 def generate_password(self, user_id):
     account = self.db.accounts.find_one({'user_id': user_id})
     if not account:
         raise TotoException(ERROR_USER_NOT_FOUND,
                             "Invalid user ID or password")
     pass_chars = string.ascii_letters + string.digits
     new_password = ''.join([random.choice(pass_chars) for x in xrange(10)])
     self.db.accounts.update(
         {'user_id': user_id},
         {'$set': {
             'password': secret.password_hash(new_password)
         }})
     self.clear_sessions(user_id)
     return new_password
Example #21
0
 def create_account(self,
                    user_id,
                    password,
                    additional_values={},
                    **values):
     if not user_id:
         raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
     user_id = user_id.lower()
     account_key = _account_key(user_id)
     if self.db.exists(account_key):
         raise TotoException(ERROR_USER_ID_EXISTS,
                             "User ID already in use.")
     values.update(additional_values)
     values['user_id'] = user_id
     values['password'] = secret.password_hash(password)
     self.db.hmset(account_key, values)
Example #22
0
  def create_account(self, user_id, password, additional_values={}, **values):
    '''Create an account for the given ``user_id`` and ``password``. Optionally set additional account
      values by passing them as keyword arguments (the ``additional_values`` parameter is deprecated).

      Note: if your database uses a predefined schema, make sure to create the appropriate columns
      before passing additional arguments to ``create_account``.
    '''
    if not user_id:
      raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
    user_id = user_id.lower()
    account = self._get_account(user_id)
    if account:
      raise TotoException(ERROR_USER_ID_EXISTS, "User ID already in use.")
    values.update(additional_values)
    values['user_id'] = user_id
    values['password'] = secret.password_hash(password)
    self._store_account(user_id, values)
Example #23
0
 def create_account(self,
                    user_id,
                    password,
                    additional_values={},
                    **values):
     if not user_id:
         raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
     user_id = user_id.lower()
     if self.db.get("select account_id from account where user_id = %s",
                    (user_id, )):
         raise TotoException(ERROR_USER_ID_EXISTS,
                             "User ID already in use.")
     values.update(additional_values)
     values['user_id'] = user_id
     values['password'] = secret.password_hash(password)
     self.db.execute(
         "insert into account (" + ', '.join([k for k in values]) +
         ") values (" + ','.join(['%s' for k in values]) + ")",
         [values[k] for k in values])
Example #24
0
    def create_account(self,
                       user_id,
                       password,
                       additional_values={},
                       **values):
        '''Create an account for the given ``user_id`` and ``password``. Optionally set additional account
      values by passing them as keyword arguments (the ``additional_values`` parameter is deprecated).

      Note: if your database uses a predefined schema, make sure to create the appropriate columns
      before passing additional arguments to ``create_account``.
    '''
        if not user_id:
            raise TotoException(ERROR_INVALID_USER_ID, "Invalid user ID.")
        user_id = user_id.lower()
        account = self._get_account(user_id)
        if account:
            raise TotoException(ERROR_USER_ID_EXISTS,
                                "User ID already in use.")
        values.update(additional_values)
        values['user_id'] = user_id
        values['password'] = secret.password_hash(password)
        self._store_account(user_id, values)
Example #25
0
 def change_password(self, user_id, password, new_password):
   account = self.db.accounts.find_one({'user_id': user_id})
   if not account or not secret.verify_password(password, account['password']):
     raise TotoException(ERROR_USER_NOT_FOUND, "Invalid user ID or password")
   self.db.accounts.update({'user_id': user_id}, {'$set': {'password': secret.password_hash(new_password)}})
   self.clear_sessions(user_id)