示例#1
0
def edit_profile():

    user = current_user
    edit_username_form = ChangeUserNameForm(user.username)
    edit_password_form = ChangePasswordForm()
    edit_status_form = ChangeStatusForm()
    if edit_username_form.validate_on_submit():
        user.username = edit_username_form.username.data
        db.session.add(user)
        db.session.commit()
        edit_username_form.username.data = ''
        flash(_('Your username has changed.'))
        return redirect(url_for('main.edit_profile'))
    if edit_password_form.validate_on_submit():
        user.set_password(edit_password_form.password.data)
        db.session.add(user)
        db.session.commit()
        edit_password_form.password.data = ''
        edit_password_form.password2 = ''
        flash(_('Your password has changed.'))
        return redirect(url_for('main.edit_profile'))
    if edit_status_form.validate_on_submit():
        user.status = edit_status_form.status.data
        db.session.add(user)
        db.session.commit()
        edit_status_form.status.data = ''
        flash(_('Your staus has changed.'))
        return redirect(url_for('main.edit_profile'))
    return render_template('user_page.html',
                           page_to_vievs='_edit_profile.html',
                           user=user,
                           title=_('Edit Profile'),
                           edit_username_form=edit_username_form,
                           edit_password_form=edit_password_form,
                           edit_status_form=edit_status_form)
示例#2
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        password_old = form.password_old.data
        password = form.password.data
        password2 = form.password2.data
        current_user.set_password(password)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('main.change_password'))
    return render_template('change_profile.html',
                           title='Change Password',
                           form=form,
                           label='Change Password')
def user_profile_password():

    # Validate password for form
    def _check_password(pwd):
        return user_api_client.verify_password(current_user.id, pwd)
    form = ChangePasswordForm(_check_password)

    if form.validate_on_submit():
        user_api_client.update_password(current_user.id, password=form.new_password.data)
        return redirect(url_for('.user_profile'))

    return render_template(
        'views/user-profile/change-password.html',
        form=form
    )
def user_profile_password():

    # Validate password for form
    def _check_password(pwd):
        return user_api_client.verify_password(current_user.id, pwd)
    form = ChangePasswordForm(_check_password)

    if form.validate_on_submit():
        current_user.set_password(form.new_password.data)
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template(
        'views/user-profile/change-password.html',
        form=form
    )
示例#5
0
def change_password():
    if not current_user.is_authenticated:
        return redirect(url_for('auth.login'))

    form = ChangePasswordForm()
    """ Check which button is click """
    if form.submitcancle.data:
        return redirect(url_for('main.user', username=current_user.username))

    if form.validate_on_submit():
        """ check user old password is valid """
        oldpassword_is_valid = current_user.check_password(
            form.oldpassword.data)

        if oldpassword_is_valid:
            current_user.set_password(form.password.data)
            db.session.commit()
            flash(_("Yes! Your password has been changed!"))
            logout_user()
            return redirect(url_for('auth.login'))
        else:
            flash(_("Oh! Your original password hasn't correct!"))

    return render_template('change_password.html', form=form)