class UserSignUpForm(forms.Form): # MIN_LENGTH = settings.PASSWORD_MIN_LENGTH MIN_LENGTH = 5 email = forms.EmailField(label=_('email'), required=True, max_length=255) first_name = forms.CharField(max_length=30, label=_('First Name')) password = forms.CharField(widget=forms.PasswordInput(), label=_("Password"), min_length=6) class Meta: model = ApplicationUser fields = ('first_name', 'last_name', 'phoneNumber', 'password') def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(UserSignUpForm, self).__init__(*args, **kwargs) def clean_password(self): password = self.cleaned_data.get('password') if len(password) < self.MIN_LENGTH: raise forms.ValidationError( "The password must be at least %d characters long." % self.MIN_LENGTH) else: print '>>> password is :', password return password
class CourseSubscriptionForm(forms.Form): code = forms.CharField( label=_('2FA Code'), max_length=100, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': _('2FA Code')}) ) password = forms.CharField( label=_("Password"), widget=forms.PasswordInput ) terms = forms.BooleanField() def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') super().__init__(*args, **kwargs) def clean_password(self): password = self.cleaned_data['password'] if not self.user.check_password(password): raise forms.ValidationError(_("Wrong password informed")) return password def clean_code(self): code = self.cleaned_data['code'] if not bool(match_token(self.user, code)): raise forms.ValidationError(_("The 2FA code is invalid")) return code
class SkillForm(ModelForm): name = forms.CharField(max_length=100, required=False) description = forms.CharField(widget=forms.Textarea, required=False) class Meta: model = Skill exclude = ['user']
class SignupForm(account.forms.SignupForm): advisor = forms.CharField(label=_("Advisor username (optional)"), required=False) first_name = forms.CharField(label=_("First name")) last_name = forms.CharField(label=_("Last name")) confirm_email = forms.EmailField(label=_("Confirm e-mail")) password = PasswordField(label=_("Password"), strip=settings.ACCOUNT_PASSWORD_STRIP) terms = forms.BooleanField(label=_("I have read and agree to the terms of use: <a href=\"https://www.xfactor.cash/terms.html\" target=\"blank\">open terms</a>")) field_order = ['type', 'advisor', 'first_name', 'last_name', 'username', 'email', 'confirm_email', 'password', 'password_confirm', 'term'] # Valida o campo de confirmar e-mail def clean_confirm_email(self): email = self.cleaned_data.get('email') confirm_email = self.cleaned_data.get('confirm_email') if not email == confirm_email: raise forms.ValidationError(_("The e-mails aren't equal")) return confirm_email def clean_advisor(self): advisor = self.cleaned_data['advisor'] if len(advisor) > 0: if not Users.objects.filter(username=advisor, is_active=True, graduations__type=Graduations._advisor).exists(): raise forms.ValidationError(_("Advisor doesn't exists")) return
class SendTokensForm(forms.Form): tokens = forms.FloatField() from_user = forms.CharField(widget=forms.HiddenInput()) to_user = forms.CharField(widget=forms.HiddenInput()) def clean(self): form_data = self.cleaned_data from_user = User.objects.filter( kepler_id=form_data['from_user']).first() to_user = User.objects.filter(kepler_id=form_data['to_user']).first() tokens = self.cleaned_data['tokens'] if not from_user or not to_user: raise ValidationError("Cannot find specified users") if from_user.tokens < tokens: raise ValidationError("You don't have enough tokens to send") return form_data
class SignupForm(forms.Form): name = forms.CharField(label=_("Name"), max_length=30, widget=forms.TextInput(), required=True) password = account.forms.PasswordField( label=_("Password"), strip=settings.ACCOUNT_PASSWORD_STRIP, ) password_confirm = account.forms.PasswordField( label=_("Password (again)"), strip=settings.ACCOUNT_PASSWORD_STRIP, ) email = forms.EmailField(label=_("Email"), widget=forms.TextInput(), required=True) code = forms.CharField(max_length=64, required=False, widget=forms.HiddenInput()) agree_terms = forms.BooleanField( required=True, error_messages={ 'required': 'You must agree to our Terms of service to sign up.' }) def clean_username(self): return self.cleaned_data["username"] def clean_email(self): value = self.cleaned_data["email"] qs = EmailAddress.objects.filter(email__iexact=value) if not qs.exists() or not settings.ACCOUNT_EMAIL_UNIQUE: return value raise forms.ValidationError( _("A user is registered with this email address.")) def clean(self): if "password" in self.cleaned_data and "password_confirm" in self.cleaned_data: if self.cleaned_data["password"] != self.cleaned_data[ "password_confirm"]: raise forms.ValidationError( _("You must type the same password each time.")) return self.cleaned_data
class SignupForm(account.forms.SignupForm): avatar = forms.ImageField(required=True) kepler_id = forms.CharField(max_length=30, required=True) username = None first_name = forms.CharField(max_length=250) last_name = forms.CharField(max_length=250) email = forms.EmailField() def __init__(self, *args, **kwargs): super(account.forms.SignupForm, self).__init__(*args, **kwargs) field_order = [ "kepler_id", "first_name", "last_name", "password", "email", "avatar" ] if not OrderedDict or hasattr(self.fields, "keyOrder"): self.fields.keyOrder = field_order else: self.fields = OrderedDict((k, self.fields[k]) for k in field_order) class Meta: model = UserProfile def clean_kepler_id(self): kepler_id = self.cleaned_data['kepler_id'] if not User.objects.filter(kepler_id=kepler_id).exists(): raise ValidationError( "please make sure that your kepler id is correct") user = User.objects.filter(kepler_id=kepler_id).first() if UserProfile.objects.filter(user=user).exists(): raise ValidationError("Kepler profile already exists") return kepler_id def clean_email(self): email = self.cleaned_data['email'] return email def clean(self): form_data = self.cleaned_data kepler_id = form_data['kepler_id'] email = form_data['email'] user_profile = User.objects.filter(kepler_id=kepler_id).first() if user_profile.email != email: raise ValidationError("Provided kepler id and email doesn't match") return form_data
class userLoginForm(forms.Form): identifier_field = "getNumber" getNumber = forms.CharField(max_length=30, label=_('Phone Number')) password = forms.CharField(label=_("Password"),widget=forms.PasswordInput(render_value=False)) def clean(self, *args, **kwargs): cleaned_data = super(userLoginForm, self).clean(*args, **kwargs) if self._errors: return user = auth.authenticate(**self.user_credentials()) if user: self.user = user else: raise forms.ValidationError( _("Please make sure you are providing valid Phone Number and password.")) return cleaned_data def user_credentials(self): self.identifier_field = "getNumber" return hookset.get_user_credentials(self, self.identifier_field)
class SignupForm(account.forms.SignupForm): first_name = forms.CharField(label=_(u'First name'), max_length=30, required=True) last_name = forms.CharField(label=_(u'Last name'), max_length=30, required=True) address = forms.CharField(max_length=100, required=True) field_order = [ 'username', 'first_name', 'last_name', 'email', 'password', 'password_confirm', 'address', ]
class userLoginForm(forms.Form): identifier_field = "email" email = forms.CharField(label=_("Email"), max_length=60) password = forms.CharField(label=_("Password"), widget=forms.PasswordInput(render_value=False)) def clean(self, *args, **kwargs): print '>>> In clean function of Form <<' cleaned_data = super(userLoginForm, self).clean(*args, **kwargs) if self._errors: return user = auth.authenticate(**self.user_credentials()) if user: self.user = user else: raise forms.ValidationError( _("Please make sure you are providing valid Username and password." )) return cleaned_data def user_credentials(self): self.identifier_field = "email" return hookset.get_user_credentials(self, self.identifier_field)
class LoginForm(account.forms.LoginForm): kepler_id = forms.CharField(label=("kepler_id")) username = None identifier_field = "kepler_id" authentication_fail_message = ( "The email address and/or password you specified are not correct.") def __init__(self, *args, **kwargs): super(account.forms.LoginForm, self).__init__(*args, **kwargs) field_order = ["kepler_id", "password", "remember"] if not OrderedDict or hasattr(self.fields, "keyOrder"): self.fields.keyOrder = field_order else: self.fields = OrderedDict((k, self.fields[k]) for k in field_order) class Meta: model = User
class Code2FAForm(forms.Form): code = forms.CharField( label=_('2FA Code'), max_length=100, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': _('2FA Code')}) ) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super().__init__(*args, **kwargs) def clean_code(self): code = self.cleaned_data['code'] if not bool(match_token(self.request.user, code)): raise forms.ValidationError(_("The 2FA code is invalid")) return code
class PaymentsForm(forms.Form): error_css_class = 'error' type = forms.ChoiceField( label=_('Payment Type'), widget=forms.Select(attrs={'autofocus': True, 'class': 'form-control'}), choices=(('plan', _("User plan"),), ('course', _("Course"),)) ) code = forms.CharField( label=_("Payment Code"), max_length=10, widget=forms.TextInput(attrs={'autofocus': True, 'class': 'form-control', 'placeholder': _('Payment Code')}), ) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super().__init__(*args, **kwargs) def clean_code(self): return self.cleaned_data['code']