def register_complete(request): form = RegisterForm(request.POST or None) context = { "form": form, "error": None, } if request.method == 'POST': if form.is_valid(): username = form.cleaned_data['username'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] try: validate_password(password) user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name, email=email, password=password) user.save() return render(request, 'registration/registration_complete.html') except ValidationError: print( password_validators_help_texts( get_default_password_validators())) context['error'] = password_validators_help_texts( get_default_password_validators()) return render(request, "registration/registration_form.html", context)
def test_password_validators_help_texts(self): help_texts = password_validators_help_texts() self.assertEqual(len(help_texts), 2) self.assertIn('12 characters', help_texts[1]) self.assertEqual( password_validators_help_texts(password_validators=[]), [])
def post(self, request): form = self.form_class(request.POST) loginform = LoginForm(None) if form.is_valid(): user = form.save(commit=False) user.username = form.cleaned_data["username"] user.email = form.cleaned_data["email"] password = form.cleaned_data["password1"] try: validate_password(password) except (ValidationError): return render( request, self.template_name, { "form": form, "errorhelp": password_validators_help_texts(), "loginform": loginform, }) user.set_password(password) user.save() user = authenticate(username=form.cleaned_data["username"], password=password) if user is not None: if user.is_active: login(request, user) return redirect("gruppeapp:makegroup") return render( request, self.template_name, { "form": form, "errorhelp": password_validators_help_texts(), "loginform": loginform, })
def change_password(request): """page to change password""" help_texts = password_validators_help_texts(password_validators=None) if request.method == 'POST': form = ChangePasswordForm(request.POST, request=request) if form.is_valid(): current_password = form.cleaned_data['current_password'] if request.user.check_password(current_password): new_password = form.cleaned_data.get('new_password') user = request.user user.set_password(new_password) user.save() messages.success(request, "Password updated!") return redirect('accounts:profile') else: messages.error( request, "The password did not match \ your current password!") return redirect('accounts:change_password') else: form = ChangePasswordForm() help_texts = help_texts[:-1] help_texts.append("Your first name, last name, or username" " cannot be in your new password.") return render(request, 'accounts/change_password.html', { 'form': form, 'help_texts': help_texts })
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['username'].label_suffix = '' self.fields['username'].label = '' self.fields['username'].help_text = _( 'Username is the only identifier of your account.') self.fields['password1'].label_suffix = '' self.fields['password1'].label = '' self.fields[ 'password1'].help_text = password_validation.password_validators_help_texts( ) self.fields['password2'].label_suffix = '' self.fields['password2'].label = '' self.fields['email'].label_suffix = '' self.fields['email'].label = '' self.fields['email'].help_text = _( 'Email address is important to active and your account ' 'and help to recover password.') self.fields['password1'].widget.attrs.update({ 'class': 'form-control login-field', 'placeholder': '密码', }) self.fields['password2'].widget.attrs.update({ 'class': 'form-control login-field', 'placeholder': '确认密码', })
class RegistrationForm(UserCreationForm): """Registration form.""" password1 = forms.CharField( label=_("Password"), strip=False, widget=forms.PasswordInput, help_text='<br></br>'.join(password_validators_help_texts()), ) # add placeholder and hover text def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for field in self.fields.values(): field.widget.attrs.update({ "placeholder": field.label, "data-container": "body", "data-toggle": "popover", "data-trigger": "hover", "data-placement": "right", "data-content": field.help_text, "id": field.label }) class Meta: model = User fields = ['username', 'first_name', 'last_name', 'email']
def clean_new_pw(self): password1 = self.cleaned_data.get('new_pw', '') if password1 and validate_password(password1, user=self.user) is not None: raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid') return password1
class SetPasswordForm(forms.Form): """ A form that lets a user change set their password without entering the old password """ new_password1 = forms.CharField( label="New password", widget=forms.PasswordInput, strip=False, ) new_password2 = forms.CharField( label="New password confirmation", strip=False, widget=forms.PasswordInput, help_text=' '.join( password_validation.password_validators_help_texts()), ) def clean_new_password2(self): password1 = self.cleaned_data.get('new_password1') password2 = self.cleaned_data.get('new_password2') if password1 and password2: if password1 != password2: raise forms.ValidationError("The passwords do not match.") password_validation.validate_password(password2) return password2 def save(self, user): password = self.cleaned_data["new_password1"] user.set_password(password) user.save()
def password_change(request): """ Handles the "change password" task -- both form display and validation. """ redirect_uri = get_safe_redirect_uri(request, allowed_hosts()) post_change_redirect = update_url(reverse('accounts:password_change_done'), {'redirect_uri': redirect_uri}) template_name = 'accounts/password_change_form.html' if request.method == "POST": form = PasswordChangeForm(user=request.user, data=request.POST) if form.is_valid(): form.save() # Updating the password logs out all other sessions for the user # except the current one update_session_auth_hash(request, form.user) return HttpResponseRedirect(post_change_redirect) else: form = PasswordChangeForm(user=request.user) context = { 'password_validators_help_texts': password_validators_help_texts(), 'form': form, 'title': _('Password change'), 'redirect_uri': redirect_uri } return TemplateResponse(request, template_name, context)
def get(self, request): link = request.GET.get('link', None) AES = AESCipher(settings.SECRET_KEY) userinfo = JSONDeserializer().deserialize(AES.decrypt(link)) form = ArchesUserCreationForm(userinfo) if datetime.fromtimestamp(userinfo['ts']) + timedelta(days=1) >= datetime.fromtimestamp(int(time.time())): if form.is_valid(): user = form.save() crowdsource_editor_group = Group.objects.get(name=settings.USER_SIGNUP_GROUP) user.groups.add(crowdsource_editor_group) return redirect('auth') else: try: for error in form.errors.as_data()['username']: if error.code == 'unique': return redirect('auth') except: pass else: form.errors['ts'] = [_('The signup link has expired, please try signing up again. Thanks!')] return render(request, 'signup.htm', { 'form': form, 'showform': True, 'postdata': userinfo, 'validation_help': validation.password_validators_help_texts() })
def get(self, request): if self.request.user.is_authenticated and self.request.user.username != "anonymous": context = self.get_context_data( main_script="views/user-profile-manager", ) user_details = self.get_user_details(request.user) context["nav"]["icon"] = "fa fa-user" context["nav"]["title"] = _("Profile Manager") context["nav"]["login"] = True context["nav"]["help"] = { "title": _("Profile Editing"), "template": "profile-manager-help", } context[ "validation_help"] = validation.password_validators_help_texts( ) context["user_surveys"] = JSONSerializer().serialize( user_details["user_surveys"], sort_keys=False) context["identities"] = JSONSerializer().serialize( user_details["identities"], sort_keys=False) context["resources"] = JSONSerializer().serialize( user_details["resources"], sort_keys=False) return render(request, "views/user-profile-manager.htm", context)
class RegisterForm(LoginForm): password2 = forms.CharField(widget=forms.PasswordInput, label='Repeat password', max_length=100, help_text=' '.join( password_validators_help_texts())) name = forms.CharField(label='Full name', max_length=225, help_text='What is your preferred full name?') field_order = ['name', 'email', 'password', 'password2'] def __init__(self, *args, **kwargs): self._type = kwargs.pop('type', None) super(LoginForm, self).__init__(*args, **kwargs) def clean_password2(self): # Check that the two password entries match password = self.cleaned_data.get("password") password2 = self.cleaned_data.get("password2") if password and password2 and password != password2: raise forms.ValidationError("Passwords don't match") validate_password(password) return password2 def clean(self): # Check if the parameter of the url is one of our user types if self._type not in models.USR_URL_TYPE: raise forms.ValidationError( "Unexpected type. Are you trying to hack us?") return self.cleaned_data
class RegisterForm(LoginForm): password2 = forms.CharField(widget=forms.PasswordInput, label='Repeat password', max_length=100, help_text=' '.join( password_validators_help_texts())) name = forms.CharField(label='Full name', max_length=25, help_text='What is your preferred full name?') terms_and_conditions = forms.BooleanField( label= 'I\'ve read, understand and accept <a href="https://www.ugahacks.com/privacy" target="_blank">UGAHacks ' 'Privacy Policy</a>.<span style="color: red; font-weight: bold;"> *</span>' ) birthday = forms.DateField(widget=forms.DateInput( format=('%m/%d/%Y'), attrs={ 'class': 'form-control', 'type': 'date' })) field_order = [ 'name', 'email', 'password', 'password2', 'birthday', 'terms_and_conditions' ] def clean_password2(self): # Check that the two password entries match password = self.cleaned_data.get("password") password2 = self.cleaned_data.get("password2") if password and password2 and password != password2: raise forms.ValidationError("Passwords don't match") validate_password(password) return password2 def clean_terms_and_conditions(self): cc = self.cleaned_data.get('terms_and_conditions', False) # Check that if it's the first submission hackers checks terms and conditions checkbox # self.instance.pk is None if there's no Application existing before # https://stackoverflow.com/questions/9704067/test-if-django-modelform-has-instance if not cc and not self.instance.pk: raise forms.ValidationError( "In order to apply and attend you have to accept our Terms & Conditions and" " our Privacy Policy.") return cc def clean_birthday(self): birthday = self.cleaned_data.get('birthday') currdate = datetime.datetime.now() if datetime.datetime(birthday.year + 18, birthday.month, birthday.day) > currdate: raise forms.ValidationError( "In order to apply and attend you must be at least 18 years old." ) return birthday def clean_email(self): email = self.cleaned_data.get("email") return email.lower()
def get(self, request): link = request.GET.get('link', None) AES = AESCipher(settings.SECRET_KEY) userinfo = JSONDeserializer().deserialize(AES.decrypt(link)) form = ArchesUserCreationForm(userinfo) if datetime.fromtimestamp(userinfo['ts']) + timedelta( days=1) >= datetime.fromtimestamp(int(time.time())): if form.is_valid(): user = form.save() crowdsource_editor_group = Group.objects.get( name=settings.USER_SIGNUP_GROUP) user.groups.add(crowdsource_editor_group) return redirect('auth') else: try: for error in form.errors.as_data()['username']: if error.code == 'unique': return redirect('auth') except: pass else: form.errors['ts'] = [ _('The signup link has expired, please try signing up again. Thanks!' ) ] return render( request, 'signup.htm', { 'form': form, 'showform': True, 'postdata': userinfo, 'validation_help': validation.password_validators_help_texts() })
def clean_password(self): password1 = self.cleaned_data.get('password', '') user = User(email=self.cleaned_data.get('email')) if validate_password(password1, user=user) is not None: raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid') return password1
class RegistrationForm(UserCreationForm): username = forms.CharField( required=True, widget=forms.TextInput(attrs={'placeholder': "usuario"})) email = forms.EmailField( required=True, widget=forms.EmailInput(attrs={'placeholder': "email"})) password1 = forms.CharField( required=True, widget=forms.PasswordInput(attrs={'placeholder': "contraseña"}), help_text=password_validators_help_texts()) password2 = forms.CharField( required=True, widget=forms.PasswordInput( attrs={'placeholder': "confirmación contraseña"})) class Meta: model = User fields = ('username', 'email', 'password1', 'password2') def clean_email(self): email = self.cleaned_data.get('email') if not email: raise ValidationError('El email es necesario') elif User.objects.filter(email=email).exists(): raise ValidationError('El email ya existe') return email def clean_username(self): username = self.cleaned_data.get('username') if not username: raise ValidationError('El usuario es necesario') return username
def change_password(request): if request.user.is_authenticated and request.method == 'POST': n_user = User.objects.get(id=request.user.id) if n_user.check_password(request.POST['old_password']): try: if validate_password(request.POST['new_password']) is None: n_user.set_password(request.POST['new_password']) n_user.save() auth_user = authenticate( username=request.user.username, password=request.POST['new_password']) if auth_user and request.user.is_active: auth_login(request, auth_user) return JsonResponse([{ 'message': 'Successfully changed your password!' }], safe=False) except ValidationError: return JsonResponse([{ 'message': (str(password_validators_help_texts()).replace( ",", "\n").rstrip("]")).strip("[") }], safe=False) else: return JsonResponse([{ 'message': 'Your old password is wrong!' }], safe=False)
def clean_new_password(self): new_password = self.cleaned_data.get('new_password') if new_password and validate_password(new_password, user=self.instance) is not None: raise forms.ValidationError( gettext_lazy(password_validators_help_texts())) return new_password
def get(self, request): if self.request.user.is_authenticated( ) and self.request.user.username != 'anonymous': context = self.get_context_data( main_script='views/user-profile-manager', ) user_details = self.get_user_details(request.user) context['nav']['icon'] = "fa fa-user" context['nav']['title'] = _("Profile Manager") context['nav']['login'] = True context['nav']['help'] = { 'title': _('Profile Editing'), 'template': 'profile-manager-help', } context[ 'validation_help'] = validation.password_validators_help_texts( ) context['user_surveys'] = JSONSerializer().serialize( user_details['user_surveys'], sort_keys=False) context['identities'] = JSONSerializer().serialize( user_details['identities'], sort_keys=False) context['resources'] = JSONSerializer().serialize( user_details['resources'], sort_keys=False) return render(request, 'views/user-profile-manager.htm', context)
class PasswordChangeForm(PasswordChangeForm): new_password1 = forms.CharField( label=("New password"), widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), strip=False, help_text=password_validation.password_validators_help_texts(), )
class RegistrationOwner(View): context = { "is_owner": True, 'help_text': password_validators_help_texts(), } def get(self, request): return render(request, "accounts/register.html", self.context) def post(self, request): username = request.POST['username'] password = request.POST['password'] repeat_password = request.POST['repeatPassword'] first_name = request.POST['firstName'] last_name = request.POST['lastName'] email = request.POST['email'] company_name = request.POST['company_name'] company_address = request.POST['address'] if password and repeat_password and password == repeat_password: user = User(username=username, first_name=first_name, last_name=last_name, email=email, password=password) user.save() owner = Owner(profile=user) owner.save() company = Companies(owner=owner, company_name=company_name, address=company_address) company.save() messages.success(request, 'Your Account has been Created! You are now able to log in') return redirect("accounts:login") messages.error(request, 'Password Do Not Match') return render(request, "accounts/register.html", self.context)
def user_decorator(*args, **kwargs): username = args[0].request.data.get('username') password = args[0].request.data.get('password') email = args[0].request.data.get('email') user_privacy = args[0].request.data.get('user_privacy') if None in (username, password, email, user_privacy): return Response(data={ 'Error': 'Username, password, email and privacy settings are required' }, status=status.HTTP_400_BAD_REQUEST) try: validate_email(email) except: return Response(data={'Error': 'Please enter a valid email'}, status=status.HTTP_400_BAD_REQUEST) try: validate_password(password, user=User(username=username, email=email)) except: return Response(data={'Error': password_validators_help_texts()}, status=status.HTTP_400_BAD_REQUEST) if User.objects.filter(username=username): return Response(data={ 'Error': 'The username already exists, please use a different username' }, status=status.HTTP_400_BAD_REQUEST) return fn(*args, **kwargs)
def password_validators_help_text_html(password_validators=None): """ Return an HTML string with all help texts of all configured validators in an . """ help_texts = password_validation.password_validators_help_texts(password_validators) help_items = format_html_join('', '<p class="text-muted">{}</p>', ((help_text,) for help_text in help_texts)) return format_html('<div>{}</div>', help_items) if help_items else ''
def clean_new_pw(self): password1 = self.cleaned_data.get('new_pw', '') if password1 and validate_password(password1, user=self.user) is not None: raise forms.ValidationError( _(password_validators_help_texts()), code='pw_invalid' ) return password1
def clean_password(self): password1 = self.cleaned_data.get('password', '') try: user = User.objects.get(id=self.user_id) except User.DoesNotExist: user = None if validate_password(password1, user=user) is not None: raise forms.ValidationError(_(password_validators_help_texts()), code='pw_invalid') return password1
def post(self, request): showform = True confirmation_message = '' postdata = request.POST.copy() postdata['ts'] = int(time.time()) form = ArchesUserCreationForm(postdata, enable_captcha=settings.ENABLE_CAPTCHA) if form.is_valid(): AES = AESCipher(settings.SECRET_KEY) userinfo = JSONSerializer().serialize(form.cleaned_data) encrypted_userinfo = AES.encrypt(userinfo) url_encrypted_userinfo = urlencode({'link': encrypted_userinfo}) admin_email = settings.ADMINS[0][1] if settings.ADMINS else '' email_context = { 'button_text': _('Signup for Arches'), 'link': request.build_absolute_uri( reverse('confirm_signup') + '?' + url_encrypted_userinfo, ), 'greeting': _('Thanks for your interest in Arches. Click on link below to confirm your email address! Use your email address to login.' ), 'closing': _('This link expires in 24 hours. If you can\'t get to it before then, don\'t worry, you can always try again with the same email address.' ), } html_content = render_to_string('email/general_notification.htm', email_context) # ... text_content = strip_tags( html_content ) # this strips the html, so people will have the text as well. # create the email, and attach the HTML version as well. msg = EmailMultiAlternatives(_('Welcome to Arches!'), text_content, admin_email, [form.cleaned_data['email']]) msg.attach_alternative(html_content, "text/html") msg.send() confirmation_message = _( 'An email has been sent to <br><strong>%s</strong><br> with a link to activate your account' % form.cleaned_data['email']) showform = False return render( request, 'signup.htm', { 'enable_captcha': settings.ENABLE_CAPTCHA, 'form': form, 'postdata': postdata, 'showform': showform, 'confirmation_message': confirmation_message, 'validation_help': validation.password_validators_help_texts() })
def _password_validators_help_text_html(password_validators=None): help_texts = password_validation.password_validators_help_texts(password_validators) if not help_texts: return '' return format_html('<ul>{}</ul>', format_html_join('', '<li>{}</li>', ((text,) for text in help_texts)) )
class CustomUserCreationForm(UserCreationForm): first_name = forms.CharField(label="First name", widget=forms.TextInput( attrs={ "class": "name auth-form-field", "autocomplete": "off", "aria-label": "First name", })) last_name = forms.CharField(label="Last name", widget=forms.TextInput( attrs={ "class": "name auth-form-field", "autocomplete": "off", "aria-label": "Last name" })) username = UsernameField( widget=forms.TextInput( attrs={ "class": "username auth-form-field", "autocomplete": "off", "aria-label": "Username", "aria-describedby": "usernameHelpBlock", "autofocus": True }), help_text="You can use letters, numbers and @/./+/-/_ characters") password1 = forms.CharField( label="Password", strip=False, widget=forms.PasswordInput( attrs={ "class": "password auth-form-field", "ng-model": "password1", "autocomplete": "off", "aria-label": "Password", "aria-describedby": "passwordHelpBlock" }), help_text=password_validation.password_validators_help_texts()) password2 = forms.CharField( label="Confirm password", strip=False, widget=forms.PasswordInput( attrs={ "class": "password auth-form-field", "ng-model": "password2", "autocomplete": "off", "aria-label": "Confirm password" }), help_text="Enter the same password as before, for verification.") class Meta: model = User fields = ("username", ) field_classes = {'username': UsernameField}
class UserChangeForm(forms.ModelForm): """A form for updating users. Includes all the fields on the user, but replaces the password field with admin's password hash display field. """ password = ReadOnlyPasswordHashField( label=("Password"), help_text=( "Passwords are not stored in plaintext, so there is no way to see " "this user's password")) password1 = forms.CharField(required=False, widget=forms.PasswordInput, label='Password', max_length=100) password2 = forms.CharField(required=False, widget=forms.PasswordInput, label='Repeat password', max_length=100, help_text=' '.join( password_validators_help_texts())) class Meta: model = User exclude = [] def __init__(self, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) if self.initial: self.fields.pop('password1') self.fields.pop('password2') def clean_password(self): # Regardless of what the user provides, return the initial value. # This is done here, rather than on the field, because the # field does not have access to the initial value if self.initial: return self.initial["password"] def clean_password2(self): # Check that the two password entries match password1 = self.cleaned_data.get("password1", None) password2 = self.cleaned_data.get("password2", None) if not self.initial and password1 and password2 and password1 != password2: raise forms.ValidationError("Passwords don't match") validate_password(password1) return password2 def save(self, commit=True): # Save the provided password in hashed format user = super(UserChangeForm, self).save(commit=False) if not self.initial: user.set_password(self.cleaned_data["password2"]) if commit: user.save() return user
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Don't append colons to form labels ("Benutzername", nicht "Benutzername:"). self.label_suffix = "" # Set proper help texts (https://code.djangoproject.com/ticket/31158). self.fields['new_password1'].help_text = mark_safe("<br>".join(password_validation.password_validators_help_texts())) self.fields['new_password2'].help_text = "As you cannot see the password as you type, this helps catching typos."
def post(self, request): context = {'request': request} request.data._mutable = True user = UserSerializer(data=request.data, context=context) employee = EmployeeSerializer(data=request.data, context=context) employee_config = EmployeeConfigSerializer(data=request.data, context=context) employee_profile = EmployeeProfileSerializer(data=request.data, context=context) try: validate_password(request.data['password'], user=None, password_validators=None) except: pass_error = password_validators_help_texts() return Response(pass_error, status=status.HTTP_400_BAD_REQUEST) email_exists = User.objects.filter( email=request.data['email']).exists() if email_exists: email_error = ['a user already uses that gmail account'] return Response(email_error, status=status.HTTP_400_BAD_REQUEST) if user.is_valid(): x = user.save() x.set_password(x.password) x.save() user_object = User.objects.get(username=request.data['username']) user_id = user_object.pk request.data['user'] = user_object.pk if employee.is_valid(): employee.save() employee_object = Employee.objects.get( user=request.data['user']) request.data['user'] = employee_object.pk if employee_config.is_valid() and employee_profile.is_valid(): employee_config.save() employee_profile.save() return Response([True, user_id], status=status.HTTP_201_CREATED) user_error = [] try: username_error = user.errors['username'][0] user_error.append(username_error) except: pass try: email_error = user.errors['email'][0] user_error.append(email_error) except: pass return Response(user_error, status=status.HTTP_400_BAD_REQUEST)
class PasswordChangeSerializer(serializers.Serializer): old_password = serializers.CharField(label=_("Old password"), write_only=True) new_password1 = serializers.CharField( label=_("New password"), help_text=password_validators_help_texts(), write_only=True, ) new_password2 = serializers.CharField(label=_("New password confirmation"), write_only=True)
def register(request): if request.method == 'POST': form = UserCreationForm(request.POST) #see if username is already taken if form.is_valid(): form.save() return render(request,'squadshare/basic.html',{'content':["Registration Successful"]}) else: return render(request, 'squadshare/basic.html', {'content':["Failed Registration"]}) else: form = UserCreationForm() c={} c.update(csrf(request)) c['form'] = form help_text = password_validation.password_validators_help_texts() c['help_text']=help_text return render(request, 'squadshare/register.html',c)
def get(self, request): form = ArchesUserCreationForm(enable_captcha=settings.ENABLE_CAPTCHA) postdata = { 'first_name': '', 'last_name': '', 'email': '' } showform = True confirmation_message = '' return render(request, 'signup.htm', { 'enable_captcha': settings.ENABLE_CAPTCHA, 'form': form, 'postdata': postdata, 'showform': showform, 'confirmation_message': confirmation_message, 'validation_help': validation.password_validators_help_texts() })
def post(self, request): showform = True confirmation_message = '' postdata = request.POST.copy() postdata['ts'] = int(time.time()) form = ArchesUserCreationForm(postdata, enable_captcha=settings.ENABLE_CAPTCHA) if form.is_valid(): AES = AESCipher(settings.SECRET_KEY) userinfo = JSONSerializer().serialize(form.cleaned_data) encrypted_userinfo = AES.encrypt(userinfo) url_encrypted_userinfo = urlencode({'link':encrypted_userinfo}) admin_email = settings.ADMINS[0][1] if settings.ADMINS else '' email_context = { 'button_text': _('Signup for Arches'), 'link':request.build_absolute_uri(reverse('confirm_signup') + '?' + url_encrypted_userinfo,), 'greeting': _('Thanks for your interest in Arches. Click on link below to confirm your email address! Use your email address to login.'), 'closing': _('This link expires in 24 hours. If you can\'t get to it before then, don\'t worry, you can always try again with the same email address.'), } html_content = render_to_string('email/general_notification.htm', email_context) # ... text_content = strip_tags(html_content) # this strips the html, so people will have the text as well. # create the email, and attach the HTML version as well. msg = EmailMultiAlternatives(_('Welcome to Arches!'), text_content, admin_email, [form.cleaned_data['email']]) msg.attach_alternative(html_content, "text/html") msg.send() confirmation_message = _('An email has been sent to <br><strong>%s</strong><br> with a link to activate your account' % form.cleaned_data['email']) showform = False return render(request, 'signup.htm', { 'enable_captcha': settings.ENABLE_CAPTCHA, 'form': form, 'postdata': postdata, 'showform': showform, 'confirmation_message': confirmation_message, 'validation_help': validation.password_validators_help_texts() })
def test_password_validators_help_texts(self): help_texts = password_validators_help_texts() self.assertEqual(len(help_texts), 2) self.assertIn('12 characters', help_texts[1]) self.assertEqual(password_validators_help_texts(password_validators=[]), [])