def change_password_cn(): form = UpdatePasswordForm() if form.validate_on_submit(): if bcrypt.check_password_hash(current_user.password, form.old_password.data): current_user.password = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8') db.session.commit() flash('您的密码已更改成功。', 'success') return redirect(url_for('user.account_cn')) else: flash('您的旧密码有误,请检查!', 'danger') return render_template('change_password.html', title = '更改密码',form = form) return render_template('change_password.html', title ='更改密码', form = form)
def change_password_en(): form = UpdatePasswordForm() if form.validate_on_submit(): if bcrypt.check_password_hash(current_user.password, form.old_password.data): current_user.password = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8') db.session.commit() flash('Your password has been changed!', 'success') return redirect(url_for('user.account_en')) else: flash("The old password doesn't match your current password, please check!", 'danger') return render_template('change_password.html', title = 'Chang password', form = form) return render_template('change_password.html', title = 'Chang password', form = form)
def register_cn(): if current_user.is_authenticated: return redirect(url_for('webapp.welcome')) form = RegistrationForm() if form.validate_on_submit(): # hash the original user password hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username = form.username.data, email = form.email.data, password = hashed_password) db.session.add(user) db.session.commit() flash('我们为您创建了账户! 您现在可以登录了!', 'success') return redirect(url_for('user.login_cn')) return render_template('register.html', title = '注册', form = form, get_defaulte_language='cn')
def register_en(): if current_user.is_authenticated: return redirect(url_for('webapp.welcome')) form = RegistrationForm() if form.validate_on_submit(): # hash the original user password hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username = form.username.data, email = form.email.data, password = hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to login in!', 'success') return redirect(url_for('user.login_en')) return render_template('register.html', title = 'Register', form = form, lang='en')