Example #1
0
def basic_authentication():
    """ Attempt HTTP basic authentication on a per-request basis. """
    if "Authorization" in request.headers:
        authorization = request.headers.get("Authorization")
        authorization = authorization.split(" ", 1)[-1]
        name, password = authorization.decode("base64").split(":", 1)
        account = Account.by_name(name)
        if account is None or not account.validate_password(password) or not login_user(account):
            raise Unauthorized("Invalid username or password.")
Example #2
0
def login_save():
    """ Create an account based on the sign-up form. """
    data = request_content(request)
    account = Account.by_name(data.get('name'))
    if not account \
       or not account.validate_password(data.get('password')) \
       or not login_user(account):
        return error_fill(login_form(), data,
            {'name': 'Invalid username or password!'})
    flash("Welcome back, %s!" % account.display_name, 'success')
    return redirect(url_for('home.index'))
Example #3
0
def login_save():
    """ Create an account based on the sign-up form. """
    data = request_content(request)
    account = Account.by_name(data.get('name'))
    if not account \
       or not account.validate_password(data.get('password')) \
       or not login_user(account):
        return error_fill(login_form(), data,
                          {'name': 'Invalid username or password!'})
    flash("Welcome back, %s!" % account.display_name, 'success')
    return redirect(url_for('home.index'))
Example #4
0
File: web.py Project: mihi-tr/grano
def basic_authentication():
    """ Attempt HTTP basic authentication on a per-request basis. """
    if 'Authorization' in request.headers:
        authorization = request.headers.get('Authorization')
        authorization = authorization.split(' ', 1)[-1]
        name, password = authorization.decode('base64').split(':', 1)
        account = Account.by_name(name)
        if account is None \
            or not account.validate_password(password) \
            or not login_user(account):
            raise Unauthorized('Invalid username or password.')
Example #5
0
def basic_authentication():
    """ Attempt HTTP basic authentication on a per-request basis. """
    if 'Authorization' in request.headers:
        authorization = request.headers.get('Authorization')
        authorization = authorization.split(' ', 1)[-1]
        name, password = authorization.decode('base64').split(':', 1)
        account = Account.by_name(name)
        if account is None \
            or not account.validate_password(password) \
            or not login_user(account):
            raise Unauthorized('Invalid username or password.')