Exemplo n.º 1
0
def set_user_context(uid=None, email=None):
    if email:
        user = User.get(User.email == email.lower())
    else:
        user = User.get(User.id == uid)
    sid = sessionslib.create(user.id, user.groups)
    context.set_context(uid=user.id, sid=sid, groups=user.groups)
Exemplo n.º 2
0
def authenticate(email, password='', _oauthed=False):
    """
    returns session if successful else returns None
    """
    if not validate_email(email):
        raise InvalidEmailError(email)
    email = email.lower()
    user = User.get(User.email == email)
    if not user:
        raise EmailiDoesNotExistError(email)
    if _oauthed:
        return sessionslib.create(user.id,
                                  user.groups,
                                  extras={
                                      'email': email,
                                      'name': user.name
                                  })
    if user.password == encrypt(password, settings.SALT):
        return sessionslib.create(user.id,
                                  user.groups,
                                  extras={
                                      'email': email,
                                      'name': user.name
                                  })
    raise AuthError(email)
Exemplo n.º 3
0
def uid_by_email(email):
    """
    -> user or None
    """
    #User.get().where(User.email == email.lower())
    try:
        user_id = User.get(User.email == email.lower())
    except User.DoesNotExist:
        user_id = None
    return user_id
Exemplo n.º 4
0
def authenticate(email, password):
    """
    returns session if successful else returns None
    """
    if not validate_email(email):
        raise InvalidEmailError(email)
    user = User.get(User.email == email.lower())
    if not user:
        raise EmailiDoesNotExistError(email)
    if user.password == encrypt(password, settings.SALT):
        return sessionslib.create(user.id, user.groups)
    raise AuthError(email)