def register(): form = RegisterForm() if form.validate_on_submit(): user = User(name=form.name.data, surname=form.surname.data, email=form.email.data, username=form.email.data.split("@")[0], password=form.password.data, verified=False) db.session.add(user) try: db.session.commit() except exc.IntegrityError: flash("User already exists!", "error") return render_template('register.html', form=form) token = generate_verification_token(user.email) verification_url = url_for('users.verify_email', token=token, _external=True) html = render_template('activate.html', verification_url=verification_url) subject = "Please verify your email" send_email(user.email, subject, html) login_user(user) flash("Verification link has been sent via email", "success") return redirect(url_for('users.unverified')) return render_template('register.html', form=form)
def register(): current_app.logger.debug('Inside register route of users blueprint') user_details = Users.get_current_user() error_message = None registerform = RegisterForm() if registerform.validate_on_submit(): username = registerform.username.data password = registerform.password.data existing_user = Users.get_by_name(name=username) if not existing_user: hashed_password = generate_password_hash(password, method='sha256') new_user = Users(name=username, password=hashed_password, expert=False, admin=False) new_user.save_to_db() session['username'] = username if username == 'admin': admin_user = Users.get_by_name(name='admin') admin_user.admin = True admin_user.save_to_db() current_app.logger.debug( 'Redirecting to index route of questions blueprint') return redirect(url_for('questions.index')) else: current_app.logger.error('User already exists') error_message = "User already exists!" return render_template('register.html', user=user_details, error=error_message, form=registerform)
def register(): """The route for the register screen. This routes a user to a form to register for access to the application. Decorators: app.route Returns: Renders template for registration page upon get request Renders template for login page upon successful post request """ if current_user.is_authenticated: flash(f'You are already logged in as {current_user.username}. You must log out to register another user.', 'info') return redirect(url_for('main.dashboard')) form = RegisterForm() if form.validate_on_submit(): hashed_password = sha256_crypt.hash(form.password.data) user = User(first_name=form.first_name.data, last_name=form.last_name.data, username=form.username.data, email=form.email.data, password=hashed_password, role='locked', registered_date=datetime.now().strftime("%Y %m %d %H:%M:%S")) db.session.add(user) db.session.commit() flash("You are now registered, but your account is 'pending' authorization. You will receive an email once your account is approved.", 'info') logger.info(f'{user.first_name} {user.last_name} - Username: {user.username} registered.') return redirect(url_for('main.index')) else: return render_template('register.html', Title="Register", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): if form.token.data == config.get('reg_token').strip(): if form.check_email_unique(form.email.data): phone = form.area.data + form.exchange.data + form.subscriber.data new_user = User(form.email.data.lower(), form.first.data.capitalize(), form.last.data.capitalize(), form.password.data, phone, form.email_me.data, form.text_me.data) db.session.add(new_user) db.session.commit() flash( f'Welcome {new_user.first}, you are now registered. Please login to continue.' ) return redirect(url_for('core.login')) else: flash( f'Sorry, the email {form.email.data} has already been registered. ' f'Perhaps try to login with the \'I forgot my password\' option' ) form.email.data = '' form.password.data = '' form.pass_confirm.data = '' else: # bad token flash(f'The registration token provided is not correct.') form.token.data = '' return render_template('register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): user = Users(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() flash("Your account has been created! You are now able to log in!") return redirect(url_for("users.login")) return render_template("register.html", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): user = User( name=form.username.data, email=form.email.data, password=form.password.data ) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('home.home')) return render_template('register.html', form=form)
def register(): ''' Registration page. :return: rendered template ''' form = RegisterForm() if form.validate_on_submit(): user = User(username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() login_user(user) # automatically log user in return redirect(url_for('main.home')) return render_template('register.html', form=form)
def register(): error = None form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): new_user = User(form.name.data, form.email.data, bcrypt.generate_password_hash(form.password.data).decode()) try: db.session.add(new_user) db.session.commit() flash('Thanks for registering. Please login.') return redirect(url_for('users.login')) except IntegrityError: error = 'That username and/or email already exist.' return render_template('register.html', form=form, error=error) return render_template('register.html', form=form, error=error)
def register(): form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): try: new_user = User(form.email.data, form.password.data) new_user.authenticated = True db.session.add(new_user) db.session.commit() flash('Thanks for registering!', 'success') return redirect(url_for('recipes.index')) except IntegrityError: db.session.rollback() flash(f'ERROR! Email ({form.email.data}) already exists.', 'error') return render_template('register.html', form=form)
def register(): form = RegisterForm() if request.method == 'POST' and form.validate_on_submit(): default_role = Role.query.filter_by(name='user').first() user = User(name=form.name.data, email=form.email.data, username=form.username.data, password=form.password.data, roles=[ default_role, ]) db.session.add(user) db.session.commit() flash('You are successfully registered.', 'success') # login_user(user) return redirect(url_for('users.login')) return render_template('register.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): try: new_user = User(form.email.data, form.password.data) db.session.add(new_user) db.session.commit() send_confirmation_email(new_user.email) flash( "Thanks for registering! Please check your email to activate your account.", 'success') return redirect(url_for('main.home')) except IntegrityError: db.session.rollback() flash(f'Error, Email {form.email.data} is already registered.', 'error') return render_template('register.html', form=form)
def register(): error = None form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): new_user = User( form.name.data, form.email.data, bcrypt.generate_password_hash(form.password.data), ) try: db.session.add(new_user) db.session.commit() flash('New user created successfully. Please login.') return redirect(url_for('users.login')) except IntegrityError: error = 'Provided username and password exist already, try again with different values' return render_template('register.html', form=form, error=error) return render_template('register.html', form=form, error=error)
def register(): if current_user.is_active: return redirect(url_for("posts.home")) form = RegisterForm() # form.username.errors # form.username(placeholder= 'Enter your username', required = True, value = 'Default Value') # form.username.errors # form.username.label # form.password.label g.message = "" if form.validate_on_submit(): name = form.username.data email = form.email.data password = form.password.data if check_and_add_user(name, email, password) == True: return redirect(url_for('posts.home')) return render_template("register.html", form = form)
def register(): error = None form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): new_user = User( form.name.data, form.email.data, bcrypt.generate_password_hash(form.password.data) ) try: db.session.add(new_user) db.session.commit() flash('Thanks for registering. Please login.') return redirect(url_for('users.login')) except IntegrityError: error = 'Sorry that username and/or email error already exist.' return render_template('register.html', form=form, error=error) else: return render_template('register.html', form=form, error=error) if request.method == 'GET': return render_template('register.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): try: new_user = User(form.email.data, form.password.data) new_user.authenticated = True db.session.add(new_user) db.session.commit() login_user(new_user) send_confirmation_email(new_user.email) flash( 'Thanks for registering! Please check your email to confirm your email address.', 'success') return redirect(url_for('recipes.public_recipes')) except IntegrityError: db.session.rollback() flash( 'ERROR! Email ({}) already exists.'.format( form.email.data), 'error') return render_template('register.html', form=form)