示例#1
0
def login_failure(message, failure_reason, form):
    """
    Handles a failed login by creating an appropriate history entry
    and redirecting the user.

    Args:
        message: The message to flash to the user.
        failure_reason: The reason to record on the history entry
            for the failure.
        form: The associated login form.

    Returns:
        The appropriate redirection to the login form.
    """
    flash(message)

    # Create login history
    hist = LoginHistory()
    hist.username = form.username.data
    hist.ip = get_ip()
    hist.successful = False
    hist.failure_reason = failure_reason
    db.session.add(hist)
    db.session.commit()

    return render_template('login.html', form=form), 401
示例#2
0
def login_failure(message, failure_reason, form):
    """
    Handles a failed login by creating an appropriate history entry
    and redirecting the user.

    Args:
        message: The message to flash to the user.
        failure_reason: The reason to record on the history entry
            for the failure.
        form: The associated login form.

    Returns:
        The appropriate redirection to the login form.
    """
    flash(message)

    # Create login history
    hist = LoginHistory()
    hist.username = form.username.data
    hist.ip = get_ip()
    hist.successful = False
    hist.failure_reason = failure_reason
    db.session.add(hist)
    db.session.commit()

    return render_template('login.html', form=form), 401      
示例#3
0
def login_success(user):
    """
    Handles a successful login by creating a login history
    entry and calling login_user.

    Args:
        user: The user to log in.
    """
    # Create login history
    hist = LoginHistory()
    hist.username = user.username
    hist.ip = get_ip()
    hist.successful = True
    db.session.add(hist)
    db.session.commit()

    # Login the user
    login_user(user, True)
示例#4
0
def login_success(user):
    """
    Handles a successful login by creating a login history
    entry and calling login_user.

    Args:
        user: The user to log in.
    """
    # Create login history
    hist = LoginHistory()
    hist.username = user.username
    hist.ip = get_ip()
    hist.successful = True
    db.session.add(hist)
    db.session.commit()

    # Login the user
    login_user(user, True)