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 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('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('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(f"Account created for {form.username.data}!, You can login now", "success") return redirect(url_for("users.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 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 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() path = os.path.join(current_app.root_path, 'static/files/', str(user.id)) os.mkdir(path) flash(f'Account was created successfully. You can log in now!', 'success') return redirect(url_for('users.login')) return render_template("register.html", title="Register", form=form)
def register(): # check if there's a user logged in already # return to the home page if there is, else continue if current_user.is_authenticated: return redirect(url_for('main.home')) # grab our registration form form = RegistrationForm() # check that our form is valid after it is submitted # make sure that we only save the hashed pw # redirect user to the login page for them to log in after successful registration 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'Your account has been created {form.username.data}!', 'success') return redirect(url_for('users.login')) return render_template("register.html", title="Register", form=form)