Ejemplo n.º 1
0
def log_in_user(email, password):
    """
    Check the credentials are correct for logging in and set up session.
    Returns None if the credentials are incorrect.
    """
    user = User.get_by_email(email)
    if not user:
        return None

    if current_app.config.get('USER_REQUIRE_ACTIVATION', True) and not user.activated:
        return None

    key = user.unlock_key_with_password(password)
    if not key:
        return None

    user._unlocked_key = key
    session['user_id'] = user.id
    session['key'] = key.exportKey(
        format='PEM',
        pkcs=1,
        passphrase=current_app.secret_key
    )

    return user
Ejemplo n.º 2
0
def log_in_user(email, password):
    """
    Check the credentials are correct for logging in and set up session.
    Returns None if the credentials are incorrect.
    """
    user = User.get_by_email(email)
    if not user:
        return None

    if not user.activated:
        return None

    key = user.unlock_key_with_password(password)
    if not key:
        return None

    user._unlocked_key = key
    session['user_id'] = user.id
    session['key'] = key.exportKey(
        format='PEM',
        pkcs=1,
        passphrase=current_app.secret_key
    )

    return user