-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
33 lines (31 loc) · 1.18 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404, get_list_or_404, redirect, render_to_response
def ingresar(request):
if request.user.is_authenticated():
return redirect('crm.views.index')
else:
if request.method == 'POST':
username = request.POST['usuario']
password = request.POST['contrasenia']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
if user.is_superuser:
return redirect('crm.views.index')
else:
#return redirect('login.views.indexUsuario')
return redirect('crm.views.index')
else:
return render(request, 'home/home.html', {'mensaje_error':"El usuario no se encuentra activo"})
else:
return render(request, 'home/home.html', {'mensaje_error':"Usuario y clave no coinciden"})
else:
return render(request, 'home/home.html')
def cerrarSesion(request):
logout(request)
return redirect('openshift.views.ingresar')