class UserForm(ModelForm): usuario = forms.CharField(max_length=50) nombre = forms.CharField(max_length=20) apellido = forms.CharField(max_length=20) email = forms.EmailField() contrasena = forms.CharField(widget=forms.PasswordInput()) contrasena2 = forms.CharField(widget=forms.PasswordInput()) class Meta: model = CustomUser fields = ['pais', 'ciudad', 'imagen'] def clean_username(self): username = self.cleaned_data['usuario'] if User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario ya registrado.') return username def clean_email(self): email = self.cleaned_data['email'] if User.objects.filter(email=email): raise forms.ValidationError('Ya existe un email igual registrado.') return email def clean_password2(self): password = self.cleaned_data['contrasena'] password2 = self.cleaned_data['contrasena'] if password != password2: raise forms.ValidationError('Las claves no coinciden') return password2 def __unicode__(self): return self.name
class CustomInfo(UserCreationForm): email = forms.EmailField( max_length=50, help_text='Required. Inform a valid email address.', widget=forms.EmailInput(attrs={ 'placeholder': 'Email', "class": "inpt", }), ) password1 = forms.CharField( label=_('Password'), widget=(forms.PasswordInput(attrs={ 'placeholder': 'Password', })), help_text=password_validation.password_validators_help_text_html()) password2 = forms.CharField( label=_('Password Confirmation'), widget=forms.PasswordInput( attrs={'placeholder': 'Password Confirmation'}), help_text=_('Just Enter the same password, for confirmation')) username = forms.CharField( label=_('Username'), max_length=150, help_text= _('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.' ), validators=[username_validator], error_messages={ 'unique': _("A user with that username already exists.") }, widget=forms.TextInput(attrs={'placeholder': 'Username'})) class Meta: model = User fields = ["username", "email", "password1", "password2"]
class RegistrationForm(forms.Form): username = forms.CharField(label='Username', max_length=20, min_length=1) password1 = forms.CharField(label='Password', widget=forms.PasswordInput(), max_length=15, min_length=3) password2 = forms.CharField(label='Password (Again)', widget=forms.PasswordInput(), max_length=15, min_length=3) mobileNo = forms.CharField(label='Mobile No.', max_length=15, min_length=5) email = forms.EmailField(label='Email') def clean_password2(self): if 'password1' in self.cleaned_data: password1 = self.cleaned_data['password1'] password2 = self.cleaned_data['password2'] if password1 == password2: return password2 raise forms.ValidationError('Passwords do not match.') def clean_username(self): username = self.cleaned_data['username'] if not re.search(r'^\w+$', username): raise forms.ValidationError( 'Username can only containalphanumericcharacters and the underscore.' ) try: Register.objects.get(name=username) except ObjectDoesNotExist: return username raise forms.ValidationError('Username is already taken.')
class RequireEmailForm(forms.Form): """邮件表单验证forms""" email = forms.EmailField(label='电子邮箱', required=True) oauthid = forms.IntegerField(widget=forms.HiddenInput, required=False) def __init__(self, *args, **kwargs): super(RequireEmailForm, self).__init__(*args, **kwargs) self.fields['email'].widget = widgets.EmailInput(attrs={'placeholder': 'email', 'class': 'form-control'})
class CsvRowValidationForm(forms.Form): employee_id = forms.IntegerField(required=True) last_name = forms.CharField(required=True) first_name = forms.CharField(required=True) email = forms.EmailField(required=True) password = forms.CharField(required=True) manager_username = forms.CharField(required=False) ranking1 = forms.CharField(required=False) ranking2 = forms.CharField(required=False)
class Contact(forms.Form): title = forms.CharField(required=True) email = forms.EmailField(required=True) text = forms.CharField(validators=[ validators.MinLengthValidator(10), validators.MaxLengthValidator(250) ], required=True, widget=forms.Textarea)
class UserPasswordResetForm(PasswordResetForm): def __init__(self, *args, **kwargs): super(UserPasswordResetForm, self).__init__(*args, **kwargs) email = forms.EmailField(label='', widget=forms.EmailInput(attrs={ 'class': 'form-control', 'placeholder': 'Enter your email', 'type': 'email', 'name': 'email' }))
class SignUpForm(UserCreationForm): first_name = forms.CharField( max_length=12, min_length=4, required=True, help_text='Required: First Name', widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'First Name' })) last_name = forms.CharField( max_length=12, min_length=4, required=True, help_text='Required: Last Name', widget=(forms.TextInput(attrs={'class': 'form-control'}))) email = forms.EmailField( max_length=50, help_text='Required. Inform a valid email address.', widget=forms.EmailInput(attrs={'placeholder': 'Email'}), ) password1 = forms.CharField( label=_('Password'), widget=(forms.PasswordInput(attrs={ 'placeholder': 'Password', })), help_text=password_validation.password_validators_help_text_html()) password2 = forms.CharField( label=_('Password Confirmation'), widget=forms.PasswordInput( attrs={'placeholder': 'Password Confirmation'}), help_text=_('Just Enter the same password, for confirmation')) username = forms.CharField( label=_('Username'), max_length=150, help_text= _('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.' ), validators=[username_validator], error_messages={ 'unique': _("A user with that username already exists.") }, widget=forms.TextInput(attrs={'placeholder': 'Username'})) class Meta: model = User fields = ( 'username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
class LoginForm(forms.Form): email = forms.EmailField() username = forms.CharField(max_length=100, required=False) password = forms.CharField(widget=forms.PasswordInput) def clean(self): data = self.cleaned_data username, password, email = (data["username"], data["password"], data["email"]) self.user = authenticate(username=username, password=password) if self.user is None: raise forms.ValidationError("Enter a valid email or password")
class EditUserForm(ModelForm): username = forms.CharField(max_length=50, disabled=True) first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) email = forms.EmailField() class Meta: model = User fields = ['username', 'first_name', 'last_name', 'email'] def clean_username(self): username = self.cleaned_data['username'] if not User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario no existe.') return username
class UserForm(UserCreationForm): email = forms.EmailField() class Meta: model = User fields = ('username', 'email', 'password1', 'password2')
class UserUpdateForm(forms.ModelForm): email = forms.EmailField() class Meta: model = User fields = ['username', 'email']
class RegisterForm(UserCreationForm): email = forms.EmailField() class Meta: model = User fields = ["username", "email", "password1", "password2"]
class SignupForm(UserCreationForm): username = forms.CharField(max_length=254, widget=forms.TextInput({ 'class': 'form-control', 'placeholder': 'Username' })) first_name = forms.CharField(max_length=30, required=False, help_text='Optional.', widget=forms.TextInput({ 'class': 'form-control', 'placeholder': 'First Name' })) last_name = forms.CharField(max_length=30, required=False, help_text='Optional.', widget=forms.TextInput({ 'class': 'form-control', 'placeholder': 'Last Name' })) email = forms.EmailField(max_length=254, required=True, widget=forms.TextInput({ 'class': 'form-control', 'placeholder': 'Email address' })) password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput({ 'class': 'form-control', 'placeholder': 'Create password' })) password2 = forms.CharField(label=_("Password"), widget=forms.PasswordInput({ 'class': 'form-control', 'placeholder': 'Repeat password' })) class Meta: model = User fields = ( 'username', 'first_name', 'last_name', 'email', 'password1', 'password2', ) def clean_email(self): # Get the email email = self.cleaned_data.get('email') # Check to see if any users already exist with this email as a username. try: match = User.objects.get(email=email) except User.DoesNotExist: # Unable to find a user, this is fine return email # A user was found with this as a username, raise an error. raise forms.ValidationError( 'This email address is already in use.')
class CsvRowValidationForm(forms.Form): employee_id = forms.IntegerField(required=True) last_name = forms.CharField(required=True) first_name = forms.CharField(required=True) email = forms.EmailField(required=True) password = forms.CharField(required=True)
class PasswordResetForm(forms.Form): email = forms.EmailField(label=_("Email"), max_length=254) def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name=None): """ Send a django.core.mail.EmailMultiAlternatives to `to_email`. """ subject = loader.render_to_string(subject_template_name, context) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) body = loader.render_to_string(email_template_name, context) email_message = EmailMultiAlternatives(subject, body, from_email, [to_email]) if html_email_template_name is not None: html_email = loader.render_to_string(html_email_template_name, context) email_message.attach_alternative(html_email, 'text/html') email_message.send() def get_users(self, email): """Given an email, return matching user(s) who should receive a reset. This allows subclasses to more easily customize the default policies that prevent inactive users and users with unusable passwords from resetting their password. """ active_users = UserModel._default_manager.filter( **{ '%s__iexact' % UserModel.get_email_field_name(): email, 'is_active': True, }) return (u for u in active_users if u.has_usable_password()) def save(self, domain_override=None, subject_template_name='registration/password_reset_subject.txt', email_template_name='registration/password_reset_email.html', use_https=False, token_generator=default_token_generator, from_email=None, request=None, html_email_template_name=None, extra_email_context=None): """ Generate a one-use only link for resetting password and send it to the user. """ email = self.cleaned_data["email"] for user in self.get_users(email): if not domain_override: current_site = get_current_site(request) site_name = current_site.name domain = current_site.domain else: site_name = domain = domain_override context = { 'email': email, 'domain': domain, 'site_name': site_name, 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(), 'user': user, 'token': token_generator.make_token(user), 'protocol': 'https' if use_https else 'http', **(extra_email_context or {}), } self.send_mail( subject_template_name, email_template_name, context, from_email, email, html_email_template_name=html_email_template_name, )
class RegistrationForm(UserCreationForm): email = forms.EmailField(label='Email') class Meta: model = User fields = ('email', 'username',)