示例#1
0
文件: account.py 项目: J4LP/newauth
 def profile(self):
     account_form = AccountUpdateForm(obj=current_user)
     account_form.main_character.choices = [(character.id, character.name) for character in current_user.characters if character.get_status() != CharacterStatus.ineligible]
     if account_form.validate_on_submit():
         if account_form.new_password.data and not account_form.password.data:
             flash('Your password is required to make these changes.', 'danger')
             return redirect(url_for('AccountView:profile'))
         if current_user.check_password(account_form.password.data):
             # Password checks out, let's update it
             current_user.update_password(account_form.new_password.data)
             db.session.add(current_user)
             db.session.commit()
             User.password_updated.send(current_user, account_form.new_password.data)
             session.clear()
             flash('Your password has been updated, please login again.')
             return redirect(url_for('AccountView:login'))
         current_user.email = account_form.email.data
         new_main_character = current_user.characters.filter_by(id=account_form.main_character.data).first()
         if not character:
             flash("We could not found this character in your characters.", 'danger')
             return redirect(url_for('AccountView:profile'))
         else:
             current_user.name = new_main_character.name
             current_user.main_character_id = new_main_character.id
         db.session.add(current_user)
         db.session.commit()
         flash('Account updated.', 'success')
         return redirect(url_for('AccountView:profile'))
     api_forms = [APIKeyForm(obj=api_key) for api_key in current_user.api_keys]
     new_api_form = APIKeyForm()
     return render_template('account/profile.html', account_form=account_form, api_forms=api_forms, new_api_form=new_api_form)
示例#2
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if check_password_hash(current_user.password, form.old_password.data):
            current_user.update_password(form.new_password.data)
            db.session.commit()
            message = "Your password has been changed."
            return render_template("message.html", active_page='none', message=message)
        else:
            form.old_password.errors = ["Old password incorrect."]
    return render_template('change_password.html', active_page='none', form=form)
示例#3
0
def change_password():

    form = PasswordChangeForm(request.form)

    if form.validate_on_submit():
        current_user.update_password(form.old.data, form.new.data)

        flash(_(u'Password changed'))
        return redirect(url_for('account.settings'))

    return render_template('account/change_password.html', form=form)
示例#4
0
def change_password():
    form = UpdateProfileForm()
    if form.validate_on_submit():
    	if check_password_hash(current_user.password, form.old_password.data):
            current_user.update_password(form.new_password.data)
            db.session.commit()
            alert = Alert("Your password has been changed.", type="alert-success")
            trips = current_user.trips.all()
            return render_template('my_trips.html', form=form, alert=alert, trips=trips)
        else:
            alert = Alert("Old password not correct.", type="alert-error")
            return render_template('change_password.html', form=form, alert=alert)
    return render_template('change_password.html', form=form)
示例#5
0
def change_password():
    '''
    Change a user's password
    '''
    form = ChangePasswordForm(request.form)
    if request.method == 'POST' and form.validate():
        if current_user.check_password(form.old_password.data):
            current_user.update_password(form.new_password.data)
            current_user.save()
            flash("Your password has been updated.", category='index_page')
            return redirect(url_for('.list_projects'))
        else:
            flash("Your password does not match.", category='error')
            return render_template('change_password.html', form=form)    
    return render_template('change_password.html', form=form)
示例#6
0
def change_password():
    """
    Change a user's password
    """
    # form = ChangePasswordForm(request.form)
    # if request.method == 'POST' and form.validate():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.old_password.data):
            current_user.update_password(form.new_password.data)
            current_user.save()
            flash("Your password has been updated.", category="index_page")
            return redirect(url_for(".list_projects"))
        else:
            flash("Your password does not match.", category="error")
            return render_template("change_password.html", form=form)
    return render_template("change_password.html", form=form)
示例#7
0
def chgpasswd():
    """
    Changes the users password.

    The only available method is POST as the form is on the 'myprofile' page. This 
    route just validates the form. If the method is GET the user is redirected to the
    'myprofile' page.
    """

    if request.method == 'GET':
        return redirect(request.referrer or url_for('login.myprofile'))

    # Create an empty error variable.
    error = None

    # Create the change password form.
    user_change_password_form = ChangePasswordForm()

    if user_change_password_form.validate_on_submit():
        # The form is valid.
        # Check the current password is correct.
        if bcrypt.check_password_hash(
                current_user.password,
                user_change_password_form.current_password.data):
            # If the current password matched update the new password.
            current_user.update_password(
                user_change_password_form.new_password.data)
            # Commit the changes to the database.
            db.session.commit()
            # Flash a message to the user.
            flash("Password has been successfully changed.")
        else:
            # Flash an error message.
            flash("Invalid password, password has not been changed", 'error')

    # Display the my profile page to the user with the specific errors of
    # the change password form.
    return render_template('login_myprofile.html',
                           error=error,
                           user_edit_details_form=EditDetailsForm(),
                           user_change_password_form=user_change_password_form)
示例#8
0
 def post_inst(self, form, request):
     current_user.password = form["new_password"].data
     current_user.update_password()
     db.session.commit()
     flash(_(u"Password changed successfully."))
     return redirect(request.args.get("next") or url_for("user.panel"))