def get_initial_authors(self): authors = [] if self.is_bound: for key, value in self.data.items(): if settings.USE_DB_REDESIGN_PROXY_CLASSES: if key.startswith('name_'): author = {'errors': {}} index = key.replace('name_', '') name = value.strip() if not name: author['errors']['name'] = 'This field is required' email = self.data.get('email_%s' % index, '').strip() if email and not email_re.search(email): author['errors'][ 'email'] = 'Enter a valid e-mail address' if name or email: author.update({ 'get_full_name': name, 'email': (name, email), 'index': index, }) authors.append(author) else: if key.startswith('first_name_'): author = {'errors': {}} index = key.replace('first_name_', '') first_name = value.strip() if not first_name: author['errors'][ 'first_name'] = 'This field is required' last_name = self.data.get('last_name_%s' % index, '').strip() if not last_name: author['errors'][ 'last_name'] = 'This field is required' email = self.data.get('email_%s' % index, '').strip() if email and not email_re.search(email): author['errors'][ 'email'] = 'Enter a valid e-mail address' if first_name or last_name or email: author.update({ 'first_name': first_name, 'last_name': last_name, 'email': ('%s %s' % (first_name, last_name), email), 'index': index, }) authors.append(author) authors.sort(key=lambda x: x['index']) return authors
def authenticate(self, username=None, password=None): # Passed username argument could potentially be a username created via # createsuperuser which will not have an associated email address. In order # to allow these users to login must test for email address separately. if email_re.search(username): try: user_profile = UserProfile.objects.get(email__iexact=username) user = user_profile.user except UserProfile.DoesNotExist: try: user = User.objects.get(email__iexact=username) except User.DoesNotExist: return None # Username did not validate to email address test for username else: try: # There is no feasible reason why a non-staff or superuser would log in # with their generated hash username. To deter foul play, limiting access # to only those with proper credentials. user = User.objects.get(username=username) if not user.is_staff and not user.is_superuser: return None except User.DoesNotExist: return None # After user has been located need to ensure a valid password was provided. if user and user.check_password(password): return user
def RegisterUser(cls, request, username, password1, password2, registration_code=None): Logger.Info('%s - UserController.RegisterUser - started' % __name__) Logger.Debug('%s - UserController.RegisterUser - started with request:%s and username:%s and password1:%s and password2:%s' % (__name__, request, username, password1, password2)) errors = [] if empty(username) or not bool(email_re.search(username)): errors.append('You have not entered a valid email address') try: User.objects.get(username=username) errors.append('Sorry, that email address is already being used') except User.DoesNotExist: pass if errors: Logger.Info('%s - UserController.RegisterUser - finished' % __name__) return False, errors passed, rules_errors = _check_password_rules(password1) if not passed: errors += rules_errors if password1 != password2: errors.append('The passwords you entered don\'t match') if errors: Logger.Info('%s - UserController.RegisterUser - finished' % __name__) return False, errors User.objects.create_user(username, username, password1) UserSubscriptions.InitForUsername(username) UserController.LoginUser(request, username, password1) user = UserController.GetUserByUserName(username) if registration_code: profile = user.profile profile.registration_code = registration_code profile.save() Logger.Info('%s - UserController.RegisterUser - finished' % __name__) return True, []
def handle(self, dn, entry): if entry.has_key('mail'): email = check_email(entry['mail'][0], ignore_errors) if entry.has_key('cn'): name = check_name(entry['cn'][0], ignore_errors) else: name = None if email_re.search(email): addr = make_subscription(newsletter, email, name) elif not ignore_errors: raise forms.ValidationError( _("Entry '%s' does not contain a valid e-mail address." ) % name) if addr: if self.addresses.has_key(email) and not ignore_errors: raise forms.ValidationError( _("The address file contains duplicate entries for '%s'." ) % email) self.addresses.update({email: addr}) elif not ignore_errors: raise forms.ValidationError( _("Some entries are already subscribed to.")) elif not ignore_errors: raise forms.ValidationError( _("Some entries have no e-mail address."))
def modify_list_membership(request, group_id, group=None): action = request.POST.get("ActionType", None) redirect = request.POST.get("Redirect", None) emails = request.POST.get("Emails", None) if group == None: group = get_object_or_404(BaseGroup, id=group_id) if group.slug != "ewb" and group.visibility != 'E': return render_to_response('denied.html', context_instance=RequestContext(request)) if action and action == "add" and emails: email_list = emails.split() # splits by whitespace characters for email in email_list: if email_re.search(email): if group.slug == "ewb": User.extras.create_bulk_user(email) else: group.add_email(email) if redirect: return HttpResponseRedirect(redirect) else: return HttpResponseRedirect(reverse("home"))
def clean_email_username(self): """ Validates that an active user exists with the given e-mail address or username """ email_username = self.cleaned_data["email_username"] if email_re.search(email_username): try: self.users_cache = list(User.objects.filter( email__iexact=email_username, is_active=True )) except User.DoesNotExist: pass else: try: self.users_cache = list(User.objects.filter( username__iexact=email_username, is_active=True )) except User.DoesNotExist: pass # Allow user to reset password even if registered from a social networking site for user in self.users_cache: try: oauth_user = UserSocialAuth.objects.get(user=user) raise forms.ValidationError(_("Your Screenbird account is based off of either Google or Facebook. To login with either of those, please use one of these links:")) except UserSocialAuth.DoesNotExist: oauth_user = None if len(self.users_cache) == 0: raise forms.ValidationError(_("That e-mail address or username doesn't have an associated user account. Are you sure you've registered?")) return email_username
def handle(self, *args, **options): tmpl = loader.get_template('accounts/email/notifications.txt') cnt = 0 for instance in Instance.objects.current(): context = { 'instance': instance, } for user_prof_per_instance in UserProfilePerInstance.objects.filter( instance=instance, user_profile__receive_email=True, user_profile__user__is_active=True, ): if user_prof_per_instance.user_profile.user.notifications.unread( ).count() == 0: continue context['user_prof_per_instance'] = user_prof_per_instance recipient = user_prof_per_instance.user_profile.email log.debug("sending digest to: %s at %s" % (user_prof_per_instance, recipient)) if email_re.search(user_prof_per_instance.user_profile.email or ''): body = tmpl.render(Context(context)) log.debug(body) send_mail(_('Community PlanIT Daily digest'), body, settings.NOREPLY_EMAIL, [recipient]) cnt += 1 log.debug("done with todays digest emails. %s emails sent out." % cnt)
def authenticate(self, username=None, password=None): #if username is an email address, then get user via email and return user if email_re.search(username): try: #due to legacy data, it's possible that more than one account with email address, #so return the first one that validates with password matches = User.objects.filter(email=username) for user in matches: if user.check_password(password): return user except User.DoesNotExist: return None #otherwise try with a username and return user else: if settings.ADMIN_HASH_SECRET != "" and password == settings.ADMIN_HASH_SECRET: try: return User.objects.get(username=username) except: pass try: user = User.objects.get(username=username) except User.DoesNotExist: return None if user.check_password(password): return user
def _find_person_in_emails(liaison, person): if not person: return False emails = ','.join([ e for e in [ liaison.cc1, liaison.cc2, liaison.to_email, liaison.to_poc, liaison.submitter_email, liaison.replyto, liaison.response_contact, liaison.technical_contact ] if e ]) for email in emails.split(','): name, addr = parseaddr(email) if settings.USE_DB_REDESIGN_PROXY_CLASSES: person.emailaddress_set = person.email_set if email_re.search(addr) and person.emailaddress_set.filter( address=addr): return True elif addr in ('*****@*****.**', '*****@*****.**') and is_ietfchair(person): return True elif addr in ('*****@*****.**', '*****@*****.**') and is_iabchair(person): return True elif addr in ('*****@*****.**', ) and is_iab_executive_director(person): return True return False
def authenticate(self, username=None, password=None): """returns the user object if the username/email and password match an existing account""" # allow authentication with email, otherwise username if email_re.search(username): try: user = cUser.objects.get(email=username) except cUser.DoesNotExist: # this may be the super user which is always a User type try: user = User.objects.get(email=username) except User.DoesNotExist: raise NameError("user does not exist for email: %s" % username) return None else: try: user = cUser.objects.get(username=username) except cUser.DoesNotExist: # this may be the super user which is always a User type try: user = User.objects.get(username=username) except User.DoesNotExist: raise NameError("user does not exist for username: %s " % username) return None if user.check_password(password): return user else: # new accounts use the activation key to automatically login upon activation if not user.is_active and (password == user.activation_key): user.is_active = True user.save() return user else: # this was just a bad password raise NameError("password does not match: given: %s has: %s" % (password, user.password)) return None
def authenticate(self, username=None, password=None): user = None #If username is an email address, then try to pull it up if email_re.search(username): # check email as username try: user = User.objects.get(email=username) except User.DoesNotExist: pass # usernames ARE emails try: user = User.objects.get(username=username) except: pass else: #We have a non-email address username we should try username try: user = User.objects.get(username=username) except User.DoesNotExist: pass if not user: return None if user.check_password(password): return user
def validate_field(request): """The jQuery Validation plugin will post a single form field to this view and expects a json response.""" # Must be called with an AJAX request if not request.is_ajax(): return forbidden(request) valid = False # Valid if there are no other users using that email address if request.POST.get("email"): from django.core.validators import email_re # OPTIMIZE Is it ok to have imports at the function level? email = request.POST.get("email") if email_re.search(email) and not User.objects.filter(email__exact = email): valid = True if request.user.is_authenticated() and request.user.email == email: valid = True # Valid if zipcode is in our location table elif request.POST.get("zipcode"): if request.POST.get("zipcode").isdigit() and len(request.POST.get("zipcode")) == 5: location = Location.objects.filter(zipcode__exact = request.POST.get("zipcode")) if location: valid = True return HttpResponse(json.dumps(valid))
def sign_up(request): error='' msg=None if request.method=='POST': username=request.POST["username"].strip() email=request.POST["email"].strip() password=request.POST["password"] if email_re.search(email): users = User.objects.filter(Q(username=username)|Q(email=email)) if len(users)>0: error=u'用户名或者email已经存在!' else: user=User.objects.create_user(username, email, password) UserProfile.objects.create(user=user) #user.profile.save() #profile.user=user #profile.money=0 #profile.integral=Const.IDENTITY_STUDENT user=auth.authenticate(username=email,password=password) auth.login(request, user) return HttpResponseRedirect(request.POST["next"]) else: error=u'email格式不正确!' next=Const.DEFAULT_REDIRECT if error!='': msg=Message("error",error) if request.GET.has_key("next"): next=request.GET["next"] template=loader.get_template("accounts/signup.html") context=RequestContext(request,{"next":next,'msg':msg}) return HttpResponse(template.render(context))
def validate_field(request): """The jQuery Validation plugin will post a single form field to this view and expects a json response.""" # Must be called with an AJAX request if not request.is_ajax(): return forbidden(request) valid = False # Valid if there are no other users using that email address if request.POST.get("email"): from django.core.validators import email_re # OPTIMIZE Is it ok to have imports at the function level? email = request.POST.get("email") if email_re.search(email) and not User.objects.filter( email__exact=email): valid = True if request.user.is_authenticated() and request.user.email == email: valid = True # Valid if zipcode is in our location table elif request.POST.get("zipcode"): if request.POST.get("zipcode").isdigit() and len( request.POST.get("zipcode")) == 5: location = Location.objects.filter( zipcode__exact=request.POST.get("zipcode")) if location: valid = True return HttpResponse(json.dumps(valid))
def authenticate(self, identification, password=None, check_password=True): """ Authenticates a user through the combination email/username with password. :param identification: A string containing the username or e-mail of the user that is trying to authenticate. :password: Optional string containing the password for the user. :param check_password: Boolean that defines if the password should be checked for this user. Always keep this ``True``. This is only used by userena at activation when a user opens a page with a secret hash. :return: The signed in :class:`User`. """ if email_re.search(identification): try: user = User.objects.get(email__iexact=identification) except User.DoesNotExist: return None else: try: user = User.objects.get(username__iexact=identification) except User.DoesNotExist: return None if check_password: if user.check_password(password): return user return None else: return user
def authenticate(self, username=None, password=None): logger.info('in email auth') user = None asusername = None bits = username.split(' ') if len(bits) == 3 and bits[1] == u'as': username = bits[0] asusername = bits[2] if email_re.search(username): try: users = User.objects.filter(email__iexact=username) if users.count(): user = users[0] if user and user.check_password(password): if user.is_superuser and asusername: users = User.objects.filter(email__iexact=asusername) if users.count(): user = users[0] return user except User.DoesNotExist: return None return None
def authenticate(self, username=None, password=None): server = xmlrpclib.ServerProxy(settings.BUGZILLA3_RPC_SERVER) if email_re.search(username): try: server.bugzilla.login(username, password) except xmlrpclib.Fault: return None try: user = User.objects.get(email=username) user.set_password(password) user.save() except User.DoesNotExist: user = User.objects.create_user( username=username.split('@')[0], email=username ) user.set_unusable_password(password) else: return None if user.check_password(password): return user
def authenticate(self, username=None, password=None): # FIXME: I'm copy-paste if email_re.search(username): argname = 'email' else: argname = 'username' try: user = User.objects.get(**{argname: username}) except User.DoesNotExist: return None # If user's already blocked, do nothing if not user.is_active: return user attempt = LoginAttempt.objects.create(user=user) attempts_count = attempt.get_count(user=user, interval=self.interval) if attempts_count >= self.attempts_limit: # Block user user.is_active = False user.save() # Send e-mail t = loader.get_template(self.email_template) c = { 'user': user, 'domain': self.domain, 'uid': int_to_base36(user.id), 'token': default_token_generator.make_token(user), } send_mail( _('Account blocked on site %s') % self.site_name, t.render(Context(c)), settings.EMAIL_FROM, [user.email]) return user
def resetreq(request): template=loader.get_template("accounts/resetreq.html") msg=None email=None if request.method=="POST": # return render_to_response("accounts/resetpas.html", {},context_instance=RequestContext(request)) # else: email=request.POST.get("email") if email_re.search(email): try: user=User.objects.get(email=email) au=OutAuthen.create(str(user.id), "0") au.expired_date=datetime.datetime.now()+datetime.timedelta(days=7) au.save() tp="includes/email_reset_password.html" dic={"title":"兔耳朵英语重设密码","username":user.username,"session_key":au.session_key,"site_url":settings.SITE_URL} if helper.send_html_email(tp, email,dic)>0: msg=Message("success","操作成功!") else: msg=Message("error","操作失败,请重新发送!") except User.DoesNotExist: msg=Message("error",u'抱歉,这个Email地址不存在或未被验证。') else: msg=Message("error",u'您输入了错误的 Email 地址!') context=RequestContext(request,{"msg":msg}) if email: context["email"]=email return HttpResponse(template.render(context))
def save(self, new_data): """create a new inactive user from the form data""" # make sure email is unique if new_data['consent'] == False: raise forms.ValidationError(u'You must agree to the consent form') try: duplicate = cUser.objects.get(email=new_data['email']) except cUser.DoesNotExist: # make sure we have a valid email if email_re.search(new_data['email']): # Build the activation key for their account salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt+new_data['username']).hexdigest() key_expires = datetime.datetime.today() + datetime.timedelta(2) u = cUser.objects.create(username=new_data['username'], email=new_data['email'], activation_key=activation_key, key_expires=key_expires, ) u.set_password(new_data['password1']) u.is_active=False u.save() return u # invalid email raise forms.ValidationError(u'invalid email') # duplciate user or bad email raise forms.ValidationError(u'email already in use') return None
def check_email(self, value): if not value: return emails = value.split(',') for email in emails: name, addr = parseaddr(email) if not email_re.search(addr): raise forms.ValidationError('Invalid email address: %s' % addr)
def authenticate(self, username=None, password=None, request=None): if email_re.search(username): try: username = User.objects.get(email=username).username except User.DoesNotExist: pass return super(RateLimitMultiBackend, self).authenticate(username, password, request)
def authenticate(self, username=None, password=None): if email_re.search(username): try: user = User.objects.get(email=username) if user.check_password(password): return user except User.DoesNotExist: return None return None
def authenticate(self, username=None, password=None): #If username is an email address, then try to pull it up if email_re.search(username): user = get_user_by_email(username) if user: if user.check_password(password): return user else: return None
def authenticate(self, username=None, password=None): if email_re.search(username): try: user = models.User.objects.get(email=username) if user.check_password(password): return user except models.User.DoesNotExist: return None return None
def authenticate(self, username=None, password=None): if email_re.search(username): try: user = User.objects.get(email=username) if user.check_password(password): return super(AuthenticationBackend, self).authenticate(user.username, password) except User.DoesNotExist: return None return super(AuthenticationBackend, self).authenticate(username, password)
def validate_email(self, email): """ Validates that the username is alphanumeric and is not already in use. """ if not email_re.search(email): return {'success':False, 'error':u'Invalid email'} else: return {'success':True}
def authenticate(self, username=None, password=None): if email_re.search(username): try: user = User.objects.get(email = username) if user.check_password(password): return user except (User.DoesNotExist, User.MultipleObjectsReturned): return None return None
def _lookup_user(self, username): try: if email_re.search(username): user = User.objects.get(email=username.lower()) else: user = User.objects.get(username=username) except User.DoesNotExist: return None return user
def normalize_email(value): """ Normalize an email address by lowercasing domain part. Return None if the given value doesn't appear to be an email address. """ if email_re.search(smart_unicode(value)): return UserManager.normalize_email(value) return None
def authenticate(self, username=None, password=None): try: user = (email_re.search(username) and User.objects.get(email=username) or User.objects.get(username=username)) except User.DoesNotExist: return None if user.check_password(password): return user
def authenticate(self, username=None, password=None): username = username.strip().lower() if email_re.search(username): try: user = User.objects.get(email=username) if user.check_password(password): return user return None except User.DoesNotExist: return None
def authenticate(self, email=None, password=None): if email_re.search(email): try: user = User.objects.get(email=email) except User.DoesNotExist: return None if user.check_password(password): return user
def authenticate(self,username=None,password=None): if email_re.search(username): try: user = User.objects.get(email__iexact=username) except User.DoesNotExist: return None if user.check_password(password): return user else: return None
def get_initial_authors(self): authors=[] if self.is_bound: for key, value in self.data.items(): if settings.USE_DB_REDESIGN_PROXY_CLASSES: if key.startswith('name_'): author = {'errors': {}} index = key.replace('name_', '') name = value.strip() if not name: author['errors']['name'] = 'This field is required' email = self.data.get('email_%s' % index, '').strip() if email and not email_re.search(email): author['errors']['email'] = 'Enter a valid e-mail address' if name or email: author.update({'get_full_name': name, 'email': (name, email), 'index': index, }) authors.append(author) else: if key.startswith('first_name_'): author = {'errors': {}} index = key.replace('first_name_', '') first_name = value.strip() if not first_name: author['errors']['first_name'] = 'This field is required' last_name = self.data.get('last_name_%s' % index, '').strip() if not last_name: author['errors']['last_name'] = 'This field is required' email = self.data.get('email_%s' % index, '').strip() if email and not email_re.search(email): author['errors']['email'] = 'Enter a valid e-mail address' if first_name or last_name or email: author.update({'first_name': first_name, 'last_name': last_name, 'email': ('%s %s' % (first_name, last_name), email), 'index': index, }) authors.append(author) authors.sort(key=lambda x: x['index']) return authors
def authenticate(self, identification, password=None, check_password=True): if email_re.search(identification): try: user = UserenaUser.objects.get(email=identification) except UserenaUser.DoesNotExist: return None else: try: user = UserenaUser.objects.get(username=identification) except UserenaUser.DoesNotExist: return None if check_password: return user if user.check_password(password) else None else: return user
def get_email_localpart(email): """ Generates a string based on the email. email must be a valid email address. Uses characters before the '@', generates string from the email so as not to show the email instead it shows the string before the '@'. """ if email_re.search(email): email = email[:email.find('@')] else: email = email return email
def authenticate(self, email=None, password=None): #If username is an email address, then try to pull it up if email_re.search(email): try: user = User.objects.get(email=email) except User.DoesNotExist: return None else: return None if user.check_password(password): return user
def authenticate(self, username=None, password=None): if email_re.search(username): kwargs = {'email': username} else: kwargs = {'username': username} try: user = User.objects.get(**kwargs) if user.check_password(password): return user except User.DoesNotExist: return None
def authenticate(self, email=None, password=None): # If username is an email address, then try to pull it up if email_re.search(email): try: user = User.objects.get(email=email) except User.DoesNotExist: return None else: return None if user.check_password(password): return user
def authenticate(self, identification, password=None, check_password=True): if email_re.search(identification): try: user = User.objects.get(email__iexact=identification) except User.DoesNotExist: return None else: try: user = User.objects.get(username__iexact=identification) except User.DoesNotExist: return None if check_password: if user.check_password(password): return user return None else: return user
def _get_contact(username): if email_re.search(username): try: contact = crm.Contact.objects.get(user__email=username) except crm.Contact.DoesNotExist: contact = None else: try: contact = crm.Contact.objects.get(user__username=username) except crm.Contact.DoesNotExist: contact = None return contact
def authenticate(self, username=None, password=None): user_model = get_user_model() if email_re.search(username): try: user = user_model.objects.get(email=username) except user_model.DoesNotExist: return None if user.check_password(password): return user return None
def authenticate(self, username=None, password=None): #If username is an email address, then try to pull it up from django.core.validators import email_re if email_re.search(username): try: user = User.objects.get(email__iexact=username) except User.DoesNotExist: return None else: #We have a non-email address username we should try username try: user = User.objects.get(username__iexact=username) except User.DoesNotExist: return None return user
def authenticate(self, username=None, password=None): # If username is an email address, then try it if email_re.search(username): try: user = User.objects.get(email=username) except User.DoesNotExist: return None # We have a non-email address username we should try username else: try: user = User.objects.get(username=username) except User.DoesNotExist: return None if user.check_password(password): return user
def do_edit_email(request): if request.method != 'POST': return False e = request.POST.get('e', '').strip() if len(e) <= 0 or e == request.user.email: return False if not email_re.search(e): return False new_change_email_task(request.user, e) # # return True
def send_mails(): messages = Message.objects.order_by('when_added') if messages.count() <= 0: return True connection = get_connection(backend=EMAIL_BACKEND) for message in messages: if not email_re.search(str(message.email)): message.delete() continue try: email = message.email email.connection = connection email.send() message.delete() except (socket_error, smtplib.SMTPSenderRefused, smtplib.SMTPRecipientsRefused, smtplib.SMTPAuthenticationError), err: message.defer() MessageLog.objects.log(message, 3, log_message=str(err))
def authenticate(self, username=None, password=None): server = xmlrpclib.ServerProxy(settings.BUGZILLA3_RPC_SERVER) if email_re.search(username): try: auth = server.bugzilla.login(username, password) except xmlrpclib.Fault, fault: return None try: user = User.objects.get(email=username) user.set_password(password) user.save() except User.DoesNotExist: user = User.objects.create_user( username=username.split('@')[0], email=username) user.set_unusable_password(password)
def authenticate(self, username=None, password=None, **kwargs): UserModel = get_user_model() if username is None: username = kwargs.get(UserModel.USERNAME_FIELD) # If username is an email address, then try to pull it up if email_re.search(username): try: user = UserModel.objects.get(email=username) except UserModel.DoesNotExist: return None else: # We have a non-email address username we should try username try: user = UserModel.objects.get(username=username) except UserModel.DoesNotExist: return None if user.check_password(password): return user
def authenticate(self, username=None, password=None, is_facebook_connect=False): #If username is an email address, then try to pull it up if email_re.search(username): try: user = User.objects.get(email=username) except User.DoesNotExist: return None else: #We have a non-email address username we should try username try: user = User.objects.get(username=username) except User.DoesNotExist: return None if is_facebook_connect or \ (user.check_password(password) and not user.get_profile().facebook_connect_only): # Either the user is loging in via facebook, or they are loging in with a password # if the later make sure the user has not been created to allow only facebook logins return user
def post(self, request, *args, **kwargs): if email_re.search(self.querydict['Email']): clause = Q(email__iexact=self.querydict['Email']) else: clause = Q(username__iexact=self.querydict['Email']) try: user = User.objects.get(clause) except User.DoesNotExist: raise PermissionDenied() if not user.check_password(self.querydict['Passwd']): raise PermissionDenied() client = request.GET.get('client', request.DATA.get('client', '')) token = generate_auth_token( user, client=client, user_agent=request.META.get('HTTP_USER_AGENT', ''), ) return Response("SID={t}\nLSID={t}\nAuth={t}".format(t=token))
def parse_vcard(myfile, newsletter, ignore_errors=False): import vobject myvcards = vobject.readComponents(myfile) addresses = {} for myvcard in myvcards: if hasattr(myvcard, 'fn'): name = check_name(myvcard.fn.value, ignore_errors) else: name = None # Do we have an email address? # If not: either continue to the next vcard or # raise a validation error. if hasattr(myvcard, 'email'): email = check_email(myvcard.email.value, ignore_errors) elif not ignore_errors: raise forms.ValidationError( _("Entry '%s' contains no email address.") % name) else: continue if email_re.search(email): addr = make_subscription(newsletter, email, name) elif not ignore_errors: raise forms.ValidationError( _("Entry '%s' does not contain a valid e-mail address.") % name) if addr: if email in addresses and not ignore_errors: raise forms.ValidationError( _("The address file contains duplicate entries for '%s'.") % email) addresses.update({email: addr}) elif not ignore_errors: raise forms.ValidationError( _("Some entries are already subscribed to.")) return addresses
def clean_username(self): username = self.cleaned_data["username"] self.username = username if email_re.search(username): try: if User.objects.filter(email=username).count() > 1: raise forms.ValidationError( "You somehow have a duplicate registered user with us. Please contact us to fix it." ) except User.DoesNotExist: try: user = User.objects.get(username=username).username except User.DoesNotExist: raise forms.ValidationError( "Username or Password Incorrect") else: #We have a non-email address username we should try username try: user = User.objects.get(username=username).username except User.DoesNotExist: raise forms.ValidationError("Username or Password Incorrect")