示例#1
0
文件: users.py 项目: Zhanelya/sprks
 def check_credentials(cls, username, password):
     """
     Returns ID of user if credentials match, 0 otherwise.
     """
     password = hash_utils.hash_password(password)
     auth = db.select('users', where="username=$username&&password=$password", vars=locals())
     if len(auth) == 1:
         return auth[0].user_id
     else:
         return 0
示例#2
0
 def check_credentials(cls, username, password):
     """
     Returns ID of user if credentials match, 0 otherwise.
     """
     password = hash_utils.hash_password(password)
     auth = db.select('users',
                      where="username=$username&&password=$password",
                      vars=locals())
     if len(auth) == 1:
         return auth[0].user_id
     else:
         return 0
示例#3
0
文件: users.py 项目: Zhanelya/sprks
    def update_password(cls, user_id, password):
        """
        Updates password according to specified user_id and new password.
        Returns true if updated for one user or password unchanged, false otherwise.
        """
        user_list = cls.select_users(user_id=user_id)
        password_hash = hash_utils.hash_password(password)
        if len(user_list) == 1 and password_hash == user_list[0].password:
            return True

        if db.update('users', where="user_id=$user_id", password=password_hash, vars=locals()) \
                == 1:
            return True

        return False
示例#4
0
    def update_password(cls, user_id, password):
        """
        Updates password according to specified user_id and new password.
        Returns true if updated for one user or password unchanged, false otherwise.
        """
        user_list = cls.select_users(user_id=user_id)
        password_hash = hash_utils.hash_password(password)
        if len(user_list) == 1 and password_hash == user_list[0].password:
            return True

        if db.update('users', where="user_id=$user_id", password=password_hash, vars=locals()) \
                == 1:
            return True

        return False
示例#5
0
文件: users.py 项目: Zhanelya/sprks
 def register(cls, username, password, email):
     """
     Attempts to insert new user data into users table.
     Returns ID of user if successfully registered, 0 if user already exists, -1 if database error.
     """
     if len(cls.select_users(username=username)) > 0:
         return 0
     else:
         if username == '' or email == '':
             return -1
         db.insert('users', username=username, email=email, password=hash_utils.hash_password(password))
         user_lookup = cls.select_users(username=username)
         if len(user_lookup) == 1:
             return user_lookup[0].user_id
         else:
             return -1
示例#6
0
 def register(cls, username, password, email):
     """
     Attempts to insert new user data into users table.
     Returns ID of user if successfully registered, 0 if user already exists, -1 if database error.
     """
     if len(cls.select_users(username=username)) > 0:
         return 0
     else:
         if username == '' or email == '':
             return -1
         db.insert('users',
                   username=username,
                   email=email,
                   password=hash_utils.hash_password(password))
         user_lookup = cls.select_users(username=username)
         if len(user_lookup) == 1:
             return user_lookup[0].user_id
         else:
             return -1