Commits

offline committed 55f1be0

javascript changed to core instead of mootools

  • Participants
  • Parent commits 24d36e3

Comments (0)

Files changed (4)

File openauth/settings.py

 ####################################################################################################
 
 ### LOGIN_REGEX ####################################################################################
-# TODO: implement logic to change the default regex when email                                     #
-#       authentication type set                                                                    #
 # The default login regex is to allow anything as login                                            #
 LOGIN_REGEX = get_config("LOGIN_REGEX", re.compile(r"^.*$"))                                       #
 ####################################################################################################
 ####################################################################################################
 
 ### LOGIN_LABEL ####################################################################################
-# TODO: Plase add logic to automaticaly change                                                     #
 # Please provide an appropriate label for you login field. The default for username type           #
 # of authentication is 'Login', for email authentication is 'Email'                                #
 LOGIN_LABEL = get_config("LOGIN_LABEL", None)                                                      #
 OPENID_EXTRA_FIELDS = get_config("OPENID_EXTRA_FIELDS", ['nickname'])                              #
 ####################################################################################################
 
-### OPENID_FIELDS_MAPPING ##########################################################################
+### OPENID_PROFILE_MAPPING #########################################################################
 # Please provide a mapping from OPENID_EXTRA_FIELDS to your profile fields.                        #
-OPENID_FIELDS_MAPPING = get_config("OPENID_FIELDS_MAPPING", {'nickname': 'login'})                 #
+OPENID_PROFILE_MAPPING = get_config("OPENID_PROFILE_MAPPING", {'nickname': 'login'})               #
 ####################################################################################################
 
 ### AX_URIS ########################################################################################

File openauth/templates/openauth/openid_login.html

 
 {% block content %}
 <script type="text/javascript">
-function customAuth(provider) {
-    var form = $('openid_login');
+function chooseProvider(provider) {
+    var form = document.getElementById('openid_login');
+    var url = document.getElementById('id_openid_url');
     if (provider == 'google') {
-        $('id_openid_url').set('value', 'https://www.google.com/accounts/o8/id');
+        url.value = 'https://www.google.com/accounts/o8/id';
         form.submit();
     } else if(provider == 'yahoo') {
-        $('id_openid_url').set('value', 'http://yahoo.com');
+        url.value =  'http://yahoo.com';
         form.submit();
     } else {
         alert('unknown provider');
     }
 }
 </script>
-<h2>Авторизация через OpenID</h2>
-
+<h2>OpenID Authorization and Registration</h2>
 
 <form action="." method="post" id="openid_login">
     {{ form.as_table }}
-    <p>Or with <input type="button" name="auth_google" onclick="customAuth('google')" value="Google"/></p>
-    <p>Or with <input type="button" name="auth_yahoo" onclick="customAuth('yahoo')" value="Yahoo"/></p>
+    <p>Or with <input type="button" name="auth_google" onclick="chooseProvider('google')" value="Google"/></p>
+    <p>Or with <input type="button" name="auth_yahoo" onclick="chooseProvider('yahoo')" value="Yahoo"/></p>
     <p><input type="submit" value="Continue"/></p>
 </form>
-<div>
-	<h3>Новый пользователь?</h3>
-	<p>Хотите зарегистироваться обычным способом перейдите на <span><a href="../registation/">страницу регистрации</a></span>.</p>
-</div>
 {% endblock %}

File openauth/utils.py

 
 
 def have_profile_name(field):
-    return field in openauth.settings.OPENID_FIELDS_MAPPING
+    return field in openauth.settings.OPENID_PROFILE_MAPPING
 
 
 def get_profile_field_name(field):
-    profile_field = openauth.settings.OPENID_FIELDS_MAPPING[field]
+    profile_field = openauth.settings.OPENID_PROFILE_MAPPING[field]
     return profile_field
 
 

File openauth/views.py

         form = ResetPasswordForm()
     return {'form': form}
 
-@login_required(opposite=True)
+
 @render_to('openauth/openid_login.html')
 def openid_login(request):
     """
-    If OpenID url was submitted then start OpenID authentication
-    else display OpenID authentication form
+    Display OpenID authentication form. This is also the first step
+    in OpenID registration. The actual login is in openid_complete 
+    function below.
     """
     if request.method == "POST":
         form = OpenIDLoginForm(request.POST, request=request)
     return {'form': form}
 
 
-
 def openid_complete(request):
     """
     Complete OpenID authorization process.
     If OpenID URL was successfuly authenticated:
-     * if user with such URL exists then login as this user
      * if no user with such URL exists and current user is authenticated then
        assign OpenID url to this user
+     * if user with such URL exists then login as this user
      * if no user with such URL exists then redirect to registration form
     """
     client = consumer.Consumer(request.session, None)
     data = dict(request.GET.items())
+
     # In case OpenID server responded with POST method
     if request.method == "POST":
         data.update(request.POST)
         resp = client.complete(data, request.session['openid_return_to'])
         del request.session['openid_return_to']
     except KeyError:
-        return notify_user.error(request, reverse("openauth-openid-login"), _("Invalid response received from OpenID server, please start start the authentication process again"))
+        return notify_user.error(request, 
+                reverse("openauth-openid-login"),
+                _("Invalid response received from OpenID server, please start start the authentication process again")
+                )
     if resp.status == consumer.CANCEL:
         return notify_user.error(request, "/", _('You have cancelled OpenID authorization'))
     elif resp.status == consumer.FAILURE:
                     auth.login(request, user)
                     return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, _("You have successfully authorized via OpenID"))
             else:
-                # user must fill addition fields to complete registration
+                if not openauth.settings.REGISTRATION_ALLOWED:
+                    return notify_user.notice(request, '/', openauth.lang.REGISTRATION_DISABLED)
+                # if user must fill addition fields to complete registration
                 # we ease this process by trying to fetch extra information
                 # from openid provider.
-                dump_openid_data(request, resp)
-                return redirect(reverse('openauth-openid-registration'))
+                if not openauth.settings.OPENID_PROFILE_MAPPING:
+                    OpenID(user=request.user, url=resp.identity_url).save()
+                    if not openauth.settings.OPENID_ACTIVATION_REQUIRED:
+                        user = auth.authenticate(openid_url=resp.identity_url)
+                        if user:
+                            auth.login(request, user)
+                            return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, _("You have successfully authorized via OpenID"))
+                else:
+                    dump_openid_data(request, resp)
+                    return redirect(reverse('openauth-openid-registration'))
+
     return notify_user.error(request, reverse("openauth-openid-login"), _("Invalid response received from OpenID server, please start start the authentication process again"))
 
 
                 params = {'domain': request.get_host(), 'email': user.email, 'url': confirmation.get_url(request)}
                 email_template(user.email, 'openauth/mail/registration.txt', **params)
                 return notify_user.success(request, "openauth-show-user", openauth.lang.PLEASE_ACTIVATE)
-            return notify_user.success(request, "/", _("You have been successfully registred"))
+            user = auth.authenticate(openid_url=openid_url)
+            if user:
+                auth.login(request, user)
+                return notify_user.success(request, "/", _("You have been successfully registred"))
     else:                                        
-        initial = extract_openid_data(request)
+        initial = {}
+        if openauth.settings.OPENID_PROFILE_MAPPING:
+            initial = extract_openid_data(request)
         form = str_to_class(openauth.settings.OPENID_REGISTRATION_FORM)(initial=initial)
 
     return {'form': form, 'openid_url': openid_url}