def reset_password(): if request.method == 'GET': return render_template('reset_password.html') data = request.get_json() original_password = data['original_password'] new_password1 = data['password1'] new_password2 = data['password2'] if current_user.validate_password(original_password): if (new_password1 == new_password2): if (new_password1 != original_password): current_user.set_password(new_password1) db.session.commit() logout_user() return jsonify({"reset_password": True}) else: flash( 'Please make sure you new password is different the original one!' ) else: flash( 'Please make sure the two new passwords you input are the same!' ) else: flash('Invalid email or password.', 'warning') return jsonify({"reset_password": False})
def changepassword(): form = PasswordChangeForm() if request.method == 'GET': return render_template('changepassword.html', form=form, name=current_user.email) else: if form.validate_on_submit(): if current_user.validate_password(form.currentpassword.data): local_object = db.session.merge(current_user) local_object.password = current_user.update_password( form.newpassword.data) db.session.add(local_object) db.session.commit() Mail_Service.send_email(current_user.email, "Password Changed", current_user, request.remote_addr) flash("Password Sucessfully Changed") else: flash("Incorrect Current Password") return render_template('changepassword.html', form=form, name=current_user.email) else: flash("Error with form") return render_template('changepassword.html', form=form, name=current_user.email) return redirect(url_for('account'))
def change_password(): form = ChangePasswordForm() if form.validate_on_submit() and current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('密码已更新.', 'success') return redirect(url_for('.index', username=current_user.username)) return render_template('user/settings/change_password.html', form=form)
def re_authenticate(): if login_fresh(): # How does this do ?? return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password(form.password.data): confirm_login() # How does this do ?? return redirect_back() return render_template('auth/login.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit() and current_user.validate_password(form.old_password.data): current_user.set_password(form.new_password.data) db.session.commit() flash("密码修改成功,请用新密码重新登录", "success") logout_user() return redirect(url_for("main.index")) return render_template("auth/change_password.html", form=form)
def re_authenticated(): if login_fresh(): return redirect(url_for("main.index")) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() return redirect_back() return render_template("auth/login.html", form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit() and current_user.validate_password( form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash("Password updated.", "success") return redirect(url_for("user.index", username=current_user.username)) return render_template("user/settings/change_password.html", form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) db.commit() return redirect(url_for('main.index')) return redirect(url_for('auth.changepwd')) return render_template('auth/changepwd.html', form=form)
def re_authenticate(): """处理非新鲜登录的重认证""" if login_fresh(): return redirect(url_for('blog.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password(form.password.data): confirm_login() return redirect_back() return render_template('auth/signin.html', form=form)
def re_authenticate(): if login_fresh(): return redirect(url_for('main.index')) form = ReLoginForm() if form.validate_on_submit(): if current_user.validate_password(form.password.data): confirm_login() return redirect_back() flash('密码错误, 请重新输入', 'warning') return render_template('auth/login.jinja2', form=form)
def re_authenticate(): """当用户‘不新鲜’时访问带@fresh_login_required的视图时,重新认证""" if login_fresh(): return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() return redirect_back() return render_template('auth/login.html', form=form)
def change_password(): """用户变更密码""" form = ChangePasswordForm() # 表单验证通过,且原密码验证通过,变更新密码,数据库确认,重定向到主页 if form.validate_on_submit() and current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('密码已变更。', 'success') return redirect(url_for('main.index', username=current_user.username)) return render_template('auth/change_password.html', form=form) # 表单验证或原密码验证未通过,返回变更密码页面
def reset_password(): if request.method == 'POST': form = ResetPasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.oldPassword.data): current_user.password = form.newPassword.data db.session.commit() flash('修改成功!', 1) else: flash(form.errors_info) return common_render('page/user/reset_password/index.html')
def re_authenticate(): if login_fresh(): flash('活跃用户不需要重新登录', 'info') return redirect(url_for('base')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() return redirect_back() return render_template('user/login.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.new_password.data) # 重设密码 db.session.commit() flash('密码修改成功。', 'success') return redirect(url_for('.index', username=current_user.username)) else: flash('密码不正确!', 'warning') return render_template('user/settings/change_password.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): # 验证旧密码 current_user.set_password(form.new_password.data) db.session.commit() flash("Password updated.", category="success") return redirect(url_for("user.index", username=current_user.username)) else: flash("Old password is incorrect.", category="warning") return render_template("user/settings/change_password.html", form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash(_('Пароль обновлен.'), 'success') return redirect(url_for('.index', username=current_user.username)) else: flash(_('Старый пароль введен неверно.'), 'warning') return render_template('user/settings/change_password.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('Password updated.', 'success') return redirect(url_for('.index', username=current_user.username)) else: flash('Old password is incorrect.', 'warning') return render_template('user/settings/change_password.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): with db.auto_commit(): current_user.password = form.new_password.data flash('密码修改成功,请重新登录.', 'success') return redirect(url_for('auth.login')) else: flash('原始密码错误.', 'warning') return render_template('user/settings/change_password.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('新密码已设置.', 'success') return redirect(url_for('blog.index')) else: flash('旧密码不正确.', 'warning') return render_template('admin/change_password.html', form=form)
def changepw(): """Handler for changing user password.""" form = PWChangeForm() if form.validate_on_submit(): if not current_user.validate_password(form.oldpw.data): flash('Invalid old password') elif current_user.set_password(get_db(), form.newpw.data): flash('Password successfully changed.') return redirect(url_for('mainpage')) else: flash('Error changing password.') return render_template('pwchange.html', form=form)
def changepw(): """Handler for changing user password.""" form = PWChangeForm() if form.validate_on_submit(): if not current_user.validate_password(form.oldpw.data): flash('Invalid old password') elif current_user.set_password(get_db(), form.newpw.data): flash('Password successfully changed.') return redirect(url_for('mainpage')) else: flash('Error changing password.') return render_template('pwchange.html', form=form)
def change_password(username): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) current_user.save() flash('密码修改成功', 'success') return redirect( url_for('user.index', username=current_user.username)) else: flash('旧密码不正确', 'warning') return render_template('user/change_password.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.password = form.password.data db.session.commit() flash('密码已修改,请重新登陆。', 'success') logout_user() return redirect(url_for('auth.login')) else: flash('旧密码错误,请重新输入。', 'warning') return render_template('user/settings/change_password.html', form=form)
def change_password(): """ 修改密码 """ logger.info('url = ' + str(request.url)) form = ChangePasswordForm() if form.validate_on_submit() and current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('密码修改成功!', 'success') return redirect(url_for('.index', username=current_user.username)) return render_template('user/settings/change_password.html', form=form)
def re_authenticate(): ''''对已经登录的用户重新认证,保持 “新鲜”。 类似 Github 等认证。对于一些敏感操作需要重新认证,例如修改密码。 ''' if login_fresh(): return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() return redirect_back() return render_template('auth/login.html', form=form)
def re_authenticate(): if login_fresh(): return redirect(url_for('front.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() log_user(content=render_template('logs/auth/login.html')) return redirect_back() return render_template('auth/login.html', form=form)
def re_authenticate(): """ 重新认证 """ logger.info('url = ' + str(request.url)) # 刷新 if login_fresh(): return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password(form.password.data): confirm_login() return redirect_back() return render_template('auth/login.html', form=form)
def test_change_user_password(self): current_password = "******" new_password = "******" with self.client: url = url_for('setting.change_user_password') data = dict(current_password="******", password=new_password) response_data = self.post_data(url, data) self.assertIn('invalid', response_data) data = dict(current_password=current_password, password=new_password) response_data = self.post_data(url, data) self.assertIn('ok', response_data) self.assertEqual(True, current_user.validate_password(new_password))
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): if cache.get(current_user.username) == form.verify_code.data: current_user.set_password(form.password.data) db.session.commit() flash('修改成功,请重新登录', 'success') logout_user() return redirect(url_for('auth.login')) else: flash('验证码错误或失效', 'warning') else: flash('密码错误', 'warning') return render_template('user/settings/change_password.html', form=form)
def reset_email(): if request.method == 'GET': return render_template('reset_email.html') data = request.get_json() password = data['password'] new_email = data['new_email'] if current_user.validate_password(password): if (current_user.email != new_email): current_user.email = new_email db.session.commit() return jsonify({"reset_email": True}) else: flash( 'Please make sure the you enter a different email from the current one!' ) else: flash('Invalid email or password.', 'warning') return jsonify({"reset_email": False})