Пример #1
0
 def test_empty_password(self):
     form = LoginForm({'username': '******', 'password': ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'password': [u'This field is required.']}
     )
Пример #2
0
def signin(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        user = request.user
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                user.login = True
                #return render(request, 'userauth/l.html')
                if user.status == 'In':
                    return HttpResponseRedirect(reverse('userauth:profile'))
                return HttpResponseRedirect(reverse('scrapedstories:mystory'))

            else:
                return render(request, 'userauth/login.html', {
                    'form': form,
                    'erro_msg': "wrong username or password"
                })
        else:
            return render(request, 'userauth/login.html', {
                'form': form,
                'erro_msg': "Error!!"
            })

    else:
        form = LoginForm()
        return render(request, 'userauth/login.html', {'form': form})
Пример #3
0
 def test_too_long_username(self):
     form = LoginForm(self.too_long_username)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'username': [u'Ensure this value has at most 64' +
                       ' characters (it has 65).']}
     )
Пример #4
0
def login_view(request):
    if request.method == 'POST':
        # pdb.set_trace()
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST['username'],
                                password=request.POST['password'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return redirect('home:index')
        else:
            return render(request, 'userauth/login.html', {'form': form})
    else:
        return render(request, 'userauth/login.html', {'form': LoginForm()})

    return redirect('home:index')
Пример #5
0
 def post(self, request, *args, **kwargs):
     if request.method == 'POST':
         form = LoginForm(request.POST)
         if form.is_valid():
             user = authenticate(username=request.POST['username'],
                                 password=request.POST['password'])
             if user is not None:
                 if user.is_active:
                     login(request, user)
                     return redirect('list:index')
         else:
             return render(
                 request, 'userauth/login.html', {
                     'form': LoginForm(),
                     "error": "Incorrect username and/or password."
                 })
     else:
         return render(request, 'userauth/login.html',
                       {'form': LoginForm()})