Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from MaziniiX/main
Browse files Browse the repository at this point in the history
commit
  • Loading branch information
MaziniiX authored Jun 20, 2024
2 parents a1493cc + 9d2918a commit db08f85
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 106 deletions.
1 change: 0 additions & 1 deletion Django_Frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
mig
47 changes: 30 additions & 17 deletions Django_Frontend/monprojet/monapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,37 @@
from django import forms
from .models import Client, Staff, StaffType

class ClientForm(forms.Form):
username = forms.CharField(max_length=150)
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
is_staff = forms.BooleanField(required=False)
is_superuser = forms.BooleanField(required=False)
from django import forms
from django.contrib.auth.models import User
from .models import Client, Staff, StaffType

class ClientForm(forms.ModelForm):
class Meta:
model = Client
fields = '__all__'

class StaffForm(forms.ModelForm):
class Meta:
model = Staff
fields = '__all__'

class StaffForm(forms.Form):
username = forms.CharField(max_length=150)
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
is_staff = forms.BooleanField(required=False)
is_superuser = forms.BooleanField(required=False)
staff_type = forms.IntegerField()

class StaffTypeForm(forms.ModelForm):
class Meta:
model = StaffType
fields = ['type']
fields = '__all__'

class RegistrationForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)

class Meta:
model = User
fields = ['username', 'email', 'password']

def save(self, commit=True):
user = super(RegistrationForm, self).save(commit=False)
user.set_password(self.cleaned_data['password'])
if commit:
user.save()
client = Client(user=user)
client.save()
return user
59 changes: 59 additions & 0 deletions Django_Frontend/monprojet/monapp/static/monapp/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
body {
font-family: Arial, sans-serif;
background: #fff;
color: #000;
margin: 0;
padding: 0;
}

.header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #000;
padding: 10px 20px;
color: white;
position: relative;
}

.menu-button {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}

.menu-button:hover, .menu-button:focus {
background-color: #3e8e41;
}

.menu-content {
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.menu-content a {
display: none; /* Add this line to hide the menu by default */
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.menu-button:hover .menu-content, .menu-button:focus .menu-content {
display: block;
}

h1 {
color: white;
}

main {
color: black;
}
24 changes: 18 additions & 6 deletions Django_Frontend/monprojet/monapp/templates/monapp/base.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
<!-- base.html -->
{% load static %}
<!DOCTYPE html>
<html>
<head>
<!-- Metadonnées, CSS, JavaScript, etc. -->
<title>Mon Application</title>
<link rel="stylesheet" type="text/css" href="{% static 'monapp/styles.css' %}">
</head>
<body>
<header>
<!-- Ajoutez votre bouton de retour à la page d'accueil ici -->
<a href="{% url 'home' %}">Home</a>
<header class="header">
<nav>
<button class="menu-button">Menu</button>
<div class="menu-content">
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'create-client' %}">Create Client</a>
<a href="{% url 'create-staff' %}">Create Staff</a>
<a href="{% url 'create-staff-type' %}">Create Staff Type</a>
<a href="{% url 'view_clients' %}">View Clients</a>
<a href="{% url 'view_staff' %}">View Staff</a>
<a href="{% url 'view_staff_types' %}">View Staff Types</a>
<!-- Ajoutez d'autres liens ici selon vos besoins -->
</div>
</nav>
<h1>Mon Application</h1>
</header>

<main>
{% block content %}
<!-- Le contenu spécifique à chaque page sera inséré ici -->
Expand Down
23 changes: 4 additions & 19 deletions Django_Frontend/monprojet/monapp/templates/monapp/home.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<!-- home.html -->
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<!-- Vous pouvez ajouter ici vos propres liens CSS, scripts JavaScript, etc. -->
</head>
<body>
{% extends 'monapp/base.html' %}

{% block content %}
<h1>Welcome to the Home Page!</h1>
<!-- Ajoutez le reste de votre contenu ici -->
<ul>
<li><a href="{% url 'create-client' %}">Create Client</a></li>
<li><a href="{% url 'create-staff' %}">Create Staff</a></li>
<li><a href="{% url 'create-staff-type' %}">Create Staff Type</a></li>
<li><a href="{% url 'view_clients' %}">View Clients</a></li>
<li><a href="{% url 'view_staff' %}">View Staff</a></li>
<li><a href="{% url 'view_staff_types' %}">View Staff Types</a></li>
<!-- Ajoutez d'autres liens ici selon vos besoins -->
</ul>
</body>
</html>
{% endblock %}
16 changes: 16 additions & 0 deletions Django_Frontend/monprojet/monapp/templates/monapp/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'monapp/base.html' %}

{% block content %}
<h2>Login</h2>
{% if messages %}
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
{% endif %}
<form method="post">
{% csrf_token %}
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
{% endblock %}
10 changes: 10 additions & 0 deletions Django_Frontend/monprojet/monapp/templates/monapp/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'monapp/base.html' %}

{% block content %}
<h1>Register a new client account</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Register</button>
</form>
{% endblock %}
4 changes: 3 additions & 1 deletion Django_Frontend/monprojet/monapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
path('', views.home, name='home'),
path('create-client/', views.client_create_view, name='create-client'),
path('create-staff/', views.staff_create_view, name='create-staff'),
path('create-staff-type/', views.create_staff_type, name='create-staff-type'),
path('create-staff-type/', views.staff_type_create_view, name='create-staff-type'),
path('register/', views.register, name='register'),
path('login/', views.login, name='login'),
path('success/', views.success, name='success'),
path('view_staff/', views.view_staff, name='view_staff'),
path('view_clients/', views.view_clients, name='view_clients'),
Expand Down
100 changes: 52 additions & 48 deletions Django_Frontend/monprojet/monapp/views.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,39 @@
from django.http import HttpRequest
import requests
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.models import User
from .forms import ClientForm, StaffForm, StaffTypeForm
from .forms import ClientForm, StaffForm, StaffTypeForm, RegistrationForm
from .models import Staff, Client, StaffType
from django.http import HttpRequest

# Create your views here.

api_url = 'http://localhost:8020/api/'
def get_api_url(request: HttpRequest) -> str:
host = request.get_host()
protocol = 'https://' if request.is_secure() else 'http://'
api_url = f'{protocol}api.{host}/'
return api_url

def client_create_view(request):
if request.method == 'POST':
form = ClientForm(request.POST)
if form.is_valid():
data = form.cleaned_data
user = User.objects.create_user(
username=data['username'],
email=data['email'],
password=data['password'],
first_name=data['first_name'],
last_name=data['last_name'],
is_staff=data['is_staff'],
is_superuser=data['is_superuser']
)
user.save()
messages.success(request, 'Client created successfully')
return redirect('success')
else:
form = ClientForm()
form = ClientForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('home')
return render(request, 'monapp/create_client.html', {'form': form})

def staff_create_view(request):
if request.method == 'POST':
form = StaffForm(request.POST)
if form.is_valid():
data = form.cleaned_data
user = User.objects.create_user(
username=data['username'],
email=data['email'],
password=data['password'],
is_staff=data['is_staff'],
is_superuser=data['is_superuser']
)
user.staffprofile.staff_type = data['staff_type']
user.staffprofile.save()
user.save()
messages.success(request, 'Staff created successfully')
return redirect('success')
else:
form = StaffForm()
return render(request, 'monapp/create_staff.html', {'form': form})
form = StaffForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('home')
return render(request, 'monapp/create_staff.html', {'form': form})

def create_staff_type(request):
if request.method == 'POST':
form = StaffTypeForm(request.POST)
if form.is_valid():
form.save()
return redirect('home')
else:
form = StaffTypeForm()
def staff_type_create_view(request):
form = StaffTypeForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('home')
return render(request, 'monapp/create_staff_type.html', {'form': form})

def view_staff(request):
Expand All @@ -77,4 +52,33 @@ def success(request):
return render(request, 'monapp/success.html')

def home(request):
return render(request, 'monapp/home.html')
return render(request, 'monapp/home.html')

def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
return redirect('login')
else:
form = RegistrationForm()
return render(request, 'monapp/register.html', {'form': form})

def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']

response = requests.post('http://your-api-url/login/', data={
'username': username,
'password': password,
})

if response.status_code == 200:
# Login successful, redirect to home page
return redirect('home')
else:
# Login failed, show error message
messages.error(request, 'Login failed. Please check your username and password.')

return render(request, 'monapp/login.html')
Loading

0 comments on commit db08f85

Please sign in to comment.