Example #1
0
def login_user(request):
    """Login view."""
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('root', kwargs={}))

    login_error_msg = None
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            auth_user = authenticate(username=form.cleaned_data['username'],
                                     password=form.cleaned_data['password'])
            if auth_user:
                login(request, auth_user)
                return HttpResponseRedirect(reverse('root', kwargs={}))
            else:
                login_error_msg = 'Login error'
    else:
        form = LoginForm()

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

    return render(request, 'login.html', context)
Example #2
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.load()
            auth.login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', { 'form': form })            
Example #3
0
def user_login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')
    form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #4
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(**form.cleaned_data)
            if user:
                login(request, user)
                return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {
        'form': form,
    })
Example #5
0
def login(request):
	if request.method == 'POST':
		form = LoginForm(request.POST)
		if form.is_valid():
			user = form.save()
			request.session.flush()
			request.session['user'] = user.id
			return HttpResponseRedirect('/')
	else:
		form = LoginForm()
	return render(request, 'login_form.html', {
		'form': form,
	})	
Example #6
0
def login_user(request):
	if request.method == "POST":
		form = LoginForm(request.POST)
		if form.is_valid():
			user = authenticate(username=request.POST.get('username'), password = request.POST.get('password'))
			if user is not None and user.is_active:
				login(request,user)
				return HttpResponseRedirect("/")
	else:
		form = LoginForm()
	return render(request, 'qa/login.html', {
		'form': form
	})
Example #7
0
def mylogin(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #8
0
def log_in(request):
    if request.method == 'POST':
        form = 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 is not None:
                if user.is_active:
                    login(request, user)
            return HttpResponseRedirect(reverse('index'))
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #9
0
File: views.py Project: zmozg/web
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect('/')
            return HttpResponseRedirect('/login.html')
    else:
        form = LoginForm()
    return render(request, 'qa/login.html', {'form': form})
Example #10
0
def loginn(request):
    error = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(**form.cleaned_data)
            if user:
                login(request, user)
                return redirect('main')
            else:
                error = 'Invalid username or password. Try again!'
    else:
        form = LoginForm()
    return render(request, 'qa/login.html', {'form': form, 'error': error})
Example #11
0
def login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username = username, password = password)
            auth_login(request, user)
            return HttpResponseRedirect(reverse('homepage'))
    else:
        form = LoginForm()
    return render(request, 'login.html', {
        'form' : form
    })
Example #12
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save(request)
            if user != None:
                resp = HttpResponseRedirect('/') #Replace to request.next
                return resp       
    else:
        form = LoginForm()
            
    return render(request, 'login.html', {
                'form': form,
        })
Example #13
0
def dolog(request):
	user = request.user
	if user.is_authenticated():
		return HttpResponseRedirect("/")

	if request.method == "POST":
                form = LoginForm(request.POST)
                if form.is_valid():
			form.log(request)
                        return HttpResponseRedirect("/")
        else:
                        form = LoginForm()
        return render(request, 'qa/formlogin.html', {
                'form': form
})
Example #14
0
File: views.py Project: VLPC/web
def login_view(request):
    if request.method == 'POST':
        form = 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 is not None:
                login(request, user)
            response = HttpResponseRedirect('/')
            response.set_cookie('sessionid', 'sessionid')
            return response
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #15
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            sessionid = form.save()
            if sessionid:
                url = request.GET.get('continue', '/')
                response = HttpResponseRedirect(url)
                response.set_cookie('sessionid', sessionid,
                                    '''domain='.site.com' ''', httponly=True,
                                    expires=datetime.now() + timedelta(days=5))
                return response
    form = LoginForm()
    return render(request, 'login.html', {
        'form': form
    })
Example #16
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {
        'form': form,
        'user': request.user,
        'session': request.session,
    })
def login_add(request):
   #logger.debug(request)
   if request.method == 'POST': 
     #logger.debug('login_add:' + request.method)
     form = LoginForm(request.POST)
     #logger.debug('login_add POST:' + request.POST['username'] + ',pass='******'password'])
     if form.is_valid():
         #logger.debug('login_add form.is_valid:')
         user = form.save()
         if user is not None:
           logout(request)
           login(request,user)
           #logger.debug('login_add login')
           return HttpResponseRedirect('/')

   form = LoginForm()
   return render(request, 'login.html', {'form': form,})
Example #18
0
def login_page(request):

    if request.method == "POST":

        form = 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 is not None:

                if user.is_active:

                    login(request, user)

                    return HttpResponseRedirect("/")

                    # Redirect to a success page.

                #else:

                    # Return a 'disabled account' error message

            #else:

                # Return an 'invalid login' error message.

    if request.method == "GET":

        form = LoginForm()

        return render(request, 'login.html', {

            'title': 'Aut-n',

            'form': form,

            'button-text': 'Enter',

        })
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_authenticated:
                    login(request, user)
            else:
                form.add_error(
                    None,
                    "Login Failed! Enter the username and password correctly!")
                return render(request, 'qa/login.html', {
                    'form': form,
                })
            if request.POST.get('next', '/').strip() != "":
                return redirect(request.POST.get('next', '/'))
            else:
                return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'qa/login.html', {
        'form': form,
    })
Example #20
0
def login_add(request):
   #logger.debug(request)
   error = ''
   if request.method == 'POST': 
     #logger.debug('login_add:' + request.method)
     form = LoginForm(request.POST)
     url = request.POST.get('continue', '/')
     sessid = do_login(form.login, form.password)
     if sessid:
         user = form.save()
         if user is not None:
           logout(request)
           login(request,user)
           #logger.debug('login_add login')
           return HttpResponseRedirect('/')

   form = LoginForm()
   return render(request, 'login.html', {'form': form,})
Example #21
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            print(username, password)
            user = authenticate(username=username, password=password)
            print(type(user))
            if user is not None:
                if user.is_active:
                    login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form,
                                          'user': request.user,
                                          'session': request.session, })
Example #22
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            print(username, password)
            user = authenticate(username=username, password=password)
            print(type(user))
            if user is not None:
                if user.is_active:
                    login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form,
                                          'user': request.user,
                                          'session': request.session, })
Example #23
0
def mylogin(request):
    message = ''
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')
            else:
                message = 'username or password are incorrect'
    else:
        form = LoginForm()
    return render(request, 'qa/login.html',{
        'form': form,
        'message':message,
    })
Example #24
0
def loginAsk(request, *args, **kwargs):
    if request.method == 'POST':
       form = LoginForm(request.POST)
       if form.is_valid():
          cleaned_data = form.clean()
          user = authenticate(username=cleaned_data['username'],\
                              password = cleaned_data['password'])
          login(request, user)
         # user = form.logIn() 
          url = '/'
          return HttpResponseRedirect(url)
    else:
       form = LoginForm()

    return render ( request,
                    'qa/LoginForm.html',
                    {   
                    'form': form,
                    })
Example #25
0
def login(request) :
	if request.method == "POST" :
		form = LoginForm(request.POST)
		if form.is_valid() :
			form.set_password(request.POST.get("password"))
			user = form.loginUser(request)
			return HttpResponseRedirect("/")
	else :
		form = LoginForm()
	return render(request, 'ask_add.html', {
		'form' : form,
	})
Example #26
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            logger.debug('authenticating name / password: %s / %s', username, password)
            user = authenticate(username=username, password=password)
            logger.debug('authenticated user %s', user)
            if user:
                auth_login(request, user)
                request.session.set_test_cookie()
                request.session['sessionid'] = request.session[SESSION_KEY]
            return HttpResponseRedirect(reverse('main_page'))
    else:
        form = LoginForm()
        return render(request, 
                      'qa/login.html', 
                      {'form': form})
Example #27
0
def loginview(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
        error = "Bad login or password"

    return render(request, 'login.html', {
        'form': form,
        'user': request.user,
        'session': request.session
    })
Example #28
0
def login_(request):
    if request.method == 'POST':
        user = authenticate(
            username=request.POST['username'],
            password=request.POST['password'],
        )
        if user is not None:
            login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #29
0
def login_page(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            print(request.GET)
            if 'next' in request.GET:
                url = request.GET['next']
            else:
                url = reverse('home')
            print(url)
            return HttpResponseRedirect(url)
    else:
        form = LoginForm()

    if 'success' in request.GET:
        text = request.GET['success']
        return render(request, 'login.html',
                      mixin({
                          'form': form,
                          'text': text,
                      }))

    if 'next' in request.GET:
        return render(request, 'login.html',
                      mixin({
                          'form': form,
                          'next': request.GET['next']
                      }))

    return render(request, 'login.html', mixin({'form': form}))
Example #30
0
def user_login(request, *args, **kwargs):
    error = ''  # Error msg - "Incorrect username or password.".
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid() == True:
            my_login = form.save()
            username = my_login['uname']
            password = my_login['upass']
            url = '/'
            user = authenticate(username=username, password=password)
            if user != None:
                login(request, user)
                print('User %s is login.' % username)
                response = HttpResponseRedirect(url)
                return response
            error = 'Incorrect username or password.'
            print('Incorrect username or password for user=%s' % username)
            return render(request, 'login.html', {
                'form': form,
                'error': error,
                'is_user': False,
            })
        else:
            return render(request, 'login.html', {
                'form': form,
                'error': error,
                'is_user': False,
            })
    else:
        form = LoginForm()
        return render(request, 'login.html', {
            'form': form,
            'error': error,
            'is_user': False,
        })
Example #31
0
def myLogin(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        form.is_valid()
        user = form.save()
        if user is not None:
            login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form})
Example #32
0
def user_login(request, *args, **kwargs):
    error = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            url = '/'
            sessionid = do_login(form.cleaned_data['username'], form.cleaned_data['password'])
            if sessionid:
                response = HttpResponseRedirect(url)
                response.set_cookie('sessionid', sessionid,
                    domain='127.0.0.1', path='/', httponly=True,
                    expires=datetime.now()+timedelta(days=5)
                    )
                return response
            else:
                error = u'Incorrect login/password'
    else:
        form = LoginForm()
    return render(request, 'qa/login.html', {
        'error': error,
        'form': form,
        })
Example #33
0
def user_login(request):
    error = ''
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = check_login(username, password)
        url = request.POST.get('continue', '/')
        if user is not None:
            login(request, user)
            return HttpResponseRedirect(url)
        else:
            error = u'Неверный логин / пароль'
        
    return render(request, 'qa/login.html', {'form': LoginForm(), 'error': error })
Example #34
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.load()
            auth.login(request, user)
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', { 'form': form })
Example #35
0
def question_add(request):
    user = request.user
    if user.is_authenticated():
        if request.method == 'POST':
            form = AskForm(request.POST)
            form._user = request.user
            if form.is_valid():
                question = form.save()
                url = question.get_url()
                return HttpResponseRedirect(url)
        else:
            form = AskForm()
        return render(request, 'question_add.html', {'form': form})
    else:
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
Example #36
0
def user_login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            if user is not None:
                login(request, user)
                return HttpResponseRedirect('/')
    form = LoginForm()
    context = {'form': form}
    return render(request, 'login.html', context)
Example #37
0
def login(request, *args, **kwargs):
    if request.method == 'POST':
        login = request.POST.get('username')
        password = request.POST.get('password')
        sessionid = do_login(login, password)
        if sessionid:
            response = HttpResponseRedirect('/')
            response.set_cookie(
                'sessionid',
                sessionid,
            )
            return response
        else:
            error = 'Wrong login/password'
    error = None
    form = LoginForm()
    return render(request, 'login.html', {'form': form, 'error': error})
def login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            form.set_password(request.POST.get("password"))
            user = form.loginUser(request)
            return HttpResponseRedirect("/")
    else:
        form = LoginForm()
    return render(request, 'ask_add.html', {
        'form': form,
    })
Example #39
0
def login(request):
    error = ''
    if request.method == 'POST':
        login = request.POST.get('username')
        password = request.POST.get('password')
        url = '/'
        sessid = do_login(login, password)
        if sessid:
            response = HttpResponseRedirect(url)
            response.set_cookie('sessionid', sessid,
                    httponly=True,
                    expires=datetime.now()+timedelta(days=5)
                    )
            return response 
        else:
            error = 'Wrong login/password'
    form = LoginForm()
    return render(request, 'qa/login.html', {'error': error, 'form': form})
Example #40
0
def login(request):
    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']
        #form = LoginForm(request.POST)
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request,user)
            print("AUTH OK")
            return HttpResponseRedirect('/')
        else:
            print("AUTH NOT OK")
            return HttpResponseRedirect('/')
    else:
        form = LoginForm()
    return render(request, 'login.html', {
        'form' : form,
        })
Example #41
0
def login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            log_in(request, user)
            return HttpResponseRedirect("/")
    else:
        form = LoginForm()
    return render(request, 'qa/login.html', {
        'form': form,
        'username': request.user.username
    })
Example #42
0
def login(request):
    error = ''
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        url = request.POST.get('continue', '/')
        sessionid = do_login(username, password)
        if sessionid:
            response = HttpResponseRedirect(url)
            response.set_cookie('sessionid', sessionid,
                                domain='.', httponly=True,
                                expires = datetime.now()+timedelta(days=5))
            return response
        else:
            error = u'Неверный логин / пароль'
    else:
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
    return render(request, 'login.html', {'error': error })
Example #43
0
def login(request):
    error = ''
    if request.method == 'POST':
        login = request.POST.get('username')
        password = request.POST.get('password')
        url = request.POST.get('continue', '/')
        sessid = do_login(login, password)
        if sessid:
            response = HttpResponseRedirect(url)
            response.set_cookie('sessionid', sessid)
            return response
        else:
            error = 'Bad login or password'
    else:
        form = LoginForm()
    return render(request, 'login.html', {
        'form': form,
        'error': error,
    })
Example #44
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save(request)
            if user != None:
                resp = HttpResponseRedirect('/')  #Replace to request.next
                return resp
    else:
        form = LoginForm()

    return render(request, 'login.html', {
        'form': form,
    })
Example #45
0
def login(request):
    error = None
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.login()
            if user is None:
                error = 'Wrong username or password'
            else:
                return HttpResponseRedirect('/')
    else:
        form = LoginForm()

    return render(request, 'login_template.html', {'form': form, 'error': error})
Example #46
0
def ask(request):
    user = request.user
    if user.is_authenticated():
        if request.method == "POST":
            form = AskForm(request.POST)
            form._user = request.user
            if form.is_valid():
                post = form.save()
                url = post.get_url()
                return HttpResponseRedirect(url)
        else:
            form = AskForm()
        return render(request, 'ask.html', {
            'form': form,
            'user': request.user,
        })

    else:
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
Example #47
0
def login_user(request):
    error = ''
    if request.method == 'POST':
        url = request.POST.get('continue', '/')
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            if user is not None and user.is_active:
                login(request, user)
                return HttpResponseRedirect(url)
        else:
            error = 'Incorrect username or password'
    else:
        form = LoginForm()
    return render(request, 'login.html', {'form': form, 'error': error})
Example #48
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            if user is not None:
                logout(request)
                login(request, user)
                return HttpResponseRedirect('/')
    form = LoginForm()
    return render(request, 'login.html', {
        'form': form,
        'user': request.user,
        'session': request.session,
    })
Example #49
0
def loginView(request, *args, **kwargs):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect('/')
                form = LoginForm()
                form.non_field_errors = ['Пользователь заблокирован']
            else:
                form = LoginForm()
                form.non_field_errors = ['Неверные учетные данные']
    else:
        form = LoginForm()

    return render(request, 'login-signup-template.html', {'form': form, 'title': 'Login', 'signup': False})