def user_exists(email, queryset=None): """ Return True if a user with given email address exists. Note that email address matches are case-insensitive. """ try: get_user(email, queryset) except User.DoesNotExist: return False return True
def authenticate(self, email=None, password=None): try: user = get_user(email) if user.check_password(password): return user except User.DoesNotExist: return None
def authenticate(self, email=None, password=None, force=False): try: user = get_user(email) user.backend = "%s.%s" % (self.__module__, self.__class__.__name__) return user except User.DoesNotExist: return None
def save(self, commit=True): email = self.cleaned_data["email"] if user_exists(email): # A 'User Seed' existing for this email address. user = get_user(email) user.set_password(self.cleaned_data["password1"]) seed_group = Group.objects.get(name=SEED_GROUP) user.groups.remove(seed_group) else: user = super(NewUserForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] if commit: user.save() mailingLists = [] if self.cleaned_data["subscribe_announce"]: mailingLists.append("Announcements_General") mailingLists.append("Signed_Up_on_Sefaria") if self.cleaned_data["subscribe_educator"]: mailingLists.append("Announcements_Edu") if mailingLists: try: subscribe_to_list(mailingLists, user.email, first_name=user.first_name, last_name=user.last_name) except: pass return user
def clean_email(self): email = self.cleaned_data["email"] if user_exists(email): user = get_user(email) if not user.groups.filter(name=SEED_GROUP).exists(): raise forms.ValidationError("A user with that email already exists.") return email
def save(self, commit=True): email = self.cleaned_data["email"] if user_exists(email): # A 'User Seed' existing for this email address. user = get_user(email) user.set_password(self.cleaned_data["password1"]) seed_group = Group.objects.get(name=SEED_GROUP) user.groups.remove(seed_group) else: user = super(SefariaNewUserForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] if commit: user.save() mailingLists = [] language = get_language() list_name = "Announcements_General_Hebrew" if language == "he" else "Announcements_General" mailingLists.append(list_name) if self.cleaned_data["subscribe_educator"]: list_name = "Announcements_Edu_Hebrew" if language == "he" else "Announcements_Edu" mailingLists.append(list_name) if mailingLists: mailingLists.append("Signed_Up_on_Sefaria") try: subscribe_to_list(mailingLists, user.email, first_name=user.first_name, last_name=user.last_name) except: pass return user
def clean_email(self): email = self.cleaned_data["email"] if user_exists(email): user = get_user(email) if not user.groups.filter(name=SEED_GROUP).exists(): raise forms.ValidationError(_("A user with that email already exists.")) return email
def __init__(self, email=None, user_obj=None): if email: self.user = get_user(email) elif user_obj: self.user = user_obj else: raise InputError("No user provided") self._errors = []
def authenticate(self, email=None, password=None): try: user = get_user(email) if user.check_password(password): user.backend = "%s.%s" % (self.__module__, self.__class__.__name__) return user except User.DoesNotExist: return None
def authenticate(self, email=None, password=None, **kwargs): # Some authenticators expect to authenticate by 'username' if email is None: email = kwargs.get('username') try: user = get_user(email) if user.check_password(password): user.backend = "%s.%s" % (self.__module__, self.__class__.__name__) return user except User.DoesNotExist: return None
def authenticate(self, email=None, password=None): # Never allow anyone without an email to log in, regardless of settings if not email: return None try: user = get_user(email) if user.check_password(password): user.backend = "%s.%s" % (self.__module__, self.__class__.__name__) return user except User.DoesNotExist: return None
def errors(self): if len(self._errors): return self._errors[0] if user_exists(self.email): u = get_user(self.email) if u.id != self.user.id: self._errors.append(_("A user with that email already exists")) email_val = EmailValidator() try: email_val(self.email) except ValidationError as e: self._errors.append(_("The email address is not valid.")) return self._errors[0] if len(self._errors) else None
def authenticate(self, request=None, email=None, password=None, **kwargs): # Some authenticators expect to authenticate by 'username' if email is None: email = kwargs.get('username') try: user = get_user(email) if user.check_password(password): user.backend = "%s.%s" % (self.__module__, self.__class__.__name__) return user except User.DoesNotExist: return None
def save(self, commit=True): email = self.cleaned_data["email"] if user_exists(email): # A 'User Seed' existing for this email address. user = get_user(email) user.set_password(self.cleaned_data["password1"]) seed_group = Group.objects.get(name=SEED_GROUP) user.groups.remove(seed_group) else: user = super(NewUserForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] if commit: user.save() if self.cleaned_data["subscribe_announce"]: try: subscribe_to_announce(user.email, first_name=user.first_name, last_name=user.last_name) except: pass return user
def save(self, commit=True): email = self.cleaned_data["email"] if user_exists(email): # A 'User Seed' existing for this email address. user = get_user(email) user.set_password(self.cleaned_data["password1"]) seed_group = Group.objects.get(name=SEED_GROUP) user.groups.remove(seed_group) else: user = super(NewUserForm, self).save(commit=False) user.first_name = self.cleaned_data["first_name"] user.last_name = self.cleaned_data["last_name"] if commit: user.save() """if self.cleaned_data["subscribe_announce"]: try: subscribe_to_announce(user.email, first_name=user.first_name, last_name=user.last_name) except: pass """ return user
def gp_data(response): """All these will just return their respective json data""" di = json.loads(response.POST.get("response")) accesstoken = di.get("access_token") endpoint = pull_user_me() # image = pull_user_image(di) url = prepare_url_to_call_graph_api(endpoint, accesstoken) resp = call_graph_api_get_data(url) di = prepare_json_data(resp) di['gid'] = di.get('id') di['name'] = ' ' . join ( di.get("name").values() ) di['gender'] = di.get('gender') di['profile_link'] = di.get('url') di['accesstoken'] = accesstoken di['response'] = str( resp.read() ) di['designation'] = "NA" # Settings is_active to True for the moment di['is_active'] = True # di['avatar'] = image # if create happens only then create User # otherwise, just set session & redirect #create fbuser email = None for k in di.get("emails"): if k['type'] == 'account': email = k['value'] password = "******" print "email" print email # if email is empty throw error if not email: raise Exception("No email present") # ========= # if user has email id like # then redirect to Restricted Email Detected Page # then If email not '@samhita.org' # again Restricted Email Detected page # if not a samhita.org email, again redirect to restricted_emails page # if '@samhita.org' not in email: # return HttpResponseRedirect("/") # restricted_emails = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] # for k in restricted_emails: # if email in restricted_emails[k]: # # redirect to restricted_emails page # return HttpResponseRedirect("/") # ========= # If not user, then create if not user_exists(email): # Create User create_user(email, password) # else: # # user = User.objects.filter(email=email) # # user = user[0] # user = get_user(email) user = get_user(email) response.user = user di['avatar'] = pull_user_image(response, di) print "user" print user # Create UserProfile user_p, cr = UserProfile.objects.get_or_create(user=user) # user_p = UserProfileForm(di, user=user) user_p.avatar = di['avatar'] user_p.save() # Create FBUserProfile fb_user_p = Guser.objects.filter(user=user, gid=di['gid']) # If not user create a user if not fb_user_p: print "NOT FB" form = GuserForm(di) print "form" print form print "errors" print form.errors fb_user_p = form.save(response, commit=False) fb_user_p.user = user # and not form.errors if form.is_bound and form.is_valid(): print "isbound isvalid" #enter fb_id, accesstoken, & then pass the POST variable to see if all fields are filled, #& then save, other wise u will hav to manually save each field by doing a save(commit=False) form.save(response, commit=True) else: print "Some Gplus FOrm invalid error errors while logging in." #then, #authenticate #&login #& redirect to '/' # fb_user = authenticate(email=user.email, password=user.password) fb_user = authenticate(email=user.email, password=password) if fb_user is not None: if fb_user.is_active: print "is active" #login(request, fb_user) login(response, fb_user) # redirect here return HttpResponseRedirect(reverse("googleapp.views.list_all")) else: print "Not active" else: print 'fb_user is None' return di
def fb_data(response): """All these will just return their respective json data""" accesstoken = response.POST.get('response[authResponse][accessToken]') endpoint = pull_user_me() url = prepare_url_to_call_graph_api(endpoint, accesstoken) resp = call_graph_api_get_data(url) di = prepare_json_data(resp) di['fb_id'] = di.get('id') di['accesstoken'] = accesstoken di['response'] = str( resp.read() ) # Settings is_active to True for the moment di['is_active'] = True # if create happens only then create User # otherwise, just set session & redirect # u = form.get_or_create() #create fbuser email = di.pop("email") password = "******" # If not user, then create if not user_exists(email): # Create User create_user(email, password) user = get_user(email) # Create UserProfile user_p, cr = UserProfile.objects.get_or_create(user=user) # Create FBUserProfile fb_user_p = FBUserProfile.objects.filter(user=user, fb_id=di['fb_id']) # If not user create a user if not fb_user_p: form = FBUserProfileForm(di) fb_user_p = form.save(commit=False) fb_user_p.user = user # and not form.errors if form.is_bound and form.is_valid(): #enter fb_id, accesstoken, & then pass the POST variable to see if all fields are filled, #& then save, other wise u will hav to manually save each field by doing a save(commit=False) form.save(commit=True) else: print "Some FB Form invalid error errors while logging in." else: # user = User.objects.filter(email=email) # user = user[0] user = get_user(email) #then, #authenticate #&login #& redirect to '/' # fb_user = authenticate(email=user.email, password=user.password) fb_user = authenticate(email=user.email, password=password) if fb_user is not None: if fb_user.is_active: #login(request, fb_user) login(response, fb_user) # redirect here return HttpResponseRedirect(reverse("stpros.views.list_all")) else: print "Not active" else: print 'fb_user is None' return di
def handle(self, *args, **options): email = options.get('email', None) interactive = options.get('interactive') verbosity = int(options.get('verbosity', 1)) # Do quick and dirty validation if --noinput if not interactive: if not email: raise CommandError("You must use --email with --noinput.") try: is_valid_email(email) except exceptions.ValidationError: raise CommandError("Invalid email address.") # If not provided, create the user with an unusable password password = None # Prompt for username/email/password. Enclose this whole thing in a # try/except to trap for a keyboard interrupt and exit gracefully. if interactive: try: # Get an email while 1: if not email: email = raw_input('E-mail address: ') try: is_valid_email(email) except exceptions.ValidationError: sys.stderr.write("Error: That e-mail address is invalid.\n") email = None continue try: get_user(email) except User.DoesNotExist: break else: sys.stderr.write("Error: That email is already taken.\n") email = None # Get a password while 1: if not password: password = getpass.getpass() password2 = getpass.getpass('Password (again): ') if password != password2: sys.stderr.write("Error: Your passwords didn't match.\n") password = None continue if password.strip() == '': sys.stderr.write("Error: Blank passwords aren't allowed.\n") password = None continue break except KeyboardInterrupt: sys.stderr.write("\nOperation cancelled.\n") sys.exit(1) # Make Django's tests work by accepting a username through # call_command() but not through manage.py username = options.get('username', None) if username is None: create_superuser(email, password) else: User.objects.create_superuser(username, email, password) if verbosity >= 1: self.stdout.write("Superuser created successfully.\n")
def gp_data(response): """All these will just return their respective json data""" di = json.loads(response.POST.get("response")) accesstoken = di.get("access_token") endpoint = pull_user_me() # image = pull_user_image(di) url = prepare_url_to_call_graph_api(endpoint, accesstoken) resp = call_graph_api_get_data(url) di = prepare_json_data(resp) di['gid'] = di.get('id') di['name'] = ' '.join(di.get("name").values()) di['gender'] = di.get('gender') di['profile_link'] = di.get('url') di['accesstoken'] = accesstoken di['response'] = str(resp.read()) di['designation'] = "NA" # Settings is_active to True for the moment di['is_active'] = True # di['avatar'] = image # if create happens only then create User # otherwise, just set session & redirect #create fbuser email = None for k in di.get("emails"): if k['type'] == 'account': email = k['value'] password = "******" print "email" print email # if email is empty throw error if not email: raise Exception("No email present") # ========= # if user has email id like # then redirect to Restricted Email Detected Page # then If email not '@samhita.org' # again Restricted Email Detected page # if not a samhita.org email, again redirect to restricted_emails page # if '@samhita.org' not in email: # return HttpResponseRedirect("/") # restricted_emails = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] # for k in restricted_emails: # if email in restricted_emails[k]: # # redirect to restricted_emails page # return HttpResponseRedirect("/") # ========= # If not user, then create if not user_exists(email): # Create User create_user(email, password) # else: # # user = User.objects.filter(email=email) # # user = user[0] # user = get_user(email) user = get_user(email) response.user = user di['avatar'] = pull_user_image(response, di) print "user" print user # Create UserProfile user_p, cr = UserProfile.objects.get_or_create(user=user) # user_p = UserProfileForm(di, user=user) user_p.avatar = di['avatar'] user_p.save() # Create FBUserProfile fb_user_p = Guser.objects.filter(user=user, gid=di['gid']) # If not user create a user if not fb_user_p: print "NOT FB" form = GuserForm(di) print "form" print form print "errors" print form.errors fb_user_p = form.save(response, commit=False) fb_user_p.user = user # and not form.errors if form.is_bound and form.is_valid(): print "isbound isvalid" #enter fb_id, accesstoken, & then pass the POST variable to see if all fields are filled, #& then save, other wise u will hav to manually save each field by doing a save(commit=False) form.save(response, commit=True) else: print "Some Gplus FOrm invalid error errors while logging in." #then, #authenticate #&login #& redirect to '/' # fb_user = authenticate(email=user.email, password=user.password) fb_user = authenticate(email=user.email, password=password) if fb_user is not None: if fb_user.is_active: print "is active" #login(request, fb_user) login(response, fb_user) # redirect here return HttpResponseRedirect(reverse("googleapp.views.list_all")) else: print "Not active" else: print 'fb_user is None' return di
def __init__(self, email=None): self.user = get_user(email) self._errors = []
def handle(self, *args, **options): email = options.get('email', None) interactive = options.get('interactive') verbosity = int(options.get('verbosity', 1)) # Do quick and dirty validation if --noinput if not interactive: if not email: raise CommandError("You must use --email with --noinput.") try: is_valid_email(email) except exceptions.ValidationError: raise CommandError("Invalid email address.") # If not provided, create the user with an unusable password password = None # Prompt for username/email/password. Enclose this whole thing in a # try/except to trap for a keyboard interrupt and exit gracefully. if interactive: try: # Get an email while 1: if not email: email = raw_input('E-mail address: ') try: is_valid_email(email) except exceptions.ValidationError: sys.stderr.write( "Error: That e-mail address is invalid.\n") email = None continue try: get_user(email) except User.DoesNotExist: break else: sys.stderr.write( "Error: That email is already taken.\n") email = None # Get a password while 1: if not password: password = getpass.getpass() password2 = getpass.getpass('Password (again): ') if password != password2: sys.stderr.write( "Error: Your passwords didn't match.\n") password = None continue if password.strip() == '': sys.stderr.write( "Error: Blank passwords aren't allowed.\n") password = None continue break except KeyboardInterrupt: sys.stderr.write("\nOperation cancelled.\n") sys.exit(1) # Make Django's tests work by accepting a username through # call_command() but not through manage.py username = options.get('username', None) if username is None: create_superuser(email, password) else: User.objects.create_superuser(username, email, password) if verbosity >= 1: self.stdout.write("Superuser created successfully.\n")