def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username and password: self.user_chache = authenticate(username=username, password=password) if self.user_chache is None: raise forms.ValidationError(_("Silahkan masukan username dan password anda dengan benar!!!")) elif not self.user_chache.is_active: raise forms.ValidationError(_("Akun ini sedang aktif!!! ")) return cleaned_data
def clean(self): cleaned_data = super(Register, self).clean() form_empty = True for field_value in cleaned_data.values(): if field_value is not None and field_value = '': form_empty = False break if form_empty: raise forms.ValidationError(_("Harus diisi!!!")) return cleaned_data
def clean_password(self): password = self.cleaned_data.get('password') password2 = self.cleaned_data.get('password2') if password != password2: raise forms.ValidationError(_("Password harus sama!!!"))
def clean_email(self): email = self.cleaned_data['email'] email_qs = User.objects.filter(email=email) if email_qs.exists(): raise forms.ValidationError(_("E-mail ini sudah terdaftar!!!")) return email
def cleaned_username(self): existing = User.objects.filter(username__iexact=self.cleaned_data['username']) if existing.exists(): raise forms.validationError(_("Username yang diinput sudah ada!!!")) return self.cleaned_data['username']