Пример #1
0
def _post_register():
    redirect_to = request.args.get("redirect_to")
    values = get_form_values(request, _get_registration_form())
    dic = {k: v for k, v in values.iteritems()}
    del dic["cfm_password"]
    del dic["password"]
    user_obj = users.User(
        **dic
    )
    user_obj.account_status = users.AccountStatus.AWAITING_CONFIRMATION
    if not users.get_user_by_attr({
        "$or": [{
                    "email": user_obj.email
                }, {
                    "username": user_obj.username
                }]
    }):
        user_obj._id = users.save(user_obj, need_confirmation=False,
                              confirmation_email_subject="Complete your account registration",
                              confirmation_relative_url="/register/confirm/")
        users.set_passwd(user_obj, values["password"])
        return redirect(redirect_to)

    login_user(user_obj)
    return redirect(url_for("register_user") + "?user=exists")
Пример #2
0
def register():
    if request.method == "GET":
        registration_form = generate_form(__get_registration_form(), **{
            "action": "/register/",
            "method": "post",
        })
        return render_template("registration.html", **{
            "registration_form": registration_form,
            "is_register": True,
        })
    else:
        values = get_form_values(request, __get_registration_form())
        dic = {k: v for k, v in values.iteritems()}
        user_obj = users.User(
            **dic
        )
        user_obj.account_status = users.AccountStatus.AWAITING_CONFIRMATION
        if not users.get_user_by_attr({
            "$or": [{
                        "email": user_obj.email
                    }, {
                        "username": user_obj.username
                    }]
        }):
            user_obj = users.save(user_obj, need_confirmation=True,
                confirmation_email_subject="Complete your account registration",
                confirmation_relative_url="/register/confirm/")
            users.set_passwd(user_obj, values["password"])
            return "Saved!"
        return "Already registered."
Пример #3
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")
Пример #4
0
def forgot_password():
    form = __forgot_passwd_form()
    if request.method == "GET":
        return render_template("forgot_password.html", **{
            "form": generate_form(form, **{
                "action": "/user/forgot-password/",
                "method": "post",
            })
        })

    elif request.method == "POST":
        form_values = get_form_values(request, __forgot_passwd_form())
        user_obj = users.get_user_by_attr({"email": form_values["email"]})
        users.send_reset_passwd_notice(user_obj)
        return "Check your email"
Пример #5
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"
Пример #6
0
def _post_forgot_password():
    form = _forgot_passwd_form()
    form_values = get_form_values(request, form)
    user_obj = users.get_user_by_attr({"email": form_values["email"]})
    users.send_reset_passwd_notice(user_obj)
    return render_template("forgot_password_done.html")