added a register_user function to be able to use in a plugin's register view, and...
authorRodney Ewing <ewing.rj@gmail.com>
Mon, 20 May 2013 18:48:40 +0000 (11:48 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 24 May 2013 23:52:49 +0000 (16:52 -0700)
mediagoblin/auth/tools.py
mediagoblin/auth/views.py

index 10fb6491a9c4e3280f0c2ae80d5375f6fe324ac2..a1273d3b92b204f6e2ddfbad3b1a0472be68c96a 100644 (file)
@@ -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}")
index 5be4b91b5ecf9a396843a6f5bdea6649affc29f9..f6d4d4d1447ab62201167bf6c9d90e6ccfcf444e 100644 (file)
@@ -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