def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): 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 log in.', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def insert_db(): if request.method == 'POST': data = request.get_json() name = data.get('name') pwd = data.get('pwd') else: name = request.args.get("name") pwd = request.args.get("pwd") user = User(name=name, pwd=pwd) db.session.add(user) # 这个session是临时保存上传数据用的 db.session.commit() json_response = {"status": 200, "message": "success"} return jsonify(json_response)
def register(): form = RegisterForm() if form.validate_on_submit(): 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( f'{form.username.data} your account has been successfully created!' ) return redirect(url_for('auth.login')) return render_template('user/register.html', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_request_token(token) if not user: flash('Invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_pass db.session.commit() flash('Your pass word has been changed!', 'success') return redirect(url_for('login')) return render_template('reset_password.html', title='Reset Password', form=form)