| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #coding=utf-8
- import logging
- import datetime
- import account.password_handle as ph
- from django.db.models import Q
- import common.error_info as ce
- import common.models as cm
- logger = logging.getLogger(__name__)
- class AccountManage(object):
- def authenticate(self,request,account,pwd):
- """
- @attention: 用户认证
- """
- user = cm.SysUserInfo.objects.filter(Q(name=account)).first()
- if user is not None:
- if self.user_can_authenticate(user):
- if ph.check_password(pwd, user.password):
- return user
- else:
- raise ce.TipException("账号或密码错误")
- else:
- raise ce.TipException("账户已停用")
- else:
- raise ce.TipException("账号或密码错误")
- def user_can_authenticate(self, user):
- """
- @attention: 账户是否已经激活
- """
- is_active = getattr(user, 'is_active', None)
- return is_active == 1
-
- def get_user(self, pk):
- """
- @attention: 由于在django系统中,每次request都是一个独立的请求,所以每次进入时第一次使用,都会调用该函数
- """
- try:
- user = cm.SysUserInfo.objects.get(pk=pk)
- except cm.SysUserInfo.DoesNotExist:
- return None
- return user
|