Commits

offline committed 88f420a

Profile mapping structure now changed

Comments (0)

Files changed (4)

openauth/backends/__init__.py

         """
         SocialID.objects.create(user=user, identity=self.get_identity(), provider=self.provider)
         request.flash['success'] =  _('OpenId record was added to your account')
+        auth.authenticate(identity=self.get_identity(), provider=self.provider)
         auth.login(request, user)
         raise Redirect(settings.LOGIN_REDIRECT_URL)
 
 
     def extract_data(self, data, field):
         try:
-            return {field: data.get(field, '')}
+            return {self.PROFILE_MAPPING[field][0]: data.get(field, '')}
         except AttributeError:
-            return {field: ''}
+            return {self.PROFILE_MAPPING[field][0]: ''}
 
     def validate_response(self, request):
         pass

openauth/backends/google.py

 
     def extract_data(self, data, field):
         try:
-            return {field: data.getSingle(settings.AX_URIS[field], '')}
+            return {self.PROFILE_MAPPING[field][0]: data.getSingle(settings.AX_URIS[field], '')}
         except:
-            return {field: ''}
+            return {self.PROFILE_MAPPING[field]: ''}
 

openauth/backends/twitter.py

     def get_extra_data(self, response):
         return urlparse.parse_qs(response, keep_blank_values=False)
 
-    def extract_data(self, data, profile_field, field):
+    def extract_data(self, data, field):
         try:
-            return {profile_field: data.get(field, '')[0]}
+            return {self.PROFILE_MAPPING[field][0]: data.get(field, '')[0]}
         except IndexError:
-            return {profile_field: ''}
+            return {self.PROFILE_MAPPING[field][0]: ''}
             
 

openauth/forms.py

 ResetPasswordForm = autostrip(ResetPasswordForm)
 
 
-class SocialIDExtraForm(forms.Form):
-    def __init__(self, *args, **kwargs):
-        fields = kwargs.pop("fields", {})
-        for key, value in fields.items():
-            self.base_fields[key] = value
-        super(SocialIDExtraForm, self).__init__(*args, **kwargs)
-
-    def clean_login(self):
-        login = self.cleaned_data['login']
-        if settings.UNIQUE_USERNAME and get_object_or_None(User, username=login):
-            raise forms.ValidationError("This username already taken");
-        return login
-
-    def save(self, identity, provider):
-        user = User.objects.create(username=self.cleaned_data['login'])
-        if settings.SOCIALID_ACTIVATION_REQUIRED:
-            user.is_active = False
-        user.save()
-        SocialID.objects.create(user=user, identity=identity, provider=provider)
-        return user
-
-
 class NewPasswordForm(forms.Form):
     """
     Form for changing user's password.
 
 NewPasswordForm = autostrip(NewPasswordForm)
 
+
+class SocialIDExtraForm(forms.Form):
+    def __init__(self, *args, **kwargs):
+        """
+        Form with fields from backend PROFILE_MAPPINGS setting.
+        """
+        fields = kwargs.pop("fields", {})
+        for key, value in fields.values():
+            self.base_fields[key] = value
+        super(SocialIDExtraForm, self).__init__(*args, **kwargs)
+
+    def save(self, identity, provider):
+        user = User.objects.create(username=self.cleaned_data['username'])
+        if settings.SOCIALID_ACTIVATION_REQUIRED:
+            user.is_active = False
+        user.save()
+        SocialID.objects.create(user=user, identity=identity, provider=provider)
+        return user
+
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.