示例#1
0
文件: auth.py 项目: rclanan/radar
def account_view():
    account_form = AccountForm(prefix='account', obj=current_user)
    change_password_form = ChangePasswordForm(prefix='change-password')
    change_email_form = ChangeEmailForm(prefix='change-email')

    if 'account-submit' in request.form:
        if account_form.validate():
            current_user.first_name = account_form.first_name.data
            current_user.last_name = account_form.last_name.data
            db.session.commit()
            flash('Account updated.', 'success')
            return redirect(url_for('auth.account'))
    elif 'change-password-submit' in request.form:
        if change_password_form.validate():
            password = change_password_form.new_password.data
            current_user.set_password(password)
            db.session.commit()
            flash('Password updated.', 'success')
            return redirect(url_for('auth.account'))
    elif 'change-email-submit' in request.form:
        if change_email_form.validate():
            email = change_email_form.new_email.data
            current_user.email = email
            db.session.commit()
            flash('Email updated.', 'success')
            return redirect(url_for('auth.account'))

    context = dict(
        account_form=account_form,
        change_password_form=change_password_form,
        change_email_form=change_email_form,
    )

    return render_template('account.html', **context)
示例#2
0
文件: auth.py 项目: rclanan/radar
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        password = form.new_password.data
        current_user.set_password(password)
        db.session.commit()
        flash('Password updated.', 'success')
        return redirect(url_for('radar.index'))

    context = dict(
        form=form,
    )

    return render_template('change_password.html', **context)