예제 #1
0
 def login(cls, username, password, seconds=60 * 60 * 24):
     user = UserInfoDao.get_by_username(username)
     if not user:
         raise Exception('用户不存在')
     if password != user["password"]:
         raise Exception('密码错误')
     return cls.create_token(user, seconds)
예제 #2
0
 def register(username, password, seconds=60 * 60 * 24):
     user = UserInfoDao.get_by_username(username)
     if user:
         raise Exception('用户已存在')
     UserInfoDao.create_user(username, password)
     user = UserInfoDao.get_by_username(username)
     uid = user['uid']
     token = uuid.uuid1().hex
     expire_time = datetime.datetime.now() + datetime.timedelta(
         seconds=seconds)
     UserTokenDao.create_token(uid, token, expire_time)
     return {
         'uid': uid,
         'username': username,
         'token': token,
         'expire_time': expire_time,
     }
예제 #3
0
 def login(username, password, seconds=60 * 60 * 24):
     user = UserInfoDao.get_by_username(username)
     if not user:
         raise Exception('用户不存在,请先注册')
     uid = user['uid']
     print(uid)
     username = user['username']
     if password != user['password']:
         raise Exception('密码错误')
     token = uuid.uuid1().hex
     expire_time = datetime.datetime.now() + datetime.timedelta(
         seconds=seconds)
     UserTokenDao.create_token(uid, token, expire_time)
     return {
         'uid': uid,
         'username': username,
         'token': token,
         'expire_time': expire_time,
     }