CARGA
CARGA
This commit is contained in:
0
autenticacion/__init__.py
Normal file
0
autenticacion/__init__.py
Normal file
BIN
autenticacion/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
autenticacion/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
autenticacion/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
autenticacion/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
autenticacion/__pycache__/forms.cpython-310.pyc
Normal file
BIN
autenticacion/__pycache__/forms.cpython-310.pyc
Normal file
Binary file not shown.
BIN
autenticacion/__pycache__/forms.cpython-39.pyc
Normal file
BIN
autenticacion/__pycache__/forms.cpython-39.pyc
Normal file
Binary file not shown.
BIN
autenticacion/__pycache__/views.cpython-310.pyc
Normal file
BIN
autenticacion/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
autenticacion/__pycache__/views.cpython-39.pyc
Normal file
BIN
autenticacion/__pycache__/views.cpython-39.pyc
Normal file
Binary file not shown.
3
autenticacion/admin.py
Normal file
3
autenticacion/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
autenticacion/apps.py
Normal file
5
autenticacion/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AutenticacionConfig(AppConfig):
|
||||
name = 'autenticacion'
|
||||
16
autenticacion/forms.py
Normal file
16
autenticacion/forms.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
|
||||
class UserForm(UserCreationForm):
|
||||
first_name = forms.CharField()
|
||||
last_name = forms.CharField()
|
||||
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name','last_name', 'username', 'password1' ,'password2' )
|
||||
|
||||
|
||||
|
||||
|
||||
0
autenticacion/migrations/__init__.py
Normal file
0
autenticacion/migrations/__init__.py
Normal file
3
autenticacion/models.py
Normal file
3
autenticacion/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
autenticacion/tests.py
Normal file
3
autenticacion/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
76
autenticacion/views.py
Normal file
76
autenticacion/views.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.views.generic import View
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import login, logout, authenticate
|
||||
from .forms import UserForm
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
|
||||
def acceder(request):
|
||||
if request.method == "POST":
|
||||
form = AuthenticationForm(request, data=request.POST)
|
||||
if form.is_valid():
|
||||
nombre_usuario = form.cleaned_data.get("username")
|
||||
password = form.cleaned_data.get("password")
|
||||
usuario = authenticate(username=nombre_usuario, password=password)
|
||||
if usuario is not None:
|
||||
login(request, usuario)
|
||||
messages.success(request, F"Bienvenid@ de nuevo {nombre_usuario}")
|
||||
return redirect("index")
|
||||
else:
|
||||
messages.error(request, "Los datos son incorrectos")
|
||||
else:
|
||||
messages.error(request, "Los datos son incorrectos")
|
||||
|
||||
form = AuthenticationForm()
|
||||
return render(request, "acceder.html", {"form": form})
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class VistaRegistro(View):
|
||||
def get(self, request):
|
||||
form = UserForm()
|
||||
return render(request, "registro.html", {"form": form})
|
||||
|
||||
|
||||
def post(self, request):
|
||||
form = UserForm(request.POST)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.save()
|
||||
return redirect("usuarios")
|
||||
else:
|
||||
for field, items in form.errors.items():
|
||||
for item in items:
|
||||
messages.error(request, '{}: {}'.format(field, item))
|
||||
return render(request, "registro.html", {"form": form})
|
||||
|
||||
|
||||
|
||||
def salir(request):
|
||||
logout(request)
|
||||
messages.success(request, F"Tu sesion se ha cerrado correctamente")
|
||||
return redirect("index")
|
||||
|
||||
|
||||
def usuarios(request):
|
||||
datos = User.objects.all()
|
||||
return render(request, 'usuarios.html', {"datos": datos})
|
||||
|
||||
|
||||
@login_required(login_url='/acceder')
|
||||
def userupdate(request, id):
|
||||
instance= get_object_or_404(User, pk=id)
|
||||
form = UserForm(request.POST or None, instance=instance)
|
||||
context= {'form': form}
|
||||
if form.is_valid():
|
||||
obj= form.save(commit= False)
|
||||
obj.save()
|
||||
messages.success(request, "El usuario fue actualizado")
|
||||
return redirect("usuarios")
|
||||
|
||||
else:
|
||||
context= {'form': form, 'error': 'Error al actualizar'}
|
||||
return render(request,'usuariosupdate.html' , context)
|
||||
Reference in New Issue
Block a user