def test_form_login(self): request = self.factory.post('', { 'username': '******', 'password': '******' }) form = LoginForm(request.POST) self.assertTrue(form.is_valid()) user = form.login(request) self.assertTrue(user, self.user)
def login_user(request): form = LoginForm(request.POST or None) if request.method == "POST": if form.is_valid(): user = form.login(request) if user: login(request, user) if request.POST.get("next"): return HttpResponseRedirect(request.POST.get("next")) else: return HttpResponseRedirect("/") return render(request, "core/login.html", {"form": form})
def login_user(request): form = LoginForm(request.POST or None) if request.method == 'POST': if form.is_valid(): user = form.login(request) if user: login(request, user) if request.POST.get('next'): return HttpResponseRedirect(request.POST.get('next')) else: return HttpResponseRedirect('/') return render(request, 'core/login.html', {'form': form})
def login_user(request): form = LoginForm(request.POST or None) if request.method == 'POST': if form.is_valid(): user = form.login(request) if user: login(request, user) if request.GET.get('next'): # Redirect to a success page. return HttpResponseRedirect(request.GET.get('next')) else: return HttpResponseRedirect('/') return render(request, 'core/login.html', {'form': form})
def test_form_login(self): request = self.factory.post('', {'username': '******', 'password': '******'}) form = LoginForm(request.POST) self.assertTrue(form.is_valid()) user = form.login(request) self.assertTrue(user, self.user)