Commits

offline committed 097ee9f

autologin ability added to allow auto login after registration when no activation needed

  • Participants
  • Parent commits 759148b

Comments (0)

Files changed (2)

File openauth/settings.py

 LOGIN_REDIRECT_URL = get_config("LOGIN_REDIRECT_URL", "/auth/user/")                               #
 ####################################################################################################
 
+### AUTO_LOGIN #####################################################################################
+# This allow login automaticaly after registration if actiovation doesn't required                 #
+AUTO_LOGIN = get_config("AUTO_LOGIN", True)                                                        #
+####################################################################################################
+
 ### ACTIVATION_AUTO_LOGIN ##########################################################################
 # This allow login automaticaly after clicking the  activation link in email in case your site     #
 # require activation                                                                               #

File openauth/views.py

 from openid.consumer import consumer, discover
 from openid.extensions import sreg, ax
 
+from django.shortcuts import get_object_or_404, redirect
+from django.contrib.auth import login as login_user
+from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
 from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
 from django.contrib import auth 
-from django.shortcuts import get_object_or_404, redirect
-from django.utils.translation import ugettext as _
 from django.http import Http404
 
+from confirmation.models import Confirmation
 from annoying.decorators import render_to
-from confirmation.models import Confirmation
 from notify import notify_user
 
 import openauth
                     user.delete()
                     return notify_user.error(request, "/", openauth.lang.ERROR_SENDING_MAIL)
             else:
+                if openauth.settings.AUTO_LOGIN:
+                    user.backend = 'django.contrib.auth.backends.ModelBackend'
+                    login_user(request, user)
+                    return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, 
+                                                openauth.lang.SUCCESSFULL_LOGIN)
                 return notify_user.success(request, "openauth-login", openauth.lang.LOGIN_NOW)
     else:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)()