Commits

benoitc  committed 2a2be1c

prepare multiple openid associaton for one user

  • Participants
  • Parent commits 0f07989

Comments (0)

Files changed (3)

File django_authopenid/forms.py

 
 class OpenidRegisterForm(forms.Form):
     """ openid signin form """
-    next = forms.CharField(max_length=255, widget=forms.HiddenInput(), 
-            required=False)
     username = forms.CharField(max_length=30, 
             widget=forms.widgets.TextInput(attrs=attrs_dict))
     email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict, 
         maxlength=200)), label=u'Email address')
+        
+    def __init__(self, *args, **kwargs):
+        super(OpenidRegisterForm, self).__init__(*args, **kwargs)
+        self.user = None
     
     def clean_username(self):
         """ test if username is valid and exist in database """
             try:
                 user = User.objects.get(
                         username__exact = self.cleaned_data['username']
-                        )
+                )
             except User.DoesNotExist:
                 return self.cleaned_data['username']
             except User.MultipleObjectsReturned:
                 raise forms.ValidationError(u'There is already more than one \
                     account registered with that username. Please try \
                     another.')
+            self.user = user
             raise forms.ValidationError(_("This username is already \
                 taken. Please choose another."))
             

File django_authopenid/models.py

     model to manage association between openid and user 
     """
     openid_url = models.CharField(blank=False, max_length=255)
-    user = models.ForeignKey(User, unique=True)
+    user = models.ForeignKey(User, unique=False)
     
     def __unicode__(self):
         return "Openid %s with user %s" % (self.openid_url, self.user)

File django_authopenid/views.py

     if request.POST:
         if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
             redirect_to = settings.LOGIN_REDIRECT_URL     
-        if 'bsignin' in request.POST.keys():
+        if 'openid_url' in request.POST.keys():
             form1 = openid_form(data=request.POST)
             if form1.is_valid():
                 sreg_req = sreg.SRegRequest(optional=['nickname', 'email'])
                         redirect_url, 
                         on_failure=on_failure, 
                         sreg_request=sreg_req)
-        elif 'blogin' in request.POST.keys():
+        else:
             # perform normal django authentification
             form2 = auth_form(data=request.POST)
             if form2.is_valid():
         if 'openid_url' in request.POST.keys():
             form1 = register_form(data=request.POST)
             if form1.is_valid():
-                user_ = register_account(form1, str(openid_))     
+                user_ = register_account(form1, str(openid_))
         else:
             form2 = auth_form(data=request.POST)
             if form2.is_valid():