def changepswd(): """ Handles the change of password for the current user """ form = ChangePassForm() if form.validate_on_submit(): try: user = current_user print "here" if user.verify_password(form.oldpass.data): print "pass ok" user.password = form.newpass.data print user.username.value print form.newpass.data user.save() flash('Parola schimbata!',category='alert-success') return redirect(request.args.get('next') or '/home/') else: raise Exception('Not authorised',form.email.data) except Exception as err: print err flash('Modificarea nu poate fi facuta!', category='alert-danger') return render_template('users/edit.html', pagetitle='Schimba parola', form=form)
def profilepage(): changepass_form = ChangePassForm() # Get old password, compare with form and change password if changepass_form.validate_on_submit(): old_pass = changepass_form.oldpassword.data new_pass = changepass_form.newpassword.data changepass_form.oldpassword.data = changepass_form.newpassword.data = "" if old_pass == current_user.password: current_user.password = new_pass db.session.commit() message = 'Password successfuly changed.' return render_template("profilepage.html", user=current_user, changepass_form=changepass_form, message=message) # Error message if old password mismatches error = 'Old password mismatch.' return render_template("profilepage.html", user=current_user, changepass_form=changepass_form, error=error) return render_template("profilepage.html", user=current_user, changepass_form=changepass_form)
def change_pass(self, user_id): form = ChangePassForm(csrf_enabled=False) if form.validate_on_submit(): user = User.query.get(user_id) user.password = generate_password_hash(form.passw.data) db.session.add(user) try: db.session.commit() flash(u"The password has been changed successfully") except Exception: flash("Unexpected error") return self.render("admin_local/model/change_pass.html", form=form)
def changepass(): form = ChangePassForm() user = g.user if form.validate_on_submit(): oldhash = hashlib.sha224(form.oldPass.data + user.email).hexdigest() if oldhash == user.passhash: newhash = hashlib.sha224(form.newPass.data + user.email).hexdigest() user.passhash = newhash db.session.add(user) db.session.commit() flash('Your changes have been saved.') return redirect(url_for('user', name = g.user.name)) else: flash('Current password was incorrect.') return redirect(url_for('changepass')) else: return render_template('changepass.html', user = g.user, form = form)
def profilepage(): changepass_form = ChangePassForm() # Get old password, compare with form and change password if changepass_form.validate_on_submit(): old_pass = changepass_form.oldpassword.data new_pass = changepass_form.newpassword.data changepass_form.oldpassword.data = changepass_form.newpassword.data = "" if old_pass == current_user.password: current_user.password = new_pass db.session.commit() message = 'Password successfuly changed.' return render_template("profilepage.html", user = current_user, changepass_form = changepass_form, message = message) # Error message if old password mismatches error = 'Old password mismatch.' return render_template("profilepage.html", user = current_user, changepass_form = changepass_form, error = error) return render_template("profilepage.html", user = current_user, changepass_form = changepass_form)