authentication works, navbar to adjust, models started not done
This commit is contained in:
14
LITReview/authentication/forms.py
Normal file
14
LITReview/authentication/forms.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(max_length=63, label='Nom d’utilisateur')
|
||||
password = forms.CharField(max_length=63, widget=forms.PasswordInput, label='Mot de passe')
|
||||
|
||||
class RegisterForm(UserCreationForm):
|
||||
class Meta(UserCreationForm.Meta):
|
||||
model = get_user_model()
|
||||
fields = ('username',)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.2 on 2025-04-18 13:34
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='user',
|
||||
name='account_id',
|
||||
),
|
||||
]
|
||||
@@ -3,5 +3,4 @@ from django.contrib.auth.models import AbstractUser
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
account_id = models.CharField(max_length=10, unique=True)
|
||||
|
||||
pass
|
||||
|
||||
41
LITReview/authentication/templates/authentication/login.html
Normal file
41
LITReview/authentication/templates/authentication/login.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container" style="height: 100vh">
|
||||
<div class="row h-100 align-items-center">
|
||||
<div class="col d-flex align-items-center justify-content-center">
|
||||
|
||||
<div class="justify-content-center">
|
||||
<div class="align-self-center">
|
||||
<h2>Inscrivez-vous</h2>
|
||||
</div>
|
||||
|
||||
<div class="justify-content-end">
|
||||
<a href="{% url 'register' %}" type="button" class="btn btn-primary">S'inscrire</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col d-flex align-items-center justify-content-center">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h2>Connectez-vous</h2>
|
||||
<form method='post'>
|
||||
{% csrf_token %}
|
||||
<div class="form-group p-3">
|
||||
{{ form.username }}
|
||||
</div>
|
||||
<div class="form-group p-3">
|
||||
{{ form.password }}
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary self-align-right">Se connecter</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,22 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row justify-content-center mt-10">
|
||||
<div class="col text-center">
|
||||
<h2>Inscrivez-vous</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-3 d-flex align-items-end">
|
||||
<a href="{% url 'login' %}" class="btn btn-primary">Retourner</a>
|
||||
</div>
|
||||
<div class="col-3 d-flex align-items-end">
|
||||
<form method='post'>
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="btn btn-primary">S'inscrire</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,3 +1,40 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth import login, logout, authenticate
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
from authentication.forms import LoginForm, RegisterForm
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def login_page(request):
|
||||
form = LoginForm()
|
||||
message = ""
|
||||
|
||||
if request.method == 'POST':
|
||||
form = LoginForm(request.POST)
|
||||
if form.is_valid():
|
||||
user = authenticate(
|
||||
username=form.cleaned_data['username'],
|
||||
password=form.cleaned_data['password'],
|
||||
)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return redirect('home')
|
||||
else:
|
||||
message = "Identifiants invalides"
|
||||
|
||||
print(request.POST)
|
||||
|
||||
return render(request,
|
||||
'authentication/login.html',
|
||||
{'form': form})
|
||||
|
||||
|
||||
def register_page(request):
|
||||
form = RegisterForm()
|
||||
if request.method == 'POST':
|
||||
form = RegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
user = form.save()
|
||||
login(request, user)
|
||||
return redirect(settings.LOGIN_REDIRECT_URL)
|
||||
return render(request, 'authentication/register.html', {'form': form})
|
||||
|
||||
Reference in New Issue
Block a user