--- /dev/null
+#!/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()
# 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
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:
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'