Example #1
0
 def test(self):
     email = '*****@*****.**'
     name = 'UserTest'
     pwd = 'test'
     user = User.objects.create(email=email, name=name)
     user.set_pwd(pwd) # encrypt raw password
     user.save()
     self.assertEqual(usr.authenticate(name=name, pwd=pwd) is not None, True)
Example #2
0
 def clean(self):
     name = self.cleaned_data.get('username')
     pwd = self.cleaned_data.get('password')
     if name and pwd:
         # check user existance and activity
         from usr import authenticate
         self.user_cache = authenticate(name=name, pwd=pwd)
         if self.user_cache is None:
             raise forms.ValidationError("Please enter correct username and password.Note that password are case-sensitive.")
         if not self.user_cache.is_active:
             raise forms.ValidationError("This account is inactive.")
     else:
         raise forms.ValidationError("Please input username and password.")
     if self.request:
         if not self.request.session.test_cookie_worked():
             raise forms.ValidationError("Your Web browser doesn't appear to have cookies enabled.Cookies are required for logging in.")
     return self.cleaned_data