def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home_page')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf8') user.password = hashed_password db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title="Reset Password", form=form)
def register(): # If Current user is authenticated, redirect to homepage if current_user.is_authenticated: return redirect(url_for("home")) form = RegistrationForm() # To check Validation if form.validate_on_submit(): # Hash user password hashed_password = bcrypt.generate_password_hash( form.password.data).decode("utf-8") # Collect data form the Form Fields and instantiate to the "User" Model user = User(username=form.username.data, email=form.email.data, password=hashed_password) # Add User db.session.add(user) # Create user Account db.session.commit() flash("Your account has been created you're now able to login!", "success") return redirect(url_for("login")) return render_template("register.html", title="Register", form=form)
def save_user(username, email, password): password_hash = bcrypt.generate_password_hash(password).decode('utf-8') users_collection.insert_one({ 'username': username, 'email': email, 'password': password_hash })
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_token(token) if user is None: flash('Invalid or Expired Token', 'warning') return redirect(url_for('reset_request')) form = Reset_Form() if request.method == 'POST': hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f'Password Changed!, You Can Now Log-In ', 'success') return redirect(url_for('login')) return render_template('reset_password.html', title='Reset Password', form=form)
def registration(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): #Flashing success message flash(f'Your account has been created! You are now able to login.', 'success') #Take password from form, then decode it into utf-8 format hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') #Create instance of User class for inserting into database new_user = User(username=form.username.data, email=form.email.data, password=hashed_password) #Add new user db.session.add(new_user) #Commit changes db.session.commit() #Redirects you to homepage return redirect(url_for('users.login')) return render_template('register.html', form=form, title='Register')
def register(): if current_user.is_authenticated: return redirect(url_for('shops.shop')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=hashed_password, address=form.address.data, city=form.city.data, state=form.state.data, postcode=form.postcode.data, country=form.country.data, phone=form.phone.data) db.session.add(user) db.session.commit() send_welcome_email(user) flash('Your account has been created! You are now able to Login', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def populte(): print('drop database') db.drop_all() print('drop done') print('create database') db.create_all() print('create database done') print('creating......') for user in users: hash_password = bcrypt.generate_password_hash( user.get('password')).decode('utf-8') create_user = User(username=user.get('username'), email=user.get('email'), password=hash_password) account = Account() create_user.account = account db.session.add(create_user) db.session.commit() print('create user success') print('create users done') admin = User.query.filter_by(username='******').first() for post in posts: create_post = Post(title=post, content=post * 3, author=admin) db.session.add(create_post) db.session.commit() print('create post success') print('done')
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm(request.form) if request.method == "POST" and 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("Account created for {0}!".format(form.username.data)) return redirect(url_for('login')) return render_template("register.html", title="Register", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.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('users.login')) 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'Account created for {form.username.data},You can login now.') return redirect(url_for("login")) return render_template('register.html', title="register", form=form)
def register(): form = RegistrationForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw) db.session.add(user) db.session.commit() flash(f'{form.username.data} account has been created', 'success') return redirect(url_for('home')) return render_template('register.html', title='Register', form=form)
def sign_up(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationFrom() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data) 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! Your are now able to login', 'success') return redirect(url_for('home')) return render('sign_up.html', form=form, title='Sign Up')
def resetpassword_by_token(token): form = ResetPasswordForm() if form.validate_on_submit(): user = User.verify_rest_token(token) # return User object if user is None: flash('异常:用户验证失败或操作超时', 'danger') return redirect(url_for('users.login')) hash_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hash_password db.session.commit() flash(f'{user.username} 密码重置成功,请重新登陆', 'primary') return redirect(url_for('users.login')) return render_template('resetpassword.html', title=f'重置密码', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw) db.session.add(user) db.session.commit() flash("Your account has been created!", "success") return redirect(url_for("login")) return render_template("register.html", title='register', form=form)
def register(): if current_user.is_authenticated: # this will check current user authenticated and re direct to home page if user logged in and click on register button 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'Account created for {form.username.data} !!!', 'success') return redirect(url_for('login')) 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('Your Account Has Been Created ! Now You will be able to Create Post','success') flash(f'Account Created for {form.username.data}!', "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('main.home')) user = User.verify_reset_token(token) if(user is None): flash('Invalid/expired token', 'warning') 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('password updated', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Reset Password', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = Register_form() 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}', 'success') return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('homepage')) form = RegistrationForm() if form.validate_on_submit(): h_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=h_pass) db.session.add(user) db.session.commit() flash('Account created for {}'.format(form.username.data), 'success') ### changed lates return redirect(url_for('login')) return render_template('register.html', title="Register", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.hello')) form = RegistrationForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw) db.session.add(user) db.session.commit() flash(f'Account created for { form.username.data}! You can now Login', 'success') return redirect(url_for('main.login')) return render_template('register.html', title="Sign Up", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): # Hash the password from form hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # Create user variable with form data and hashed pass AND add into db user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f"You 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 signup(): if current_user.is_authenticated: flash(f'Already signed in!', 'success') return redirect(url_for('main.home')) form = SignUpForm() 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 }!', 'success') return redirect(url_for('users.signin')) return render_template('signup.html', title='Sign Up', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hash_pwd = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user_1 = User(username=form.username.data, email=form.email.data, password=hash_pwd) db.session.add(user_1) db.session.commit() flash(f'Your Account created for {form.username.data}!', 'success') # 'success' message here is falls in type category return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: #if user is already logged in and they click the link to the login page, they are redirected to the homepage return redirect(url_for('main.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 ) #User() is a constructor for the User. We use this constructor to create a new instance of user in the database db.session.add(user) db.session.commit() flash('Your account has been created. Please log in', 'success') #success is a bootstrap class return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('homepage')) user = User.verify_reset_token(token) if not User: flash("Invalid or Expired Token", "warning") return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): h_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = h_pass db.session.commit() flash('Your password has been updated', 'success') ### changed lates return redirect(url_for('login')) return render_template('reset_token.html', title="Reset Password", form=form)
def register(): if current_user.is_authenticated: flash(f'无效操作:{current_user.username} 请退出当前账号再进行操作', 'danger') return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hash_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hash_password) account = Account() user.account = account db.session.add(user) db.session.commit() flash(f'注册成功 - { form.username.data } 请用邮箱登陆', 'primary') return redirect(url_for('users.login')) return render_template('register.html', form=form, title='注册')
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = ResetPassword() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_pw db.session.commit() flash(f'Password changed!Now You can Login', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Reset Password', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if not user: flash('That is an invalid or expired token.', 'warning') 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('Your password has been successfully changed.', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', form=form, title='Reset Password')
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash("That is an invalid or expired token", "warning") 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 changed!!!", "success") return redirect(url_for("users.login")) return render_template("reset_token.html", title='Reset Password', form=form)
def register(): if current_user.is_authenticated: flash(f'Already logged in!') return redirect(url_for('blog')) # Create an instance of your RegistrationForm to pass to a template 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)