Skip to content

Commit

Permalink
#500 #507 #524 #224 Fixed create_user and disconnect for mongoengine
Browse files Browse the repository at this point in the history
  • Loading branch information
Shetty,Soumya committed Nov 14, 2012
1 parent 876fb63 commit af64235
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions social_auth/db/mongoengine_models.py
Expand Up @@ -44,28 +44,24 @@ def user_model(cls):

@classmethod
def create_user(cls, username, email=None):
"""
Create user with given username and email, sets an UNUSABLE_PASSWORD.
Base code borrwed from:
https://github.com/hmarr/mongoengine/blob/master/mongoengine/
django/auth.py#L129
"""
# Empty string makes email regex validation fail
if email == '':
email = None
return cls.user_model().create_user(username=username, password=UNUSABLE_PASSWORD, email=email)

# Normalize the address by lowercasing the domain part of the email
# address.
if email is not None:
try:
email_name, domain_part = email.strip().split('@', 1)
except ValueError:
pass
else:
email = '@'.join([email_name, domain_part.lower()])
user = cls(username=username, email=email)
user.password = UNUSABLE_PASSWORD
user.save()
return user
@classmethod
def allowed_to_disconnect(cls, user, backend_name, association_id=None):
if association_id is not None:
qs = cls.objects.filter(id__ne=association_id)
else:
qs = cls.objects.filter(provider__ne=backend_name)

if hasattr(user, 'has_usable_password'):
valid_password = user.has_usable_password()
else:
valid_password = True

return valid_password or qs.count() > 0


class Nonce(Document, NonceMixin):
Expand Down

0 comments on commit af64235

Please sign in to comment.