当前位置: 首页>>代码示例>>Python>>正文


Python ModelBackend.get_user方法代码示例

本文整理汇总了Python中django.contrib.auth.backends.ModelBackend.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python ModelBackend.get_user方法的具体用法?Python ModelBackend.get_user怎么用?Python ModelBackend.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.backends.ModelBackend的用法示例。


在下文中一共展示了ModelBackend.get_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_authenticate_fail

# 需要导入模块: from django.contrib.auth.backends import ModelBackend [as 别名]
# 或者: from django.contrib.auth.backends.ModelBackend import get_user [as 别名]
    def test_authenticate_fail(self):
        self.moxx.StubOutWithMock(ModelBackend, 'get_user')
        ModelBackend.get_user(self.user.pk).AndReturn(None)

        self.moxx.ReplayAll()
        user = utils.authenticate_without_password(self.user)
        self.moxx.VerifyAll()

        self.assertEqual(user, None)
开发者ID:renoc,项目名称:personal-classalchemy,代码行数:11,代码来源:tests.py

示例2: ElectionAuthBackend

# 需要导入模块: from django.contrib.auth.backends import ModelBackend [as 别名]
# 或者: from django.contrib.auth.backends.ModelBackend import get_user [as 别名]
class ElectionAuthBackend(object):
    """
    Authenticate against django.contrib.auth.backends.ModelBackend AND ipauth.backend.RangeBackend
    Users must pass both sets of authentication to use the system
    """
    supports_anonymous_user = False
    ipauth_backend = None
    model_backend = None

    def __init__(self):
        self.ipauth_backend = RangeBackend()
        self.model_backend = ModelBackend()
    
    def authenticate(self, username=None, password=None, ip=None):
        """
        Authenticate against multiple backends AND'd together
        TODO: Election admin
        """
        model_user = self.model_backend.authenticate(username=username, password=password)
        ip_user = self.ipauth_backend.authenticate(ip=ip)        
        #print 'model_user', repr(model_user)
        #print 'model_user groups', repr(model_user.groups.all())
        #print 'ip_user', repr(ip_user)
        admin_group = Group.objects.filter(name='ADMIN').all()
        if admin_group.count() > 0:
          admin_group = admin_group[0]
        else:
          admin_group = None

        if not model_user:
            return None
        if model_user.is_superuser or model_user.is_staff: # Super admin
            return model_user
        if model_user.groups.count() > 0 and admin_group in model_user.groups.all(): # Election admin
            return model_user
        #if ip_user is None:
            #print 'Your IP=%s is not in the IPAuth' % (ip, )
            #return None
        return model_user

    def get_group_permissions(self, user_obj):
        """
        Returns a set of permission strings that this user has through his/her
        groups.
        """
        return self.model_backend.get_group_permissions(user_obj)

    def get_all_permissions(self, user_obj):
        return self.model_backend.get_all_permissions(user_obj)

    def has_perm(self, user_obj, perm):
        return self.model_backend.has_perm(user_obj, perm)

    def has_module_perms(self, user_obj, app_label):
        return self.model_backend.has_module_perms(user_obj, app_label)

    def get_user(self, user_id):
        return self.model_backend.get_user(user_id)
开发者ID:Hwesta,项目名称:bc-stv-voting-system,代码行数:60,代码来源:backend.py

示例3: get_session

# 需要导入模块: from django.contrib.auth.backends import ModelBackend [as 别名]
# 或者: from django.contrib.auth.backends.ModelBackend import get_user [as 别名]
    def get_session(self, sid, authenticated=False):
        self.env.log.debug('Retrieving session for ID %r', sid)
	
        #db = self.env.get_db_cnx()
        #cursor = db.cursor()
	
	ss = DjangoSessionStore(session_key=sid)
	
	if not ss.exists(sid):
	  ss.load()
	  ss.save()
	  sid = ss.session_key
	  self.env.log.warning('create new django session')

        self.sid = sid
        self.authenticated = authenticated
	
	try:
	
	  ds = DjangoSession.objects.get(pk=sid)

	  if not ds:
	    return

	  session_data = ds.get_decoded()

	  if session_data.has_key('_auth_user_id'):
	    mb = DjangoModelBackend()
	    self.django_user_data = mb.get_user(session_data['_auth_user_id'])
	    self.authenticated = self.django_user_data.is_authenticated()
	    self.last_visit = int(mktime(self.django_user_data.last_login.timetuple()))
	    self.env.log.debug('authenticated as %s',self.django_user_data.username)
	  else:
	    self.django_user_data = DjangoAnonymousUser()
	    self.last_visit = int(mktime(gmtime()))
	    self.env.log.debug('anonymous request')
	    
	except DjangoSession.objects.model.DoesNotExist:
	  self.env.log.error('session does not exist')
	  
        self._new = False
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:43,代码来源:session.py

示例4: get_user

# 需要导入模块: from django.contrib.auth.backends import ModelBackend [as 别名]
# 或者: from django.contrib.auth.backends.ModelBackend import get_user [as 别名]
 def get_user(self, user_id):
     auth_method = ModelBackend()
     user = auth_method.get_user(user_id)
     #TODO: Add merkabah security hooks Check ban status, ipbans, etc
     return user
开发者ID:agabingung,项目名称:merkabah,代码行数:7,代码来源:backends.py


注:本文中的django.contrib.auth.backends.ModelBackend.get_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。