예제 #1
0
def signin(request):
    if request.user.is_authenticated:
        return redirect('/')
    
    else:
        if request.method == 'POST':
            form = SignInForm(request.POST)
            if not form.is_valid():
                return render(request, 'accounts/login.html', { 'forms': form, 'unregistereduser': False })

            else:
                # check for terms of services
                email = form.cleaned_data.get('email')
                password = form.cleaned_data.get('password')

                # authenticate then login
                user = authenticate(email=email, password=password)
                if user is not None:

                    if user.is_active:
                        login(request, user)
                        return redirect('/') 
                else:
                    return render(request, 'accounts/login.html', { 'forms': form, 'unregistereduser': True })


        else:
            return render(request, 'accounts/login.html', { 'forms': SignInForm(), 'unregistereduser': False })
예제 #2
0
    def test_signIn_form_no_data(self):
        user = User.objects.create_user(username="******",
                                        password="******")
        form = SignInForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 2)
예제 #3
0
 def test_valid_data(self):
     form = SignInForm(
         data={
             'email': '*****@*****.**',
             'password': '******',
             'remember': True,
             'captcha': 'IDGS'
         })
     self.assertTrue(form.is_valid())
예제 #4
0
    def test_signIn_form(self):
        user = User.objects.create_user(username="******",
                                        password="******")
        form = SignInForm(data={
            "username": "******",
            "password": "******"
        })

        self.assertTrue(form.is_valid())
예제 #5
0
    def test_sigIn_form_invalid(self):
        user = User.objects.create_user(username="******",
                                        password="******")
        form = SignInForm(data={
            "username": "******",
            "password": "******"
        })

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)
예제 #6
0
def sign_in_view(request):
    # generate_booking_data()
    old_user = request.user
    # print(old_user.user_id)
    if not old_user.is_anonymous:
        return redirect("search:search")

    if request.method == "POST":
        sign_in_form = SignInForm(data=request.POST)
        if sign_in_form.is_valid():
            user = sign_in_form.get_user()
            login(request, user)
            if user.is_admin:
                return redirect("dashboard:dashboard")
            else:
                return redirect("search:search")
        else:
            return render(request, "accounts/signin.html",
                          {"form": sign_in_form})
    else:
        sign_in_form = SignInForm()
        return render(request, "accounts/signin.html", {"form": sign_in_form})
예제 #7
0
파일: views.py 프로젝트: KdJohar/oposod
def signin(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    form = SignInForm(request.POST or None)
    if form.is_valid():
        username_or_email = form.cleaned_data['username_or_email']
        password = form.cleaned_data['password']
        user_obj = None
        try:
            user_obj = User.objects.get(username=username_or_email)
        except:
            user_obj = User.objects.get(email=username_or_email)

        if user_obj:
            if check_password(password, user_obj.password):
                user = authenticate(username=user_obj.username, password=password)
                if user:
                    if user.is_active:
                        login(request, user)
                        request.session['username'] = user_obj.username
                        # Append the user to online users set in redis.
                        # Also create a notifications object which will be used
                        # to initiate and send notifications
                        redis_obj = StrictRedis(db=9)
                        redis_obj.sadd('online:users', user_obj.username)
                        next = request.GET.get('next', '')
                        if next:
                            return HttpResponseRedirect(next)
                        else:
                            return HttpResponseRedirect(reverse('profile', args=(str(user_obj.username),)))

                else:
                    messages.info(request, 'Please activate your account first.')
                    return HttpResponseRedirect(reverse('accounts.views.signin.'))
    return render(request, 'accounts/signin.html', {
        'form': form,
    })
예제 #8
0
 def test_invalid_data(self):
     form = SignInForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 3)