def signup(): from run import app form = SignupForm(request.form) if form.validate_on_submit(): if is_email(form.email.data): # Check if user exists user = User.query.filter_by(email=form.email.data).first() if user is None: expires = int(time.time()) + 86400 hmac_hash = hmac.new( app.config.get('HMAC_KEY', ''), "%s|%s" % (form.email.data, expires) ).hexdigest() # New user template = app.jinja_env.get_or_select_template( 'email/registration_email.txt') message = template.render( url=url_for( '.complete_signup', email=form.email.data, expires=expires, mac=hmac_hash, _external=True ) ) else: # Existing user template = app.jinja_env.get_or_select_template( 'email/registration_existing.txt') message = template.render( url=url_for('.reset', _external=True), name=user.name ) if g.mailer.send_simple_message({ "to": form.email.data, "subject": "CCExtractor CI platform registration", "text": message }): flash('Email sent for verification purposes. Please check ' 'your mailbox', 'success') form = SignupForm(None) else: flash('Could not send email', 'error-message') else: flash('Invalid email address!', 'error-message') return { 'form': form }
def signup() -> Dict[str, SignupForm]: """Route for handling the signup page.""" from run import app form = SignupForm(request.form) if form.validate_on_submit(): if is_email(form.email.data): # Check if user exists user = User.query.filter_by(email=form.email.data).first() if user is None: expires = int(time.time()) + 86400 content_to_hash = "{email}|{expiry}".format( email=form.email.data, expiry=expires) hmac_hash = generate_hmac_hash(app.config.get('HMAC_KEY', ''), content_to_hash) # New user template = app.jinja_env.get_or_select_template( 'email/registration_email.txt') message = template.render(url=url_for('.complete_signup', email=form.email.data, expires=expires, mac=hmac_hash, _external=True)) else: # Existing user template = app.jinja_env.get_or_select_template( 'email/registration_existing.txt') message = template.render(url=url_for('.reset', _external=True), name=user.name) if g.mailer.send_simple_message({ "to": form.email.data, "subject": "CCExtractor CI platform registration", "text": message }): flash( 'Email sent for verification purposes. Please check your mailbox', 'success') form = SignupForm(None) else: flash('Could not send email', 'error-message') else: g.log.debug( f'sign up attempt using invalid email id: {form.email.data}') flash('Invalid email address!', 'error-message') return {'form': form}
def signup(): form = SignupForm(request.form) print(form.password.data) if request.method == 'POST' and form.validate(): # Check whether the user name is unique user_name_taken = db.session.query(User.email).filter_by( email=form.user_name.data).scalar() is not None print("heo") if user_name_taken: form.user_name.errors.append('Username taken') else: user = User(email=form.user_name.data, password=form.password.data) db.session.add(user) db.session.commit() flash('Thanks for registering') # TODO: send email to the user for registration signup return redirect(url_for('hello')) return render_template('auth/signup.html', form=form)
def signup(): """ route for handling the signup page """ from run import app form = SignupForm(request.form) if form.validate_on_submit(): if is_email(form.email.data): # Check if user exists user = User.query.filter_by(email=form.email.data).first() if user is None: expires = int(time.time()) + 86400 content_to_hash = "{email}|{expiry}".format(email=form.email.data, expiry=expires) hmac_hash = generate_hmac_hash(app.config.get('HMAC_KEY', ''), content_to_hash) # New user template = app.jinja_env.get_or_select_template('email/registration_email.txt') message = template.render(url=url_for( '.complete_signup', email=form.email.data, expires=expires, mac=hmac_hash, _external=True) ) else: # Existing user template = app.jinja_env.get_or_select_template('email/registration_existing.txt') message = template.render(url=url_for('.reset', _external=True), name=user.name) if g.mailer.send_simple_message({ "to": form.email.data, "subject": "CCExtractor CI platform registration", "text": message }): flash('Email sent for verification purposes. Please check your mailbox', 'success') form = SignupForm(None) else: flash('Could not send email', 'error-message') else: flash('Invalid email address!', 'error-message') return { 'form': form }
def verify_account(email, received_verification_code, expires): if g.user is not None: flash('Currently logged in as ' + g.user.username, 'success') return redirect(url_for('.profile')) if time.time() <= expires: expected_verification_code = generate_verification_code("{email}{expires}".format(email=email, expires=expires)) if hmac.compare_digest(expected_verification_code, received_verification_code): flash('Verification complete! Proceed to signup.', 'success') user = Users.query.filter_by(email=email).first() if user is None: form = SignupForm() if form.validate_on_submit(): user = Users(username=generate_username(email), email=email, password=form.password.data, name=form.name.data) db.session.add(user) db.session.commit() send_signup_confirmation_mail(user.email) flash('Signup Complete! Please Login to continue.', 'success') else: return render_template("mod_auth/verify.html", form=form, email=email) else: flash('Email is already registered!', 'error') return redirect(url_for('.login')) flash('Verification failed! Incorrect email address/verification code. Please try again.', 'error-message') else: flash('The verification link is expired. Please try again.', 'error-message') return redirect(url_for('.signup'))