Example #1
0
def _post_login():
    redirect_to = request.args.get("redirect_to","/")
    login_form = generate_login_form()
    form_values = get_form_values(request, login_form)
    username = form_values["username"]
    passwd = form_values["password"]
    user_obj = users.get_user_by_attr({"username": username})

    if users.auth(user_obj, passwd):
        if login_user(user_obj):
            return redirect(redirect_to)

    return redirect(url_for("login_user") + "?login=unsuccessful")
Example #2
0
def login():
    login_form = generate_login_form()

    #login form
    if request.method == "GET":
        login_form = generate_form(login_form, **{
            "action": "/login/",
            "method": "post",
        })
        return render_template("login.html", **{
            "login_form": login_form,
            "is_login": True,
        })

    #parse login credentials
    form_values = get_form_values(request, login_form)
    username = form_values["username"]
    passwd = form_values["password"]
    user_obj = users.get_user_by_attr({"username": username})
    if users.auth(user_obj, passwd):
        login_user(user_obj)
        return "Logined"
    return "Did not auth"