def change_password(): """ Method to change the password for local auth users. """ form = forms.ChangePasswordForm() user_obj = pagure.lib.query.search_user( flask.g.session, username=flask.g.fas_user.username ) if not user_obj: flask.abort(404, "User not found") if form.validate_on_submit(): try: password_checks = check_password( form.old_password.data, user_obj.password, seed=pagure.config.config.get("PASSWORD_SEED", None), ) except pagure.exceptions.PagureException as err: _log.exception(err) flask.flash( "Could not update your password, either user or password " "could not be checked", "error", ) return flask.redirect(flask.url_for("auth_login")) if password_checks: user_obj.password = generate_hashed_value(form.password.data) flask.g.session.add(user_obj) else: flask.flash( "Could not update your password, either user or password " "could not be checked", "error", ) return flask.redirect(flask.url_for("auth_login")) try: flask.g.session.commit() flask.flash("Password changed") except SQLAlchemyError: # pragma: no cover flask.g.session.rollback() flask.flash("Could not set the new password.", "error") _log.exception("Password change - Error setting new password.") return flask.redirect(flask.url_for("auth_login")) return flask.render_template("login/password_recover.html", form=form)
def change_password(): """ Method to change the password for local auth users. """ form = forms.ChangePasswordForm() user_obj = pagure.lib.search_user( SESSION, username=flask.g.fas_user.username) if not user_obj: flask.abort(404, 'User not found') if form.validate_on_submit(): try: password_checks = check_password( form.old_password.data, user_obj.password, seed=APP.config.get('PASSWORD_SEED', None)) except pagure.exceptions.PagureException as err: APP.logger.exception(err) flask.flash( 'Could not update your password, either user or password ' 'could not be checked', 'error') return flask.redirect(flask.url_for('auth_login')) if password_checks: user_obj.password = generate_hashed_value(form.password.data) SESSION.add(user_obj) else: flask.flash( 'Could not update your password, either user or password ' 'could not be checked', 'error') return flask.redirect(flask.url_for('auth_login')) try: SESSION.commit() flask.flash( 'Password changed') except SQLAlchemyError as err: # pragma: no cover SESSION.rollback() flask.flash('Could not set the new password.', 'error') APP.logger.debug( 'Password change - Error setting new password.') APP.logger.exception(err) return flask.redirect(flask.url_for('auth_login')) return flask.render_template( 'login/password_recover.html', form=form, )