def new_signup(): # forms to handle sign up and sign in signup_form = web_forms.SignUpForm() signin_form = web_forms.SignInForm() login = True if request.method == 'POST': if signin_form.data['submit_bttn']: if signin_form.validate_on_submit(): username = signin_form.data['username_field'] password = signin_form.data['password_field'] result = db.select('users', ['password', 'user_id'], ['username'], [username]) log.info('here is result: {}'.format(result)) if result: hash = result['password'] password_match = pbkdf2_sha256.verify(password, hash) if password_match: curr_user = User(result['user_id']) login_user(curr_user) next_url = request.args.get('next') if not is_safe_url(next_url): return abort(400) if not current_user.is_profile_complete(): flash( 'Please complete your profile before continuing!' ) return redirect(next_url or url_for('profile')) return redirect(next_url or url_for('team')) signin_form.username_field.errors.append( "Invalid Username or Password.") elif signup_form.data['submit']: if signup_form.validate(): # create token token = ts.dumps(signup_form.data['email'], salt='email-confirm-key') # build url confirm_url = url_for('confirm_email', token=token, _external=True) # set up html that makes up email html = render_template('signup_email.html', validate_url=confirm_url, user={ 'first': signup_form.data['first'], 'last': signup_form.data['last'] }) # create thread to speed up process subject = "Confirm Your Email" t1 = threading.Thread(target=util_basic.send_email, args=(signup_form.data['email'], html, subject)) t1.start() # create user curr_user = User.user_from_form(signup_form.data) # log user in login_user(curr_user) # wait for thread t1.join() # flash message and redirect user to their new profile page flash( 'Please check your email and follow the instructions to confirm your email address.', 'alert-success') return redirect(url_for('profile')) login = False return render_template( 'signup.html', sign_up=signup_form, sign_in=signin_form, login=login, _url= "https://s3-us-west-2.amazonaws.com/athlessary-images/defaults/login_photo.jpg" )