From 5784c12d7912fbf415995c737ed0f7afad02e7e0 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Mon, 20 May 2013 11:48:40 -0700 Subject: [PATCH] added a register_user function to be able to use in a plugin's register view, and modified auth/views.register to redirect to openid/register if appropriate. --- mediagoblin/auth/tools.py | 33 ++++++++++++++++++++++++++++++ mediagoblin/auth/views.py | 42 +++++++++++++-------------------------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py index 10fb6491..a1273d3b 100644 --- a/mediagoblin/auth/tools.py +++ b/mediagoblin/auth/tools.py @@ -108,6 +108,39 @@ def basic_extra_validation(register_form, *args): return extra_validation_passes +def register_user(request, register_form): + """ Handle user registration """ + extra_validation_passes = auth.extra_validation(register_form) + + if extra_validation_passes: + # Create the user + user = auth.create_user(register_form) + + # log the user in + request.session['user_id'] = unicode(user.id) + request.session.save() + + # send verification email + email_debug_message(request) + send_verification_email(user, request) + return user + + return None + + +def email_debug_message(request): + """ + If the server is running in email debug mode (which is + the current default), give a debug message to the user + so that they have an idea where to find their email. + """ + if mg_globals.app_config['email_debug_mode']: + # DEBUG message, no need to translate + messages.add_message(request, messages.DEBUG, + u"This instance is running in email debug mode. " + u"The email will be on the console of the server process.") + + EMAIL_VERIFICATION_TEMPLATE = ( u"http://{host}{uri}?" u"userid={userid}&token={verification_key}") diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 5be4b91b..f6d4d4d1 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -21,21 +21,10 @@ from mediagoblin.db.models import User from mediagoblin.tools.response import render_to_response, redirect, render_404 from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.auth import lib as auth_lib -from mediagoblin.auth.lib import send_verification_email -import mediagoblin.auth as auth - - -def email_debug_message(request): - """ - If the server is running in email debug mode (which is - the current default), give a debug message to the user - so that they have an idea where to find their email. - """ - if mg_globals.app_config['email_debug_mode']: - # DEBUG message, no need to translate - messages.add_message(request, messages.DEBUG, - u"This instance is running in email debug mode. " - u"The email will be on the console of the server process.") +from mediagoblin.auth import forms as auth_forms +from mediagoblin.auth.tools import (send_verification_email, + register_user, email_debug_message) +from mediagoblin import auth def register(request): @@ -53,24 +42,17 @@ def register(request): _('Sorry, registration is disabled on this instance.')) return redirect(request, "index") + if 'pass_auth' not in request.template_env.globals: + if 'openid' in request.template_env.globals: + return redirect(request, 'mediagoblin.plugins.openid.register') + register_form = auth.get_registration_form(request) if request.method == 'POST' and register_form.validate(): # TODO: Make sure the user doesn't exist already - extra_validation_passes = auth.extra_validation(register_form) - - if extra_validation_passes: - # Create the user - user = auth.create_user(register_form) - - # log the user in - request.session['user_id'] = unicode(user.id) - request.session.save() - - # send verification email - email_debug_message(request) - send_verification_email(user, request) + 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( @@ -97,6 +79,10 @@ def login(request): _('Sorry, authentication is disabled on this instance.')) return redirect(request, 'index') + if 'pass_auth' not in request.template_env.globals: + if 'openid' in request.template_env.globals: + return redirect(request, 'mediagoblin.plugins.openid.login') + login_form = auth.get_login_form(request) login_failed = False -- 2.25.1