def user_login(request): if request.method == 'POST': form = UserLoginForm(data=request.POST) if form.is_valid(): data = form.cleaned_data if not data.get('remember_me', None): request.session.set_expiry(0) user = authenticate(username=data.get('username'), password=data.get('password')) if user: if user.is_active: login(request, user) return redirect('backoffice:index') else: return HttpResponse("Votre compte est désactivé.") else: return HttpResponse("Identifiants invalides.") else: form = UserLoginForm() return render(request, 'backoffice/login.html', {'login_form': form})
def test_missing_password(self): form = UserLoginForm(data=self.missing_password) self.assertFalse(form.is_valid())
def test_valid_form_without_remember_me(self): form = UserLoginForm(data=self.valid_form_data_without_remember_me) self.assertTrue(form.is_valid())
def test_missing_username(self): form = UserLoginForm(data=self.missing_username) self.assertFalse(form.is_valid())
def test_valid_form(self): form = UserLoginForm(data=self.valid_form_data) self.assertTrue(form.is_valid())