예제 #1
0
def edit_name() -> Union[Response, str]:
    form = NameForm()
    if form.validate_on_submit():
        if db_funcs.validate_password(current_user.email, form.password.data):
            db_funcs.change_fullname(current_user.user_id, form.fullname.data)
            flash(f'Name changed to {form.fullname.data}.', 'success')
            return redirect(url_for('profile', user_id=current_user.user_id))
        flash_wrong_password()
    return render_template('edit_name.j2', form=form)
예제 #2
0
def edit_birthday() -> Union[Response, str]:
    form = BirthdayForm()
    if form.validate_on_submit():
        if db_funcs.validate_password(current_user.email, form.password.data):
            db_funcs.change_birthday(current_user.user_id, form.birthday.data)
            birthday = form.birthday.data.strftime('%d/%m/%Y')
            flash(f'Date of birth changed to {birthday}.', 'success')
            return redirect(url_for('profile', user_id=current_user.user_id))
        flash_wrong_password()
    return render_template('edit_birthday.j2', form=form)
예제 #3
0
def edit_password() -> Union[Response, str]:
    form = PasswordForm()
    if form.validate_on_submit():
        if db_funcs.validate_password(current_user.email,
                                      form.cur_password.data):
            db_funcs.change_password(current_user.user_id,
                                     form.new_password.data)
            flash('Password changed.', 'success')
            return redirect(url_for('profile', user_id=current_user.user_id))
        flash_wrong_password()
    return render_template('edit_password.j2', form=form)
예제 #4
0
def login() -> Union[Response, str]:
    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data
        if db_funcs.validate_password(email, form.password.data):
            login_user(db_funcs.get_user_by_email(email),
                       remember=form.remember.data)
            flash('You have been logged in.', 'success')
            return redirect(url_for('home'))
        flash('Login failed. Please try again.', 'danger')
    return render_template('login.j2', form=form)
예제 #5
0
def test_validate_password(user):
    assert db_funcs.validate_password(user.email, 'admin123')
예제 #6
0
 def validate_new_password(self, new_password: str) -> None:
     if validate_password(current_user.email, new_password.data):
         raise ValidationError('Please choose a new password.')