Пример #1
0
def auth_func(*args, **kw):
    """API authentication."""
    # if the user is not authenticated, try basic auth
    if not current_user.is_authenticated:
        try:
            auth = base64.b64decode(request.headers.get("Authorization").split(" ")[1]).split(":")
            user = User.from_login(*auth)
            login_user(user)
        except:
            raise ProcessingException(description='Not authenticated!', code=401)
Пример #2
0
def login():
    """Login view."""
    # prepare form
    form = LoginForm()
    if form.validate_on_submit():
        # if form content is valid, login the user and redirect to home
        user = User.from_login(form.username.data, form.password.data)
        if user:
            login_user(user)
            return redirect(url_for("home"))
        else:
            flash("Wrong username or password!", "danger")
    elif form.errors:
        flash("You must specify a valid username and password!", "danger")
    return render_template("users/login.html", form=form)