Ejemplo n.º 1
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['login'], password=form.cleaned_data['password'])    
            if user:
                if user.is_active:
                    login(request, user)        
            else:
                pass        
    return redirect('/')
def login_view(request):
    if request.user.is_authenticated():
        return redirect('mainsite:main')    
    
    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        # Checks if form is filled in correctly
        if form.is_valid():
            user = form.login(request)
            if user:
                login(request, user)
                # Updates lease status on login
                services.update_lease_status(user)
                return redirect('mainsite:main')
    else:
        form = LoginForm()
        
    return render(request, 'registration/login.html', {
        'form': form
    })