Ejemplo n.º 1
0
 def test_invalid_form(self):
     data = {
         'username': '',
         'password': '',
     }
     form = LoginForm(data=data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 2
0
def login(request):
    """Backend for AJAX login.

    POST:
    username -- username to login
    password -- password of the username

    Renders JSON: (besides 'status' or 'err')
    username -- (on 'OK') username of the logged in user
    name     -- (on 'OK') name of the logged in user
    detail   -- (on 'Error') error list from form validation

    POST data will be validated by LoginForm.
    """
    form = LoginForm(request.POST)
    if form.is_valid():
        user = auth.authenticate(
            username=form.cleaned_data['username'],
            password=form.cleaned_data['password'],
            )
        if user is not None:
            if user.is_active:
                try:
                    user.myuser
                except MyUser.DoesNotExist as err:
                    return render_JSON_Error('Root cannot login here.')
                auth.login(request, user)
                return render_JSON_OK({
                    'username': user.username,
                    'name': user.myuser.name,
                    })
        return render_JSON_Error('Login failed.')
    return render_JSON_Error('Login syntax error.', {
        'detail': form.errors,
        })
Ejemplo n.º 3
0
 def test_valid_form(self):
     username = self.user.username
     password = self.user.password
     data = {
         'username': username,
         'password': password,
     }
     form = LoginForm(data=data)
     self.assertTrue(form.is_valid())
Ejemplo n.º 4
0
def auth(request):
    form = LoginForm(request.POST)
    if form.is_valid():
        d = form.cleaned_data
        print(d)
    else:
        print('Some field missing')
    # username = request.POST['username']
    # password = request.POST['password']
    '''l = Student.objects.filter(username=username, password=password)