Commits

offline committed c2f56f8

bugfixes

Comments (0)

Files changed (4)

publicauth/backends/__init__.py

         Do nothing in case of failure.
         """
         # only actavted users can login if activation required.
-        if settings.PUBLICAUTH_ACTIVATION_REQUIRED and not request.user.is_active:
+        user = auth.authenticate(identity=self.identity, provider=self.provider)
+        if user and settings.PUBLICAUTH_ACTIVATION_REQUIRED and not request.user.is_active:
             messages.add_message(request, messages.ERROR, lang.NOT_ACTIVATED)
             raise Redirect(global_settings.LOGIN_REDIRECT_URL)
 
         # authenticate and redirect user.
-        user = auth.authenticate(identity=self.identity, provider=self.provider)
         if user:
             messages.add_message(request, messages.SUCCESS, lang.SUCCESSFULLY_AUTHENTICATED)
             auth.login(request, user)

publicauth/lang.py

 from django.conf import settings
 
 
+ACTIVATION_REQUIRED_TEXT = getattr(settings, "PUBLICAUTH_ACTIVATION_REQUIRED_TEXT", _('To complete registration, check your email and activate your account'))
 REGISTRATION_DISABLED = getattr(settings, "PUBLICAUTH_REGISTRATION_DISABLED", _('We are sorry, but registration is disabled. Come back later'))
 FILL_OPENID_URL = getattr(settings, "PUBLICAUTH_FILL_OPENID_URL", _('Please fill openid url field'))
 BACKEND_ERROR = getattr(settings, "PUBLICAUTH_BACKEND_ERROR", _('Your authentication provider returned bad response, please try again'))

publicauth/settings.py

 
 PUBLICAUTH_ACTIVATION_REQUIRED = getattr(settings, "PUBLICAUTH_ACTIVATION_REQUIRED", False)
 
+ACTIVATION_REDIRECT_URL = getattr(settings, "PUBLICAUTH_ACTIVATION_REDIRECT_URL", "/")
+
 EXTRA_FORM = getattr(settings, "PUBLICAUTH_EXTRA_FORM", "publicauth.forms.ExtraForm")

publicauth/views.py

     if request.method == "POST":
         form = str_to_class(settings.EXTRA_FORM)(request.POST)
         if form.is_valid():
-            user = form.save(identity, provider)
+            user = form.save(request, identity, provider)
             del request.session['identity']
-            user = auth.authenticate(identity=identity, provider=provider)
-            if user:
-                auth.login(request, user)
-                next_url = request.session['next_url']
-                del request.session['next_url']
-                return redirect(next_url)
+            if not settings.PUBLICAUTH_ACTIVATION_REQUIRED:
+                user = auth.authenticate(identity=identity, provider=provider)
+                if user:
+                    auth.login(request, user)
+                    next_url = request.session['next_url']
+                    del request.session['next_url']
+                    return redirect(next_url)
+            else:
+                messages.warning(request, lang.ACTIVATION_REQUIRED_TEXT)
+                return redirect(settings.ACTIVATION_REDIRECT_URL)
     else:
         initial = request.session['extra']
         form = str_to_class(settings.EXTRA_FORM)(initial=initial)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.