Exemple #1
0
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})
Exemple #2
0
 def test_missing_password(self):
     form = UserLoginForm(data=self.missing_password)
     self.assertFalse(form.is_valid())
Exemple #3
0
 def test_valid_form_without_remember_me(self):
     form = UserLoginForm(data=self.valid_form_data_without_remember_me)
     self.assertTrue(form.is_valid())
Exemple #4
0
 def test_missing_username(self):
     form = UserLoginForm(data=self.missing_username)
     self.assertFalse(form.is_valid())
Exemple #5
0
 def test_valid_form(self):
     form = UserLoginForm(data=self.valid_form_data)
     self.assertTrue(form.is_valid())
Exemple #6
0
 def test_missing_username(self):
     form = UserLoginForm(data=self.missing_username)
     self.assertFalse(form.is_valid())
Exemple #7
0
 def test_valid_form_without_remember_me(self):
     form = UserLoginForm(data=self.valid_form_data_without_remember_me)
     self.assertTrue(form.is_valid())
Exemple #8
0
 def test_valid_form(self):
     form = UserLoginForm(data=self.valid_form_data)
     self.assertTrue(form.is_valid())
Exemple #9
0
 def test_missing_password(self):
     form = UserLoginForm(data=self.missing_password)
     self.assertFalse(form.is_valid())