Blame view

service/account/account_service.py 1.28 KB
831eac332   zhuzhenchao   add file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  # coding:utf-8
  import logging
  import traceback
  from django.contrib import auth
  
  
  class AccountService(object):
      """
      用户相关服务
      """
      def __init__(self, model, request):
          self.model = model
          self.request = request
  
      def get_login_next_url(self):
          """
          登录后跳转地址
          """
          try:
              source_url = self.request.META.get('HTTP_REFERER','/')
              if 'next=' in source_url:
                  next_url = self.request.META.get('HTTP_REFERER').split("next=")[1]
              else:
                  next_url='/'
              return next_url
          except Exception, e:
              logging.warning(traceback.format_exc())
              return '/'
  
      def user_auth_local(self, username, password):
          """
          本地系统验证
          """
          try:
              user = auth.authenticate(username=username, password=password)
              return user
          except Exception, e:
              logging.error(traceback.format_exc())
              return None
  
      def user_login(self, user):
          """
          登录
          """
          try:
              auth.login(self.request, user)
              return True, ''
          except Exception, e:
              logging.error(traceback.format_exc())
              return False, e.messge