Esempio n. 1
0
 def create_user(cls, **kwargs):
     user = User()
     user.active = kwargs.get('active', True)
     user.email = kwargs.get('email', cls.fake.email())
     user.initials = kwargs.get(
         'initials',
         cls.fake.pystr(min_chars=1, max_chars=4).upper(),
     ).upper()
     user.name = kwargs.get('name', cls.fake.name())
     user.password = User.encrypt_password(
         kwargs.get('password', cls.fake.password()), )
     return user.save()
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 reset_password_POST(token):
    auth_id = deserialize_password_reset_token(token)
    user = User.objects(auth_id=auth_id).first()

    if not user:
        abort(404)

    form = ResetPasswordForm(request.form)

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

    user.password = User.encrypt_password(form.new_password.data)
    user.auth_id = ObjectId()
    user.last_updated = datetime.utcnow()
    user.save()

    flash('Your password has been reset.', 'success')

    login_user(user)

    return redirect(url_for('user.boards_GET'))
Esempio n. 4
0
def settings_update_password_POST():
    form = UpdatePasswordForm(request.form)

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

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

    current_user.password = User.encrypt_password(form.new_password.data)
    current_user.auth_id = ObjectId()
    current_user.last_updated = datetime.utcnow()
    current_user.save()

    flash('Your password has been updated.', 'success')

    login_user(current_user)

    return redirect(url_for('user.settings_update_password_POST'))