Capture names from 3rd party auth accounts
authorCharles Connell <charles@connells.org>
Tue, 21 Jan 2014 15:55:12 +0000 (10:55 -0500)
committerCharles Connell <charles@connells.org>
Tue, 21 Jan 2014 15:55:12 +0000 (10:55 -0500)
karmaworld/apps/users/forms.py [new file with mode: 0644]
karmaworld/apps/users/models.py
karmaworld/settings/common.py

diff --git a/karmaworld/apps/users/forms.py b/karmaworld/apps/users/forms.py
new file mode 100644 (file)
index 0000000..ee12d51
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# -*- coding:utf8 -*-
+# Copyright (C) 2013  FinalsClub Foundation
+from django import forms
+
+
+class SignupForm(forms.Form):
+    first_name = forms.CharField(max_length=255, required=False, label='Given name')
+    last_name  = forms.CharField(max_length=255, required=False, label='Family name')
+    email      = forms.EmailField(label='Email address')
+
+    def save(self, user):
+        user.first_name = self.cleaned_data['first_name']
+        user.last_name  = self.cleaned_data['last_name']
+        user.email      = self.cleaned_data['email']
+        user.save()
index 788b52845724d2c95ed74659e198a899f70040ac..fc5030820322b7efadccf5a13ea8b1073b2f2d15 100644 (file)
@@ -3,7 +3,8 @@
 # Copyright (C) 2013  FinalsClub Foundation
 import random
 import logging
-from allauth.account.signals import user_logged_in
+from allauth.account.signals import user_logged_in, user_signed_up, email_confirmed, email_changed, email_added
+from allauth.socialaccount.signals import pre_social_login
 from django.contrib.auth.models import User
 from django.core.exceptions import ObjectDoesNotExist
 from django.db.models.signals import post_save, pre_save
@@ -27,29 +28,14 @@ class UserProfile(models.Model):
 def user_display_name(user):
     """Return the best way to display a user's
     name to them on the site."""
-    if user.first_name or user.last_name:
+    if hasattr(user, 'first_name') and user.first_name and \
+            hasattr(user, 'last_name') and user.last_name:
         return user.first_name + ' ' + user.last_name
+    elif hasattr(user, 'email') and user.email:
+        return user.email
     else:
         return user.username
 
-
-@receiver(pre_save, sender=User, weak=True)
-def assign_username(sender, instance, **kwargs):
-    # If a user does not have a username, they need
-    # one before we save to the database
-    if not instance.username:
-        if instance.email:
-            try:
-                # See if any other users have this email address
-                others = User.objects.get(email=instance.email)
-            except ObjectDoesNotExist:
-                instance.username = instance.email
-            else:
-                instance.username = 'user' + str(random.randint(10000, 100000))
-        else:
-            instance.username = 'user' + str(random.randint(10000, 100000))
-
-
 @receiver(post_save, sender=User, weak=True)
 def create_user_profile(sender, instance, created, **kwargs):
     if created:
index 4c92b555dcae000afd81377d3e9e9854e79f65e4..09ab1c477f58ab5093086f3de04c76a9874fcb26 100644 (file)
@@ -266,11 +266,13 @@ ACCOUNT_AUTHENTICATION_METHOD = "email"
 ACCOUNT_CONFIRM_EMAIL_ON_GET = False
 ACCOUNT_EMAIL_VERIFICATION = "optional"
 ACCOUNT_EMAIL_SUBJECT_PREFIX = "KarmaNotes.org -- "
-ACCOUNT_USER_MODEL_EMAIL_FIELD = "email"
 ACCOUNT_USERNAME_REQUIRED = False
 SOCIALACCOUNT_EMAIL_REQUIRED = True
 SOCIALACCOUNT_EMAIL_VERIFICATION = "optional"
+SOCIALACCOUNT_QUERY_EMAIL = True
+SOCIALACCOUNT_AUTO_SIGNUP = False
 ACCOUNT_USER_DISPLAY = 'karmaworld.apps.users.models.user_display_name'
+ACCOUNT_SIGNUP_FORM_CLASS = 'karmaworld.apps.users.forms.SignupForm'
 
 AUTH_PROFILE_MODULE = 'users.UserProfile'