示例#1
0
def get_user(request):
    from cloudengine.users.models import AnonymousAppUser
    try:
        user_id = request.session[SESSION_KEY]
        backend = ModelBackend()
        user = backend.get_user(user_id) or AnonymousAppUser()
    except KeyError:
        user = AnonymousAppUser()
    if not hasattr(request, '_cached_app_user'):
        request._cached_app_user = user
    return request._cached_app_user
示例#2
0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a AppUser object.
    """
    backend = ModelBackend()
    user = backend.authenticate(**credentials)
    if user:
        return user

    app_user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))