Esempio n. 1
0
def settings_update_email_POST():
    form = UpdateEmailForm(request.form, email=current_user.email)

    if not form.validate_on_submit():
        return render_template(
            'user/settings-update-email.html',
            form=form,
        ), 400

    if not form.update_needed():
        flash('No update needed.', 'info')
        return redirect(url_for('user.settings_update_email_POST'))

    current_user.active = False
    current_user.auth_id = ObjectId()
    current_user.email = form.email.data
    current_user.last_updated = datetime.utcnow()
    current_user.save()

    redirect_target = url_for('user.settings_update_email_POST')

    send_verification_email(current_user, redirect_target=redirect_target)

    return redirect(
        url_for(
            'auth.verify_resend_GET',
            email=form.email.data,
            next=redirect_target,
        ))
Esempio n. 2
0
def sign_up_POST():
    form = SignUpForm(request.form)

    if not form.validate_on_submit():
        return render_template('auth/sign-up.html', form=form), 400

    user = User()
    form.populate_obj(user)
    user.initials = User.create_initials(user.name)
    user.password = User.encrypt_password(form.password.data)
    user.save()

    send_verification_email(user)

    return redirect(url_for('auth.verify_resend_GET', email=form.email.data))
Esempio n. 3
0
def verify_resend_POST():
    form = VerifyResendForm(request.form, email=request.args.get('email'))

    if not form.validate_on_submit():
        return render_template('auth/verify-resend.html', form=form), 400

    sent_email = send_verification_email(form.user, request.args.get('next'))
    status_code = 200 if sent_email else 500

    return render_template('auth/verify-resend.html', form=form), status_code
Esempio n. 4
0
def users_user_email_POST(user, **_):
    errors = email_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = email_schema.dump(request.json)

    if get_user_by_email(parsed_schema["email"]):
        return build_400_error_response({
            "email": [
                "There is already an account with this email.",
            ],
        })

    updated_user = update_user_email(user, parsed_schema["email"])

    send_verification_email(updated_user)

    return "", 204
Esempio n. 5
0
def verify_POST():
    errors = email_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = email_schema.dump(request.json)

    user = get_user_by_email(parsed_schema["email"])

    if not user:
        abort(404)

    if user.active:
        return build_400_error_response({
            "email": [
                "This email has already been verified.",
            ],
        })

    send_verification_email(user)

    return "", 204
Esempio n. 6
0
def sign_up_POST():
    errors = sign_up_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = sign_up_schema.dump(request.json)

    if get_user_by_email(parsed_schema["email"]):
        return build_400_error_response({
            "email": [
                "There is already an account with this email.",
            ],
        })

    user = save_new_user(
        parsed_schema["name"],
        parsed_schema["email"],
        parsed_schema["password"],
    )

    send_verification_email(user)

    return "", 201