def clean_validation(self): if self.code == "": raise forms.ValidationError(_T("The validation code has expired!")) elif self.cleaned_data['validation'] != self.code: raise forms.ValidationError(_T("Invalid validation code!")) else: return self.cleaned_data['validation']
def clean(self): if not self.hasCookie: raise forms.ValidationError(_T("Cookie is required!")) elif len(self.errors) == 0: cleaned_data = forms.Form.clean(self) if check_password(cleaned_data['password'], self.cleaned_data['user'].user.password): return cleaned_data else: self.errors['password'] = forms.ValidationError(_T("Invalid Password!")) raise self.errors['password'] else: return None
def clean_username(self): user = djangobbs.accounts.tools.finduser(self.cleaned_data['username']) if user: self.cleaned_data['user'] = user return self.cleaned_data['username'] else: raise forms.ValidationError(_T("The user does not exist!"))
class UserProfile(UserenaBaseProfile): """ User details such as home institution, etc., which we may wish to store in addition to the user details such as name and email maintained by django User. The UserenaBaseProfile maintains the mug shot. For now we are not maintaining a user profile. """ user = models.OneToOneField( User, unique=True, verbose_name=_T('user'), related_name='profile', )
def validate(self, attrs): """#Valida y autentifica el usuario.""" email = attrs.get('email') password = attrs.get('password') user = authenticate(request=self.context.get('request'), username=email, password=password) if not user: msg = _T('No ha sido posible autenticar con los datos otorgados.') raise serializers.ValidationError(msg, code='authentication') attrs['user'] = user return attrs
# 对应的项 entry = models.ForeignKey('accounts.ExtraProfileEntry') # 记录的内容 content = models.TextField(blank=True, default="") # 记录的时间 time = models.DateTimeField(auto_now=True) def __unicode__(self): return unicode(self.user) + u'.' + unicode(self.entry) + u'@' + unicode(self.time) + u'.' + self.content admin.site.register(ExtraUserData) EXTERNAL_ENTRY_COLLECT_SOURCE = ( ('U', _T('By User')), # 由用户填写 ('?', _T('Undefined')), # 系统保留。由各个应用自行决定用法 ('M', _T('request.META')), # 从request.META读出 ('G', _T('request.GET')), # 从request.GET读出 ('P', _T('request.POST')), # 从request.POST读出 ('R', _T('request.REQUEST')),# 从request.REQUEST读出 ('C', _T('request.COOKIE')), # 从request.COOKIES读出 ('s', _T('request.session')),# 从request.session读出 ('F', _T('request.FILES')), # 从request.FILES读出 ) EXTERNAL_ENTRY_COLLECT_TIME = ( ('R', _T('At register')), # 注册时要求填写, 注册后用户不可更改 ('M', _T('Manual')), # 注册时填写, 注册后可以由用户手动更改 ('I', _T('At login')), # 登陆时自动记录, ('O', _T('At logout')), # 登出时自动记录,
def clean(self): if not self.hasCookie: raise forms.ValidationError(_T("Cookie is required!")) return cleaned_data
def clean_email(self): n = User.objects.filter(email=self.cleaned_data['email']).count() if n < MAX_USER_PER_EMAIL: return self.cleaned_data['email'] else: raise forms.ValidationError(_T("The email was used by someone else!"))
def clean_username(self): user = djangobbs.accounts.tools.finduser(self.cleaned_data['username']) if user: raise forms.ValidationError(_T("The user name was used by someone else!")) else: return self.cleaned_data['username']