def register(): if request.method == 'POST': username = request.form['name'] password = request.form['password'] secret_pass = request.form['secret'] user = User.query.filter_by(name=username).first() error = None if not username: error = 'username is required' if not password: error = 'password is required' if secret_pass != '': error = 'Secret code is wrong' if user: error = 'User is registered try a different name' if error is None: admin = User(name=username, password=generate_password_hash(password)) db.session.add(admin) db.session.commit() flash('your account created') return redirect(url_for('user.register')) flash(error) return render_template('register.html')
def register(): form = RegisterationForm() 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'The Account has been created for {form.username.data}!','success') return redirect(url_for('login')) else: return render_template('register.html',title='Register',form = form)
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(f'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 reset_token(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_reset_token(token) if user is None: flash('That is invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f'Your password has been updated! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset Password', form=form)
def regester(): if current_user.is_authenticated: return redirect(url_for('users.account')) form = RegestrationForm() 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'Account created for {form.username.data}, You can login now!', 'success') return redirect(url_for('users.login')) return render_template('regester.html', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('users.account')) user = User.verify_reset_token(token) if not user: flash('Invalid or Expired Token, Try Again.', 'error') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f'Password updated', 'success') return redirect(url_for('users.login')) return render_template('passwordReset.html', form=form)