def signup(): next_url = util.get_next_url() form = None if config.CONFIG_DB.has_email_authentication: form = form_with_recaptcha(SignUpForm()) save_request_params() if form.validate_on_submit(): user_db = model.User.get_by('email', form.email.data) if user_db: form.email.errors.append('This email is already taken.') if not form.errors: user_db = create_user_db( None, util.create_name_from_email(form.email.data), form.email.data, form.email.data, ) user_db.put() task.activate_user_notification(user_db) cache.bump_auth_attempt() return flask.redirect(flask.url_for('welcome')) if form and form.errors: cache.bump_auth_attempt() title = 'Sign up' if config.CONFIG_DB.has_email_authentication else 'Sign in' return flask.render_template('auth/auth.html', title=title, html_class='auth', next_url=next_url, form=form, **urls_for_oauth(next_url))
def signup(): next_url = util.get_next_url() form = None if config.CONFIG_DB.has_email_authentication: form = form_with_recaptcha(SignUpForm()) save_request_params() if form.validate_on_submit(): user_db = model.User.get_by('email', form.email.data) if user_db: form.email.errors.append('This email is already taken.') if not form.errors: user_db = create_user_db( None, util.create_name_from_email(form.email.data), form.email.data, form.email.data, ) user_db.put() task.activate_user_notification(user_db) cache.bump_auth_attempt() return flask.redirect(flask.url_for('welcome')) if form and form.errors: cache.bump_auth_attempt() title = 'Sign up' if config.CONFIG_DB.has_email_authentication else 'Sign in' return flask.render_template( 'auth/auth.html', title=title, html_class='auth', next_url=next_url, form=form, **urls_for_oauth(next_url) )
def retrieve_user_from_gae(gae_user): auth_id = 'federated_%s' % gae_user.user_id() user_db = model.User.get_by('auth_ids', auth_id) if user_db: if not user_db.admin and users.is_current_user_admin(): user_db.admin = True user_db.put() return user_db return auth.create_user_db( auth_id=auth_id, name=util.create_name_from_email(gae_user.email()), username=gae_user.email(), email=gae_user.email(), verified=True, admin=users.is_current_user_admin(), )
def retrieve_user_from_google(google_user): auth_id = 'federated_%s' % google_user.user_id() user_db = model.User.get_by('auth_ids', auth_id) if user_db: if not user_db.admin and users.is_current_user_admin(): user_db.admin = True user_db.put() return user_db return create_user_db( auth_id, util.create_name_from_email(google_user.email()), google_user.email(), google_user.email(), verified=True, admin=users.is_current_user_admin(), )
def auth(): auth_type = 'open' if config.CONFIG_DB.has_email_authentication: auth_type = 'signin' if flask.url_for('signup') in flask.request.path: auth_type = 'signup' next_url = util.get_next_url() bitbucket_signin_url = url_for_signin('bitbucket', next_url) dropbox_signin_url = url_for_signin('dropbox', next_url) facebook_signin_url = url_for_signin('facebook', next_url) facebook_signin_url = url_for_signin('facebook', next_url) github_signin_url = url_for_signin('github', next_url) google_signin_url = url_for_signin('google', next_url) instgram_signin_url = url_for_signin('instagram', next_url) linkedin_signin_url = url_for_signin('linkedin', next_url) microsoft_signin_url = url_for_signin('microsoft', next_url) reddit_signin_url = url_for_signin('reddit', next_url) stackoverflow_signin_url = url_for_signin('stackoverflow', next_url) twitter_signin_url = url_for_signin('twitter', next_url) vk_signin_url = url_for_signin('vk', next_url) yahoo_signin_url = url_for_signin('yahoo', next_url) form = None hide_recaptcha = cache.get_auth_attempt() < config.RECAPTCHA_LIMIT # -------------- # Sign in stuff # -------------- if auth_type == 'signin': form = SignInForm() if hide_recaptcha or not config.CONFIG_DB.has_recaptcha: del form.recaptcha save_request_params() if form.validate_on_submit(): result = retrieve_user_from_email(form.email.data, form.password.data) if result: cache.reset_auth_attempt() return signin_user_db(result) if result is None: form.email.errors.append('Email or Password do not match') if result is False: return flask.redirect(flask.url_for('welcome')) if not form.errors: form.next_url.data = next_url # -------------- # Sign up stuff # -------------- if auth_type == 'signup': form = SignUpForm() if hide_recaptcha or not config.CONFIG_DB.has_recaptcha: del form.recaptcha save_request_params() if form.validate_on_submit(): user_db = model.User.get_by('email', form.email.data) if user_db: form.email.errors.append('This email is already taken.') if not form.errors: user_db = create_user_db( None, util.create_name_from_email(form.email.data), form.email.data, form.email.data, ) user_db.put() task.activate_user_notification(user_db) cache.bump_auth_attempt() return flask.redirect(flask.url_for('welcome')) if form and form.errors: cache.bump_auth_attempt() return flask.render_template( 'auth/auth.html', title='Sign up' if auth_type == 'signup' else 'Sign in', html_class='auth %s' % auth_type, bitbucket_signin_url=bitbucket_signin_url, dropbox_signin_url=dropbox_signin_url, facebook_signin_url=facebook_signin_url, github_signin_url=github_signin_url, google_signin_url=google_signin_url, instagram_signin_url=instgram_signin_url, linkedin_signin_url=linkedin_signin_url, microsoft_signin_url=microsoft_signin_url, reddit_signin_url=reddit_signin_url, stackoverflow_signin_url=stackoverflow_signin_url, twitter_signin_url=twitter_signin_url, vk_signin_url=vk_signin_url, yahoo_signin_url=yahoo_signin_url, next_url=next_url, form=form, auth_type=auth_type, )