Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 8 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
Showing with 86 additions and 37 deletions.
  1. +10 −0 ChangeLog
  2. +7 −0 README.rst
  3. +4 −1 allauth/account/app_settings.py
  4. +33 −8 allauth/account/forms.py
  5. +5 −8 allauth/account/utils.py
  6. +22 −18 allauth/facebook/views.py
  7. +5 −2 allauth/twitter/views.py
View
10 ChangeLog
@@ -1,3 +1,13 @@
+2011-05-29 Raymond Penners <raymond.penners@intenct.nl>
+
+ * SmileyChris contributed support for automatically generating a
+ user name at signup when ACCOUNT_USERNAME_REQUIRED is set to
+ False.
+
+ * Vuong Nguyen contributed support for (optionally) asking for the
+ password just once during signup
+ (ACCOUNT_SIGNUP_PASSWORD_VERIFICATION).
+
2011-04-22 Raymond Penners <raymond.penners@intenct.nl>
* The Twitter oauth sequence now respects the "oauth_callback"
View
7 README.rst
@@ -59,9 +59,16 @@ ACCOUNT_EMAIL_VERIFICATION (=False)
ACCOUNT_EMAIL_AUTHENTICATION (=False)
Login by e-mail address, not username
+ACCOUNT_SIGNUP_PASSWORD_VERIFICATION (=True)
+ When signing up, let the user type in his password twice to avoid typ-o's.
+
ACCOUNT_UNIQUE_EMAIL (=True)
Enforce uniqueness of e-mail addresses
+ACCOUNT_USERNAME_REQUIRED (=True)
+ If false, generates a random username rather than prompting for one
+ at signup
+
SOCIALACCOUNT_QUERY_EMAIL (=ACCOUNT_EMAIL_REQUIRED)
Request e-mail address from 3rd party account provider? E.g. using
OpenID AX, or the Facebook "email" permission
View
5 allauth/account/app_settings.py
@@ -14,7 +14,10 @@
UNIQUE_EMAIL = getattr(settings, "ACCOUNT_UNIQUE_EMAIL", True)
# Signup password verification
-SIGNUP_PASSWORD_VERIFICATION = getattr(settings, "SIGNUP_PASSWORD_VERIFICATION", True)
+SIGNUP_PASSWORD_VERIFICATION = getattr(settings, "ACCOUNT_SIGNUP_PASSWORD_VERIFICATION", True)
+
+# The user is required to enter a username when signing up
+USERNAME_REQUIRED = getattr(settings, "ACCOUNT_USERNAME_REQUIRED", True)
assert (not EMAIL_AUTHENTICATION) or EMAIL_REQUIRED
assert (not EMAIL_AUTHENTICATION) or UNIQUE_EMAIL
View
41 allauth/account/forms.py
@@ -1,4 +1,6 @@
+import base64
import re
+import uuid
from django import forms
from django.conf import settings
@@ -112,15 +114,23 @@ def __init__(self, *args, **kwargs):
else:
self.fields["email"].label = ugettext("E-mail (optional)")
self.fields["email"].required = False
+ if not USERNAME_REQUIRED:
+ del self.fields["username"]
+
+ def random_username(self):
+ return base64.urlsafe_b64encode(uuid.uuid4().bytes).strip('=')
def clean_username(self):
- if not alnum_re.search(self.cleaned_data["username"]):
- raise forms.ValidationError(_("Usernames can only contain letters, numbers and underscores."))
+ value = self.cleaned_data["username"]
+ if not alnum_re.search(value):
+ raise forms.ValidationError(_("Usernames can only contain "
+ "letters, numbers and underscores."))
try:
- user = User.objects.get(username__iexact=self.cleaned_data["username"])
+ User.objects.get(username__iexact=value)
except User.DoesNotExist:
- return self.cleaned_data["username"]
- raise forms.ValidationError(_("This username is already taken. Please choose another."))
+ return value
+ raise forms.ValidationError(_("This username is already taken. Please "
+ "choose another."))
def clean_email(self):
value = self.cleaned_data["email"]
@@ -132,7 +142,15 @@ def clean_email(self):
def create_user(self, commit=True):
user = User()
- user.username = self.cleaned_data["username"]
+ if USERNAME_REQUIRED:
+ user.username = self.cleaned_data["username"]
+ else:
+ while True:
+ user.username = self.random_username()
+ try:
+ User.objects.get(username=user.username)
+ except User.DoesNotExist:
+ break
user.email = self.cleaned_data["email"].strip().lower()
user.set_unusable_password()
if EMAIL_VERIFICATION:
@@ -149,7 +167,6 @@ class SignupForm(BaseSignupForm):
widget = forms.PasswordInput(render_value=False)
)
password2 = forms.CharField(
- required = SIGNUP_PASSWORD_VERIFICATION,
label = _("Password (again)"),
widget = forms.PasswordInput(render_value=False)
)
@@ -165,9 +182,17 @@ def __init__(self, *args, **kwargs):
"password1",
"password2",
"email"]
+ if not USERNAME_REQUIRED:
+ self.fields.keyOrder = ["email",
+ "password1",
+ "password2"]
+ if not SIGNUP_PASSWORD_VERIFICATION:
+ del self.fields["password2"]
def clean(self):
- if SIGNUP_PASSWORD_VERIFICATION and "password1" in self.cleaned_data and "password2" in self.cleaned_data:
+ if SIGNUP_PASSWORD_VERIFICATION \
+ and "password1" in self.cleaned_data \
+ and "password2" in self.cleaned_data:
if self.cleaned_data["password1"] != self.cleaned_data["password2"]:
raise forms.ValidationError(_("You must type the same password each time."))
return self.cleaned_data
View
13 allauth/account/utils.py
@@ -71,6 +71,7 @@ def perform_login(request, user):
messages.add_message(request, messages.SUCCESS,
ugettext("Successfully signed in as %(user)s.") % { "user": user_display(user) } )
+
def complete_signup(request, user, success_url):
if app_settings.EMAIL_VERIFICATION:
ctx = {
@@ -87,11 +88,7 @@ def complete_signup(request, user, success_url):
def send_email_confirmation(user, request=None):
email = user.email
if email:
- if request:
- messages.add_message \
- (request, messages.INFO,
- _(u"Confirmation e-mail sent to %(email)s") % {
- "email": email,
- }
- )
- EmailAddress.objects.add_email(user, user.email)
+ if EmailAddress.objects.add_email(user, user.email) and request:
+ messages.info(request,
+ _(u"Confirmation e-mail sent to %(email)s") % {"email": email}
+ )
View
40 allauth/facebook/views.py
@@ -12,7 +12,7 @@
from allauth.socialaccount.helpers import render_authentication_error
from allauth.socialaccount.oauth import OAuthClient
-from facebook import GraphAPI
+from facebook import GraphAPI, GraphAPIError
from models import FacebookApp, FacebookAccount
from forms import FacebookConnectForm
@@ -24,24 +24,28 @@ def login(request):
if request.method == 'POST':
form = FacebookConnectForm(request.POST)
if form.is_valid():
- token = form.cleaned_data['access_token']
- g = GraphAPI(token)
- facebook_me = g.get_object("me")
- email = valid_email_or_none(facebook_me.get('email'))
- social_id = facebook_me['id']
try:
- account = FacebookAccount.objects.get(social_id=social_id)
- except FacebookAccount.DoesNotExist:
- account = FacebookAccount(social_id=social_id)
- account.link = facebook_me['link']
- account.name = facebook_me['name']
- if account.pk:
- account.save()
- data = dict(email=email,
- facebook_me=facebook_me)
- # some facebook accounts don't have this data
- data.update((k,v) for (k,v) in facebook_me.items() if k in ['username', 'first_name', 'last_name'])
- ret = complete_social_login(request, data, account)
+ token = form.cleaned_data['access_token']
+ g = GraphAPI(token)
+ facebook_me = g.get_object("me")
+ email = valid_email_or_none(facebook_me.get('email'))
+ social_id = facebook_me['id']
+ try:
+ account = FacebookAccount.objects.get(social_id=social_id)
+ except FacebookAccount.DoesNotExist:
+ account = FacebookAccount(social_id=social_id)
+ account.link = facebook_me['link']
+ account.name = facebook_me['name']
+ if account.pk:
+ account.save()
+ data = dict(email=email,
+ facebook_me=facebook_me)
+ # some facebook accounts don't have this data
+ data.update((k,v) for (k,v) in facebook_me.items()
+ if k in ['username', 'first_name', 'last_name'])
+ ret = complete_social_login(request, data, account)
+ except GraphAPIError, e:
+ pass
if not ret:
ret = render_authentication_error(request)
return ret
View
7 allauth/twitter/views.py
@@ -11,7 +11,7 @@
from allauth.utils import get_login_redirect_url
from allauth.socialaccount.helpers import complete_social_login
from allauth.socialaccount.helpers import render_authentication_error
-from allauth.socialaccount.oauth import OAuthClient
+from allauth.socialaccount.oauth import OAuthClient, OAuthError
from models import TwitterApp, TwitterAccount
from utils import OAuthTwitter
@@ -22,7 +22,10 @@ def login_done(request):
request, app.consumer_key,
app.consumer_secret,
app.request_token_url)
- user_info = client.get_user_info()
+ try:
+ user_info = client.get_user_info()
+ except OAuthError, e:
+ return render_authentication_error(request)
try:
account = TwitterAccount.objects.get(social_id=user_info['id'])
except TwitterAccount.DoesNotExist:

No commit comments for this range

Something went wrong with that request. Please try again.