def register_with_oauth_authorized(): ''' This endpoint should be called after authorizing with oauth, by the user. ''' email = request.form.get('email') username = request.form.get('username') provider = request.form.get('provider') remote_user = request.form.get('remote_user') good = True if check_username_for_registration(username): good = False if check_email_for_registration(email): good = False if good: password = binascii.b2a_hex(os.urandom(99)) user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.flush() # to get an ID. auth = UserAuth(user.id, remote_user, provider) db.add(auth) db.commit() # Commit before trying to email send_confirmation(user) return redirect("/account-pending") return render_register_with_oauth(provider, remote_user, username, email)
def render_register_with_oauth(provider, remote_user, username, email): provider_info = list_defined_oauths()[provider] parameters = { 'email': email, 'username': username, 'provider': provider, 'provider_full_name': provider_info['full_name'], 'provider_icon': provider_info['icon'], 'remote_user': remote_user } error = check_username_for_registration(username) if error: parameters['usernameError'] = error error = check_email_for_registration(email) if error: parameters['emailError'] = error return render_template('register-oauth.html', **parameters)