Exemple #1
0
def update_email():
    if request.method == "GET":
        user = User.query.filter_by(email=current_user.email).first()
        return render_template("pages/account.html",
                               form=UpdateEmailForm(),
                               user=user)

    # If user is admin
    if request.method == "POST":
        form = UpdateEmailForm(request.form)
        if form.validate_on_submit():
            verified = User.verify_user(current_user.email,
                                        form.data.get("password"))
            if verified:
                # TODO: Handle condition for uniqueness
                try:
                    updated = User.update_email(old_email=current_user.email,
                                                email=form.data.get("email"))
                    if updated:
                        Notifications.info_account_updated(**form.data)
                        login_user(current_user)
                        return redirect(url_for("account"))
                except EmailExistsError:
                    Notifications.email_exists(form.data.get("email"))
                    return redirect(url_for("update_email"))

        Notifications.info_try_again()
        return redirect(url_for("update_email"))
Exemple #2
0
def signup():
    name = request.form.get("name")
    email = request.form.get("email")
    password = request.form.get("password")
    is_admin = request.form.get("is_admin", False)

    # register user to db
    try:
        new_user = User.register(name, email, is_admin, password)
        if new_user is None:
            Notifications.info_try_again()

        if not current_user.is_anonymous:
            if current_user.is_admin:
                Notifications.info_account_created(name, password, email)
                return redirect(url_for("admin"))
        else:
            # Login the user
            u = User.verify_user(email, password)
            login_user(u)
            Notifications.info_account_created(name, password, email)
            return redirect(url_for("home"))
    except EmailExistsError:
        Notifications.email_exists(email)
    except PasswordTooShortError:
        Notifications.password_too_short()
    return redirect(url_for("home"))