def register(request): """OpenID Registration View""" if request.method == 'GET': # Need to connect to openid provider before registering a user to # get the users openid url. If method is 'GET', then this page was # acessed without logging in first. return redirect(request, 'mediagoblin.plugins.openid.login') register_form = auth_forms.RegistrationForm(request.form) if register_form.validate(): user = register_user(request, register_form) if user: # redirect the user to their homepage... there will be a # message waiting for them to verify their email return redirect(request, 'mediagoblin.user_pages.user_home', user=user.username) return render_to_response( request, 'mediagoblin/auth/register.html', { 'register_form': register_form, 'post_url': request.urlgen('mediagoblin.plugins.openid.register') })
def finish_login(request): """Complete OpenID Login Process""" response = _finish_verification(request) if not response: # Verification failed, redirect to login page. return redirect(request, 'mediagoblin.plugins.openid.login') # Verification was successfull query = OpenIDUserURL.query.filter_by( openid_url=response.identity_url, ).first() user = query.user if query else None if user: # Set up login in session request.session['user_id'] = str(user.id) request.session.save() if request.session.get('next'): return redirect(request, location=request.session.pop('next')) else: return redirect(request, "index") else: # No user, need to register if not mg_globals.app_config['allow_registration']: messages.add_message( request, messages.WARNING, _('Sorry, registration is disabled on this instance.')) return redirect(request, 'index') # Get email and nickname from response email = _response_email(response) username = _response_nickname(response) register_form = auth_forms.RegistrationForm( request.form, openid=response.identity_url, email=email, username=username) return render_to_response( request, 'mediagoblin/auth/register.html', { 'register_form': register_form, 'post_url': request.urlgen('mediagoblin.plugins.openid.register') })