示例#1
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,
        })
示例#2
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}))
示例#3
0
文件: views.py 项目: StealthyFox/web
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})
示例#4
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})
示例#5
0
文件: views.py 项目: TiGRoNdev/web
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
    })
示例#6
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,
	})	
示例#7
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,
    })
示例#8
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,
        })
示例#9
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,
    })
示例#10
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})
示例#11
0
def login_form(request):
  if request.method == "POST":
    form = LoginForm(request.POST)
    if form.is_valid():
      user = form.save()
      if user is not None:
        if user.is_active:
          login(request, user)
          return HttpResponseRedirect('/')
  else:
    form = LoginForm()
  return render(request, 'loginform.html', {
    'form': form,
    'path': request.path,
  })
示例#12
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
    })
示例#13
0
def do_login(request):
    error = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = form.save()
            if user is not None:
                login(request, user)
                response = HttpResponseRedirect('/')
                # response.set_cookie('sessionid', key, path='/', expires=datetime.now()+timedelta(days=5))
                return response
            else:
                error = user
        else:
            error = 'Form not valid'
    form = LoginForm()
    return render(request, 'qa/login.html', {'form': form, 'error': error})
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,})
示例#15
0
文件: views.py 项目: patuh9090/stepic
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,})
示例#16
0
def user_login(request):
    """With a GET request, a form for entering data should be displayed, with a POST request,
    a login is made to the site, the redirect to the main page is returned. 
    The user should receive an authorization cookie named sessionid.

    """
    form = LoginForm(request.POST)
    if request.method == 'POST' and 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,
    })
示例#17
0
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,
    })
示例#18
0
def login_page(request, *args, **kwargs):
    error = ''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username, password = form.save()
            user = authenticate(username=username, password=password)
            logger.debug('user: {}'.format(user))
            if user is not None:
                login(request, user)
                response = HttpResponseRedirect('/')
                response.set_cookie('sessid',
                                    request.session.session_key,
                                    expires=dt.datetime.now() +
                                    dt.timedelta(days=5))
                return response
            else:
                error = u'Wrong password or username'
    form = LoginForm()
    return render(request, 'login.html', {'error': error, 'form': form})