Beispiel #1
0
 def changePassword(self, password, newpassword):
     '''
     修改用户密码
     @param password: 
     @param newpassword: 
     @return: 
     '''
     if not newpassword:
         raise ex(u'新密码不能为空')
     user = self.get_me()
     if user and user.password == User.pwdhash(password, user.salt):
         user.password = User.pwdhash(newpassword, user.salt)
         user.save()
     else:
         raise ex(u'原密码不正确!')
Beispiel #2
0
 def login(self, username, password):
     """
     用户登录
     @param username: 
     @param password: 
     @return: 
     """
     user = User.objects.filter(username=username).first()
     if user and user.password == User.pwdhash(password, user.salt):
         if user.status == User.STATUS_CANCELED:
             raise ex(u'该用户已被锁定无法登陆')
         self.session_set('me', user.get_json())
         self.logAtion(ActionLog.ACTION_LOGIN)
         logingoto = self.session_get_once('logingoto')
         return obj2dic(user, ['id', 'username', 'token'],
                        {'goto': logingoto or '/xadmin/'})
     else:
         raise ex(u'用户名或密码错误')