Esempio n. 1
0
 def test_unknown_user_by_email(self):
     form = auth_forms.LoginForm({
         'redirect': '/',
         'email': '*****@*****.**',
         'password': '******'
     })
     self.assertFalse(form.is_valid())
Esempio n. 2
0
def login(request):
    loginForm = forms.LoginForm()
    error = None
    if request.method == "POST":
        loginForm = forms.LoginForm(request.POST)
        if loginForm.is_valid():
            username = loginForm.cleaned_data['username']
            password = loginForm.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user:
                auth_login(request, user)
                return HttpResponseRedirect('/')
            else:
                error = "Invalid UserName or Password"

    context = {"form": loginForm, "error": error}

    return render(request, 'auth/login.html', context)
Esempio n. 3
0
def reg():
    form = forms.LoginForm()
    if form.validate_on_submit():
        name = form.name.data
        form.name.data = ''
        passwd = form.passwd.data
        form.name.data = ''
        print name, passwd
    # return render_template('forms.html', form=form, name=name, passwd=passwd)
    return render_template('forms.html', form=form)
def login(request):
    error = None
    form = forms.LoginForm()
    if request.method=='POST':
        form = forms.LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username = username, password = password)
            if user:
                auth_login(request, user)
                return HttpResponseRedirect('/')
            else:
                error = "INVALID USERNAME OR PWD"

    context = {
        "form" : form,
        "error" : error
    }
    return render(request, 'login.html', context)
def login(request):
    loginForm = forms.LoginForm()
    error = None

    if request.method == "POST":
        loginForm = forms.LoginForm(request.POST)

        if loginForm.is_valid():
            username = loginForm.cleaned_data['username']
            password = loginForm.cleaned_data['password']

            user = authenticate(username=username, password=password)

            if user:
                auth_login(request, user)  # STARTS A SESSION FOR THIS USER
                return HttpResponseRedirect('/')
            else:
                error = "Invalid username and password"

    context = {'form': loginForm, 'error': error}

    return render(request, 'auth/login.html', context)
Esempio n. 6
0
def auth_login(request):
    loginform = forms.LoginForm()
    error = None
    if request.method == 'POST':
        loginform = forms.LoginForm(request.POST)
        if loginform.is_valid():
            username = loginform.cleaned_data['username']
            password = loginform.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user:
                login(
                    request, user
                )  # login() saves the user’s ID in the session, using Django’s session framework.
                # it is used to attach the user to the current session.
                return HttpResponseRedirect('/')
            else:
                error = "Invalid username or password"
    context = {
        'loginform': loginform,
        'error': error,
    }
    return render(request, 'auth/login.html', context=context)
Esempio n. 7
0
def Login(request):
    if request.method == "POST":
        form = request.POST.copy()
        username = form.get("UserName")
        password = form.get("password")

        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            return render(request, 'Home/homepage.html')

        else:
            error = "Incorrect Username or Password"
            form = forms.LoginForm()
            return render(request, 'auth/login.html', {
                'error': error,
                "form": form
            })

    else:
        form = forms.LoginForm()
    return render(request, 'auth/login.html', {"form": form})
Esempio n. 8
0
    def test_login_with_case_insensitive_email(self):
        # Set up a test user.
        email = '*****@*****.**'
        user = User(email=email)
        user.set_password('password')
        user.save()

        # This should succeed.
        form = auth_forms.LoginForm({
            'redirect': '/',
            'email': '*****@*****.**',
            'password': '******'
        })
        self.assertTrue(form.is_valid())
Esempio n. 9
0
def hello(request):
    """Implements our login page."""
    redirect = '/'
    tmpl = loader.get_template('auth/hello.html')
    if request.method == 'GET':
        redirect = request.GET.get('redirect', '/')
        # Already signed in?  Then redirect immediately.
        if request.user:
            return http.HttpResponseRedirect(redirect)
        form = auth_forms.LoginForm(initial={
            'redirect': redirect,
        })
    else:
        form = auth_forms.LoginForm(request.POST)
        if form.is_valid():
            response = http.HttpResponseRedirect(form.cleaned_data['redirect'])
            auth.attach_credentials(response, form.user)
            # Update the last login time in the User record.
            form.user.last_login = datetime.datetime.now()
            AutoRetry(form.user).save()
            return response

    ctx = RequestContext(request, {'form': form})
    return http.HttpResponse(tmpl.render(ctx))
Esempio n. 10
0
 def test_login_form(self):
     # Set up a test user.
     email = '*****@*****.**'
     user = User(email=email)
     user.set_password('password')
     user.save()
     # Missing required data
     form = auth_forms.LoginForm({'redirect': '/'})
     self.assertFalse(form.is_valid())
     form = auth_forms.LoginForm({'redirect': '/', 'email': email})
     self.assertFalse(form.is_valid())
     # Form should fail to validate if password is incorrect.
     form = auth_forms.LoginForm({
         'redirect': '/',
         'email': email,
         'password': '******'
     })
     self.assertFalse(form.is_valid())
     # This should succeed.
     form = auth_forms.LoginForm({
         'redirect': '/',
         'email': email,
         'password': '******'
     })
     self.assertTrue(form.is_valid())
     # The form should reject inactive users.
     user.is_active = False
     user.save()
     form = auth_forms.LoginForm({
         'redirect': '/',
         'email': email,
         'password': '******'
     })
     self.assertFalse(form.is_valid())
     # The form should reject unknown users.
     form = auth_forms.LoginForm({
         'redirect': '/',
         'email': '*****@*****.**',
         'password': '******'
     })
     self.assertFalse(form.is_valid())