class Registration(forms.Form): username = forms.CharField( max_length=150, error_messages={'required': 'Вы забыли указать имя пользователя'}) email = forms.EmailField( max_length=254, error_messages={'required': 'Вы забыли указать Email'}) password = forms.CharField( widget=PasswordInput(), error_messages={'required': 'Вы забыли ввести пароль'}) repassword = forms.CharField( widget=PasswordInput, error_messages={'required': 'Укажите пароль еще раз'}) # Валидация проходит в этом методе def clean(self): if self.cleaned_data.get('password') != self.cleaned_data.get( 'repassword'): raise forms.ValidationError('Пароли должны совпадать!', code='invalid') return self.cleaned_data def clean_username(self): curent_user = self.cleaned_data.get('username') if User.objects.filter(username=curent_user).exists(): raise forms.ValidationError('Пользователь с таким именем уже есть', code='invalid') return curent_user def clean_email(self): curent_email = self.cleaned_data.get('email') if User.objects.filter(email=curent_email).exists(): raise forms.ValidationError('Пользователь с таким email уже есть', code='invalid') return curent_email
class Meta: document = SQLRepository widgets = { 'repo_name': TextInput(attrs={'class': 'form-control'}), 'db_host': TextInput(attrs={'class': 'form-control'}), 'db_port': TextInput(attrs={'class': 'form-control'}), 'db_name': TextInput(attrs={'class': 'form-control'}), 'db_user': TextInput(attrs={'class': 'form-control'}), 'db_password': PasswordInput(render_value=True, attrs={'class': 'form-control'}), 'db_table': TextInput(attrs={'class': 'form-control'}), 'db_user_column': TextInput(attrs={'class': 'form-control'}), 'db_password_column': TextInput(attrs={'class': 'form-control'}), 'db_password_salt': TextInput(attrs={'class': 'form-control'}), 'db_change_pass_column': TextInput(attrs={'class': 'form-control'}), 'db_change_pass_value': TextInput(attrs={'class': 'form-control'}), 'db_locked_column': TextInput(attrs={'class': 'form-control'}), 'db_locked_value': TextInput(attrs={'class': 'form-control'}), 'db_user_phone_column': TextInput(attrs={'class': 'form-control'}), 'db_user_email_column': TextInput(attrs={'class': 'form-control'}), 'oauth2_attributes': TextInput(attrs={'class': 'form-control'}), 'enable_oauth2': CheckboxInput(attrs={'class': 'js-switch'}) }
class LoginForm(AuthenticationForm): username = CharField(widget=TextInput( attrs={ 'class': 'mdl-textfield__input', 'id': 'username', 'required': 'true' })) password = CharField(widget=PasswordInput( attrs={ 'class': 'mdl-textfield__input', 'id': 'password', 'required': 'true' })) def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') user = authenticate(username=username, password=password) if not user or not user.is_active: raise forms.ValidationError( "Sorry, username or password incorrect!") return self.cleaned_data
class ExportDestinationForm(ModelForm): password = CharField( widget=PasswordInput(render_value=True), help_text=help_text.EXPORT_DESTINATION_PASSWORD, ) class Meta: model = ExportDestination fields = ( "id", "title", "description", "ip", "port", "username", "password", "destination", "socket_timeout", "negotiation_timeout", "banner_timeout", "users", )
class UserLoginForm(AuthenticationForm, ModelForm): class Meta: model = User fields = ['username', 'password'] username = CharField(widget=TextInput( attrs={ 'name': 'username', 'value': 'Логин', 'class': 'input username', 'onfocus': 'this.value=""' })) password = CharField(widget=PasswordInput( attrs={ 'name': 'password', 'value': 'Пароль', 'class': 'input password', 'onfocus': 'this.value=""' })) def __init__(self, *args, **kwargs): super(UserLoginForm, self).__init__(*args, **kwargs)
class Meta: model = User fields = ['username', 'password'] widgets = { 'username': TextInput( attrs={ 'name': 'username', 'value': 'Логин', 'class': 'input username', 'onfocus': 'this.value=""' }), 'password': PasswordInput( attrs={ 'name': 'password', 'value': 'Пароль', 'class': 'input password', 'onfocus': 'this.value=""' }) }
class SubscriberSignupAddressForm(SubscriberAddressForm): """ Adds password (like SubscriberSignupForm) and address """ password = CharField(label=u'Contraseña', widget=PasswordInput()) helper = FormHelper() helper.form_tag = False helper.form_class = 'form-horizontal' helper.label_class = 'col-sm-2' helper.field_class = 'col-sm-8' helper.help_text_inline = True helper.error_text_inline = True helper.layout = Layout(Fieldset( u'', 'first_name', 'email', 'telephone', Field( 'password', template='materialize_css_forms/layout/password.html'), HTML( u'<div class="validate col s12 ">' u'<h3 class="medium" style="color:black;">' u'Información de entrega</h3></div>'), 'address', 'city', Field('province', template='materialize_css_forms/layout/select.html') )) def is_valid(self, subscription_type): result = super( SubscriberSignupAddressForm, self).is_valid(subscription_type) if result: # continue validation to check for the new signup: self.signup_form = SignupForm({ 'first_name': self.cleaned_data.get('first_name'), 'email': self.cleaned_data.get('email'), 'phone': self.cleaned_data.get('telephone'), 'password': self.cleaned_data.get('password')}) result = self.signup_form.is_valid() if not result: self._errors = self.signup_form._errors # TODO: telephone an phone should have same name to avoid this if 'phone' in self._errors: self._errors['telephone'] = self._errors.pop('phone') return result
class AdminStaffForm(forms.ModelForm): chs_password = ReadOnlyPasswordHashField(widget=PasswordInput(), required=False, help_text='Password can only be set, not viewed.') chs_organisation = forms.CharField(initial=None, required=False) chs_user = forms.CharField(initial=None, required=False) def clean(self): data = self.cleaned_data if not data['chs_password']: del self.cleaned_data['chs_password'] return data def save(self, commit=True): raw_password = self.cleaned_data.get('chs_password') if raw_password: self.instance.set_chs_password(raw_password) return super(AdminStaffForm, self).save(commit=commit) class Meta: model = Staff
class AuthenticationForm(AuthAuthenticationForm): """Adds appropriate classes to authentication form""" error_messages = { 'invalid_login': _t("Invalid username or password."), 'inactive': _t("Account deactivated. Please contact an administrator."), } username = CharField(label=_t("Username"), max_length=30, widget=TextInput(attrs={'maxlength': 30, 'placeholder': _t("Username"), 'autocomplete': 'off', 'autofocus': 'autofocus'})) password = CharField(label=_t("Password"), widget=PasswordInput(attrs={'placeholder': _t("Password"), 'autocomplete': 'off'})) def authenticate(self): return super(AuthenticationForm, self).clean() def clean(self): if conf.AUTH.EXPIRES_AFTER.get() > -1: try: user = User.objects.get(username=self.cleaned_data.get('username')) expires_delta = datetime.timedelta(seconds=conf.AUTH.EXPIRES_AFTER.get()) if user.is_active and user.last_login + expires_delta < datetime.datetime.now(): if user.is_superuser: if conf.AUTH.EXPIRE_SUPERUSERS.get(): user.is_active = False user.save() else: user.is_active = False user.save() if not user.is_active: if settings.ADMINS: raise ValidationError(mark_safe(_("Account deactivated. Please contact an <a href=\"mailto:%s\">administrator</a>.") % settings.ADMINS[0][1])) else: raise ValidationError(self.error_messages['inactive']) except User.DoesNotExist: # Skip because the server couldn't find a user for that username. # This means the user managed to get their username wrong. pass return self.authenticate()
class LoginForm(Form): username = CharField( required=True, max_length=50, min_length=3, widget= TextInput( attrs={ 'placeholder': 'Enter username', } ) ) password = CharField( required=True, max_length=50, min_length=1, widget=PasswordInput( attrs={ 'placeholder': 'Enter password', } ) )
class LoginForm(forms.Form): user_name = forms.CharField(label="Enter Email or Number") password = forms.CharField(widget=PasswordInput()) def __init__(self, *args, **kwargs): super(LoginForm, self).__init__(*args, **kwargs) def clean(self): user_name = self.cleaned_data['user_name'] password = self.cleaned_data['password'] print(user_name, password, 'bala') if user_name and password: user = authenticate(username=user_name, password=password) print(user) if user: # if user.is_superuser: # login(request, user) print('login') else: print('error') raise forms.ValidationError('') return user
class Meta: model = get_user_model() fields = ['name', 'person_nr', 'email', 'password'] labels = { 'name': 'Full name', 'person_nr': 'Social security number', 'email': 'E-mail address', 'password': '******' } widgets = { 'name': TextInput(), 'person_nr': TextInput(), 'email': EmailInput(), 'password': PasswordInput(), } field_order = [ 'name', 'person_nr', 'email', 'phone_nr', 'password', 'password_check' ]
class Meta: model = Chofer fields = ['nombre', 'a_paterno', 'a_materno', 'telefono', 'email', 'password', 'numero_licencia', 'turno', 'saldo', 'estatus' ] labels = {'nombre': 'Nombre', 'a_paterno': 'Apellido paterno', 'a_materno': 'Apellido materno', 'email': 'Correo electronico', 'password': '******', 'telefono': 'Telefono', } widgets = {'password': PasswordInput(), 'estatus': Select(choices=[[True, 'Activo'], [False, 'Inactivo']])}
class Meta: model = Post # fields = '__all__' # fields = ['title', 'body'] exclude = ['created_by'] widgets = { 'title': TextInput(attrs={ 'class': 'form-control', 'placeholder': 'My new post' }), 'body': Textarea(attrs={ 'class': 'form-control', 'placeholder': 'Paste the content here' }), 'post_type': Select(attrs={'class': 'form-control'}), 'password': PasswordInput(attrs={'class': 'form-control'}), }
class LoginForm(AuthenticationForm): username = CharField(widget=TextInput({ 'class': 'form-control', 'placeholder': 'Nombre de usuario' })) password = CharField( widget=PasswordInput({ 'class': 'form-control', 'placeholder': 'Contraseña' }), error_messages={ 'required': 'La contraseña es requerida, favor de verificarla.' }) class Meta: fields = '__all__' error_messages = { 'invalid_login': _("El usuario o la contraseña son incorrectos," + " favor de intentarlo nuevamente."), }
class form_certificados(forms.ModelForm): from django.forms import ModelForm, PasswordInput senha = forms.CharField(widget=PasswordInput()) def __init__(self, *args, **kwargs): super(form_certificados, self).__init__(*args, **kwargs) def save(self, commit=True, *args, **kwargs): request = None if kwargs.has_key('request'): request = kwargs.pop('request') m = super(form_certificados, self).save(commit=True, *args, **kwargs) if request is not None: if m.criado_por_id is None: m.criado_por_id = request.user.id m.criado_em = timezone.now() m.modificado_por_id = request.user.id m.modificado_em = timezone.now() m.ativo = True m.save() return m class Meta: model = Certificados exclude = [ 'criado_em', 'criado_por', 'modificado_em', 'modificado_por', 'desativado_em', 'desativado_por', 'senha' ]
def __init__(self, *args, **kwargs): super(registrousuariosForm, self).__init__(*args, **kwargs) #Esto siempre hay que ponerlo #manejo de mensajes de error self.fields['username'].error_messages = { 'required': 'El nombre de Usuario no es valido!' } self.fields['password'].error_messages = { 'required': 'El password ingresado no es valido!' } self.fields['email'].error_messages = { 'required': 'La direccion de E-mail ingresada no es correcta!' } #formateando los inputs ACTIVO = ((True, 'Activo'), (False, 'Inactivo')) self.fields['is_active'].widget = Select(choices=ACTIVO) self.fields['password'].widget = PasswordInput() #agregando max-length self.fields['numeroDoc'].widget.attrs['maxlength'] = 8
class ResourcePasswordForm(BulmaMixin, Form): password = CharField( label='Password', strip=False, widget=PasswordInput(attrs={ 'autocomplete': 'off', 'class': 'has-background-black-bis' }), ) resource: Model def __init__(self, resource, *args, **kwargs): super().__init__(*args, **kwargs) self.resource = resource self.update_fields() self.add_attrs('password', {'icon_left': 'fa-lock'}) def clean_password(self): data = self.cleaned_data['password'] if self.resource.share.matches(data): return data raise ValidationError('Invalid password')
class signupform(forms.Form): firstname = forms.CharField( required=True, label="firstname", widget=TextInput(attrs={'class':'input is-primary','placeholder':"enter firstname"}), ) lastname = forms.CharField( required=True, label="lastname", widget=TextInput(attrs={'class':'input is-primary','placeholder':"enter lastname"}), ) username = forms.CharField( required=True, label="username", widget=TextInput(attrs={'class':'input is-primary','placeholder':"enter username"}), ) password = forms.CharField( required=True, label="password", widget=PasswordInput(attrs={'class':'input is-primary','placeholder':"enter password"}), )
class Meta: model = User fields = ('username', 'password') widgets = { 'username': TextInput( attrs={ 'placeholder': "Имя", 'required': '' } ), 'password': PasswordInput( attrs={ 'placeholder': 'Пароль', 'required': '' } ), } labels = { 'password': '******', } help_texts = { 'email': '', }
class Meta: model = Usuario fields = [ 'username', 'password', 'first_name', 'last_name', 'email', ] labels = { 'username':'******', 'password':'******', 'first_name':'Nombre', 'last_name':'Apellido', 'email':'Correo electrónico', } widgets = { 'username':TextInput(attrs={'class':'form-control'}), 'password':PasswordInput(attrs={'class':'form-control'}), 'first_name':TextInput(attrs={'class':'form-control'}), 'last_name':TextInput(attrs={'class':'form-control'}), 'email':EmailInput(attrs={'class':'form-control'}), }
class SignInForm(forms.Form): username = forms.CharField(widget=TextInput( attrs={"class": "form-control"})) password = forms.CharField(widget=PasswordInput( attrs={"class": "form-control"})) class Meta: fields = ['username', 'password'] def check_user(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: return user else: raise ValidationError( 'Invalid login or password. Please, try again!') def clean(self): super(SignInForm, self).clean() self.check_user() return self.cleaned_data
class Meta: model = user fields = {'username', 'email', 'password'} labels = { 'username': '******', 'email': 'ایمیل(غیرضرورری)', 'password': '******' } widgets = { 'name': TextInput( attrs={ 'class': 'form-control', 'placeholder': 'نام کاربری خود را وارد کنید' }), 'email': EmailInput(attrs={'class': 'form-control'}), 'password': PasswordInput(attrs={'class': 'form-control'}), } help_texts = {'username': None, 'email': None, 'password': None}
class LoginForm(Form): username = CharField( label='username', widget=TextInput(attrs={ 'autocomplete': 'username', 'autofocus': True, 'render_value': False, }, ), ) password = CharField( label='password', widget=PasswordInput( attrs={ 'autocomplete': 'current-password', }, render_value=False, ), strip=False, ) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super(LoginForm, self).__init__(*args, **kwargs)
class SignupForm(Form): username = CharField(widget=TextInput(attrs={ 'class': 'form-control', })) password = CharField(widget=PasswordInput(attrs={ 'class': 'form-control', })) email = EmailField(label='Email', widget=EmailInput(attrs={ 'class': 'form-control mb-2', })) first_name = CharField(widget=TextInput(attrs={ 'class': 'form-control col m-2', })) last_name = CharField(widget=TextInput(attrs={ 'class': 'form-control col m-2', })) def clean(self): username = self.cleaned_data['username'] if User.objects.filter(username=username).exists(): msg = f"Sorry, the username '{username}' is already taken." self.add_error('username', msg)
def __init__(self, *args, **kwargs): if 'widget' not in kwargs: attrs = {} # 'minlength' is poorly supported, so use 'pattern' instead. # See http://stackoverflow.com/a/10294291/25507, # http://caniuse.com/#feat=input-minlength. if PASSWORD_MIN_LENGTH and PASSWORD_MAX_LENGTH: attrs['pattern'] = ('.{%i,%i}' % (PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) attrs['title'] = (_('%i to %i characters') % (PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) elif PASSWORD_MIN_LENGTH: attrs['pattern'] = '.{%i,}' % PASSWORD_MIN_LENGTH attrs['title'] = _( '%i characters minimum') % PASSWORD_MIN_LENGTH if PASSWORD_MAX_LENGTH: attrs['maxlength'] = PASSWORD_MAX_LENGTH kwargs["widget"] = PasswordInput(render_value=False, attrs=attrs) super(PasswordField, self).__init__(*args, **kwargs)
class LoginForm(AuthenticationForm): username = forms.CharField(widget=TextInput( attrs={ 'class': 'form-control input-md', 'style': 'min-width: 0; width: 25%; display: inline;', }), required=True) password = forms.CharField(widget=PasswordInput( attrs={ 'class': 'form-control input-md', 'style': 'min-width: 0; width: 25%; display: inline;', }), required=True) class Meta: model = User fields = [ 'username', 'password', ]
class PasswordChangeForm(PasswordChangeBaseForm): old_password = CharField( label=u'Contraseña actual', widget=PasswordInput( attrs={'autocomplete': 'current-password', 'autocapitalize': 'none', 'spellcheck': 'false'} ), ) def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_id = 'change_password' self.helper.form_class = 'form-horizontal' self.helper.form_style = 'inline' self.helper.form_method = 'post' self.helper.layout = Layout( 'old_password', 'new_password_1', 'new_password_2', HTML('<div class="align-center">'), FormActions(Submit('save', u'Elegir contraseña', css_class='ut-btn ut-btn-l')), HTML('</div>'), ) self.user = kwargs.get('user') if 'user' in kwargs: del(kwargs['user']) super(PasswordChangeForm, self).__init__(*args, **kwargs) def clean_old_password(self): from django.contrib.auth import authenticate password = self.cleaned_data.get('old_password', '') user = authenticate(username=self.user.username, password=password) if not user: raise ValidationError('Contraseña incorrecta.') return password
class CreateAccountForm(ModelForm): def clean_password_check(self): password = self.cleaned_data.get('password') password_check = self.cleaned_data.get('password_check') if not password_check: raise ValidationError("You must confirm you password!") if password != password_check: raise ValidationError("The passwords do not match!") return password_check phone_nr = PhoneNumberField() password_check = CharField(widget=PasswordInput(), label='Confirm your password') class Meta: model = get_user_model() fields = ['name', 'person_nr', 'email', 'password'] labels = { 'name': 'Full name', 'person_nr': 'Social security number', 'email': 'E-mail address', 'password': '******' } widgets = { 'name': TextInput(), 'person_nr': TextInput(), 'email': EmailInput(), 'password': PasswordInput(), } field_order = [ 'name', 'person_nr', 'email', 'phone_nr', 'password', 'password_check' ]
class StaffAdminForm(OneToOneUserAdminForm): chs_password = ReadOnlyPasswordHashField( widget=PasswordInput(attrs={"class": "vTextField"}), required=False, help_text="Password can only be set, not viewed.", ) chs_organisation = forms.CharField(initial=None, required=False, widget=widgets.AdminTextInputWidget) chs_user = forms.CharField(initial=None, required=False, widget=widgets.AdminTextInputWidget) def clean(self): data = self.cleaned_data if not data["chs_password"]: del self.cleaned_data["chs_password"] return data def save(self, commit=True): raw_password = self.cleaned_data.get("chs_password") if raw_password: self.instance.set_chs_password(raw_password) return super(StaffAdminForm, self).save(commit=commit) class Meta(object): model = Staff fields = [ "username", "password", "password2", "first_name", "last_name", "email", "provider", "chs_organisation", "chs_user", "chs_password", "is_active", "is_manager", ]