def create_user(backend, details, response, uid, username, email, password, user=None, *args, **kwargs): if user: return {'user': user} if not username or not email or not password: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None return { 'user': User.objects.create_user(username=username, email=email, password=password), 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') if email: user = User.objects.filter(email=email) if user: user = user[0] else: user = User.objects.create_user(username=username, email=email) else: user = User.objects.create_user(username=username, email=email) return { 'user': user, 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') return { 'user': User.objects.create_user(username=username, email=email), 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {"user": user} if not username: return None warn_setting("SOCIAL_AUTH_CREATE_USERS", "create_user") if not setting("SOCIAL_AUTH_CREATE_USERS", True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get("email") if EmailAddress.objects.filter(email=email): # TODO - Make this fail gracefully back to sign up message = ( "The email address provided by the external " "service is already associated with another account. Please " "log in to that account first and associate your account." ) raise AuthException(backend, message) else: user = User.objects.create_user(username=username, email=email) return { "user": user, "is_new": True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') request = kwargs.get('request') is_mobile = request.mobile if is_mobile: socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) raise ValueError('Registration is not possible on mobile') if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) raise ValueError('Registration is currently closed') email = details.get('email') return { 'user': User.objects.create_user(username=username, email=email), 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') request = kwargs["request"] user = User.objects.create_user(username=username, email=email) Account.create(request=request, user=user) EmailAddress.objects.add_email(user, user.email, primary=True) return { 'user': user, 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') request = kwargs["request"] user = User.objects.create_user(username=username, email=email) Account.create(request=request, user=user) EmailAddress.objects.add_email(user, user.email, primary=True) return {'user': user, 'is_new': True}
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') from lfsp.config.middleware import REQUEST_VARS user = User(network=REQUEST_VARS.domain_config.network, username=username) user.preferences.email = email user.save() return { 'user': user, 'is_new': True }
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {"user": user} if not username: return None warn_setting("SOCIAL_AUTH_CREATE_USERS", "create_user") if not getattr(settings, "SOCIAL_AUTH_CREATE_USERS", True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get("email") return {"user": User.objects.create_user(username=username, email=email), "is_new": True}
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): """Create user. Depends on get_username pipeline.""" if user: return {'user': user} if not username: return None warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not getattr(settings, 'SOCIAL_AUTH_CREATE_USERS', True): ################################################################ #Added by brianmckinney to allow us to only invite manly users ############################################################### from invite.models import Invitation invite_key = kwargs['request'].session.get('invite', "").strip() if invite_key: try: invite = Invitation.objects.get(key=invite_key) email = details.get('email') from invite.views import notify_admins, update_invite #Notify admins that we have a new user #notify_admins(username) #Update date accepted, invite status user = User.objects.create_user(username=username, email=email) update_invite(invite_key, username) return { 'user': user, 'is_new': True } except Invitation.DoesNotExist: pass ############## End edit ################################### # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None email = details.get('email') return { 'user': User.objects.create_user(username=username, email=email), 'is_new': True }
def create_user (backend, details, response, uid, username, email, password, user = None, *args, **kwargs): if user: return {'user':user} if not username or not email or not password: return None warn_setting ('SOCIAL_AUTH_CREATE_USERS', 'create_user') if not setting('SOCIAL_AUTH_CREATE_USERS', True): # Send signal for cases where tracking failed registering is useful. socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) return None return { 'user': User.objects.create_user(username=username, email=email, password=password), 'is_new': True }
def authenticate(self, *args, **kwargs): """Authenticate user using social credentials Authentication is made if this is the correct backend, backend verification is made by kwargs inspection for current backend name presence. """ # Validate backend and arguments. Require that the Social Auth # response be passed in as a keyword argument, to make sure we # don't match the username/password calling conventions of # authenticate. if not (self.name and kwargs.get(self.name) and 'response' in kwargs): return None # Pull in basics from the backend response = kwargs.get('response') details = self.get_user_details(response) uid = self.get_user_id(details, response) is_new = False user = kwargs.get('user') # If we've got an associated user, we're good to go try: social_user = self.get_social_auth_user(uid) except UserSocialAuth.DoesNotExist: # Oops! We don't know who you are! # There's two ways this can happen # 1. You're new here and we'll need to register you if that's the kind of place this is # 2. You've been here a while, but need to link this profile # Creating users is a pain, but we need to do that first so that we can link later if user is None: # You're new here! # Check to see if we've been told to create new users # First, we need permission from settings in the form of CREATE_USERS # Then we need to make sure that the kwarg for create_user isn't False if CREATE_USERS and kwargs.get('create_user', True): # We can create the user! JOY! # But wait! Shouldn't we check to see if there's already a user with this e-mail address and just link the two? email = details.get('email') if email and ASSOCIATE_BY_MAIL: # try to associate accounts registered with the same email # address, only if it's a single object. ValueError is # raised if multiple objects are returned try: user = User.objects.get(email=email) except MultipleObjectsReturned: raise ValueError('Not unique email address supplied') except User.DoesNotExist: user = None # OK. we're finally ready to create the account if we got to this point without a user if not user: username = self.username(details) print('Creating new user with username %s and email %s', username, sanitize_log_data(email)) logger.debug('Creating new user with username %s and email %s', username, sanitize_log_data(email)) user = User.objects.create_user(username=username, email=email) is_new = True else: # Wait a second! We can't create a user! We're forbidden by the settings or the kwargs # Send signal for cases where tracking failed registering # is useful. socialauth_not_registered.send(sender=self.__class__, uid=uid, response=response, details=details) return None # Now, we've either created a user or we've returned a None. Link! try: social_user = self.associate_auth(user, uid, response, details) except IntegrityError: # Protect for possible race condition, those bastard with FTL # clicking capabilities social_user = self.get_social_auth_user(uid) # Raise ValueError if this account was registered by another user. if user and user != social_user.user: raise ValueError('Account already in use.', social_user) user = social_user.user # Flag user "new" status setattr(user, 'is_new', is_new) # Update extra_data storage, unless disabled by setting if LOAD_EXTRA_DATA: extra_data = self.extra_data(user, uid, response, details) if extra_data and social_user.extra_data != extra_data: social_user.extra_data = extra_data social_user.save() user.social_user = social_user # Update user account data. self.update_user_details(user, response, details, is_new) return user
def authenticate(self, *args, **kwargs): """Authenticate user using social credentials Authentication is made if this is the correct backend, backend verification is made by kwargs inspection for current backend name presence. """ # Validate backend and arguments. Require that the Social Auth # response be passed in as a keyword argument, to make sure we # don't match the username/password calling conventions of # authenticate. if not (self.name and kwargs.get(self.name) and 'response' in kwargs): return None response = kwargs.get('response') details = self.get_user_details(response) uid = self.get_user_id(details, response) is_new = False user = kwargs.get('user') try: social_user = self.get_social_auth_user(uid) except UserSocialAuth.DoesNotExist: if user is None: # new user if not CREATE_USERS or not kwargs.get('create_user', True): # Send signal for cases where tracking failed registering # is useful. socialauth_not_registered.send(sender=self.__class__, uid=uid, response=response, details=details) return None email = details.get('email') if email and ASSOCIATE_BY_MAIL: # try to associate accounts registered with the same email # address, only if it's a single object. ValueError is # raised if multiple objects are returned try: user = User.objects.get(email=email) except MultipleObjectsReturned: raise ValueError('Not unique email address supplied') except User.DoesNotExist: user = None if not user: username = self.username(details) logger.debug('Creating new user with username %s and email %s', username, sanitize_log_data(email)) user = User.objects.create_user(username=username, email=email) is_new = True try: social_user = self.associate_auth(user, uid, response, details) except IntegrityError: # Protect for possible race condition, those bastard with FTL # clicking capabilities social_user = self.get_social_auth_user(uid) # Raise ValueError if this account was registered by another user. if user and user != social_user.user: raise ValueError('Account already in use.', social_user) user = social_user.user # Flag user "new" status setattr(user, 'is_new', is_new) # Update extra_data storage, unless disabled by setting if LOAD_EXTRA_DATA: extra_data = self.extra_data(user, uid, response, details) if extra_data and social_user.extra_data != extra_data: social_user.extra_data = extra_data social_user.save() user.social_user = social_user # Update user account data. self.update_user_details(user, response, details, is_new) return user