Skip to content
Snippets Groups Projects
Commit cb05cace authored by Milo Hivert's avatar Milo Hivert
Browse files

ajout test commande

parents d6251e37 ee17f2fa
No related branches found
No related tags found
No related merge requests found
Showing
with 110 additions and 109 deletions
No preview for this file type
......@@ -23,74 +23,3 @@ class commande_crepe(models.Model):
livreur = models.ForeignKey(utilisateur, on_delete=models.CASCADE, related_name='commanditaire', blank=True, null=True)
date = models.DateTimeField(auto_now_add=True)
\ No newline at end of file
# class clé(models.Model):
# nom=models.CharField(max_length=300)
# value=models.CharField(max_length=300)
#from django.contrib.auth.models import AbstractUser
# class User(AbstractUser):
# rien = 'pas_cotisant'
# cotisant = 'cotisant'
# vip = 'vip'
# stepgif = 'stepgif'
# ROLE_CHOICES = (
# (rien, 'pas_cotisant'),
# (cotisant, 'cotisant'),
# (vip, 'vip'),
# (stepgif, 'stepgif'),
# )
# role = models.CharField(max_length=30,choices=ROLE_CHOICES)
# # id viarezo ?
# class Commande_crepe(models.Model):
# # la personne qui commande
# pour_qui = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='commanditaire_crepe')
# adresse_livraison = models.CharField(max_length=300)
# # état de la commande
# qui_s_en_charge = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='esclave_crepe')
# a_prendre_en_charge = 'a prendre en charge'
# en_cours = 'cotisant'
# finie = 'finie'
# ETAT_CHOICES = (
# (a_prendre_en_charge, 'a prendre en charge'),
# (en_cours, 'cotisant'),
# (finie, 'finie'),
# )
# etat = models.CharField(max_length=30,choices=ETAT_CHOICES, blank=True,null=True)
# # quelle commande : type de crêpes
# crepe_nature = models.IntegerField(blank=True)
# crepe_sucre = models.IntegerField(blank=True)
# crepe_nutella = models.IntegerField(blank=True)
# crepe_confiture = models.IntegerField(blank=True)
# class Type_hotline_vip(models.Model):
# nom = models.CharField(max_length=300)
# # descriptions ?
# class Commande_vip(models.Model):
# # la personne qui commande
# pour_qui = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='commanditaire_vip')
# adresse_livraison = models.CharField(max_length=300)
# # état de la commande
# qui_s_en_charge = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='esclave_vip')
# a_prendre_en_charge = 'a prendre en charge'
# en_cours = 'cotisant'
# finie = 'finie'
# ETAT_CHOICES = (
# (a_prendre_en_charge, 'a prendre en charge'),
# (en_cours, 'cotisant'),
# (finie, 'finie'),
# )
# etat = models.CharField(max_length=30,choices=ETAT_CHOICES)
# # type de commande
# type = models.ForeignKey(Type_hotline_vip, on_delete=models.CASCADE, blank=True,null=True)
var commander = document.getElementById("bouton_crepes");
var bouton_nature = document.getElementById("nature");
......@@ -8,7 +7,11 @@ var bouton_confiture = document.getElementById("confiture");
var bouton_adresse = document.getElementById("adresse")
bloc = document.getElementById("commande_crepe");
messageof = true
var messageof_zero = true
var messageof_trop = true
var messageof_adresse = true
var messageof_string = true
function f (){
var nature = bouton_nature.value;
......@@ -16,15 +19,42 @@ function f (){
var sucre = bouton_sucre.value;
var confiture = bouton_confiture.value;
var adresse = bouton_adresse.value;
if (parseInt(nature)+parseInt(sucre)+parseInt(nutella)+parseInt(confiture) !== 0 && adresse!==""){
window.location = "https://astegifetobegif.cs-campus.fr/mes_commandes/"+nature+"_"+nutella+"_"+sucre+"_"+confiture+"_"
console.log(parseInt(nature))
if ((typeof(nature)!=BigInt || typeof(sucre)!=BigInt || typeof(confiture)!=BigInt || typeof(nutella)!=BigInt) && messageof_string){
var paraph = document.createElement("p");
var texte = document.createTextNode("Le nombre de crêpes doit être entier.");
paraph.appendChild(texte);
bloc.appendChild(paraph);
messageof_string=false;
}
else if (messageof) {
else{
somme=parseInt(nature)+parseInt(nutella)+parseInt(sucre)+parseInt(confiture)
if (somme <= 0 && messageof_zero ){
var paraph = document.createElement("p");
var texte = document.createTextNode("Vous devez choisir au moins une crêpe pour passer une commande.");
paraph.appendChild(texte);
bloc.appendChild(paraph);
messageof_zero=false;
}
if (somme > 40 && messageof_trop){
var paraph = document.createElement("p");
var texte = document.createTextNode("Vous ne pouvez pas commander plus de 40 crêpes d'un coup.");
paraph.appendChild(texte);
bloc.appendChild(paraph);
messageof_trop=false;
}
if (adresse==="" && messageof_adresse) {
var paraph = document.createElement("p");
var texte = document.createTextNode("Vouz devez avoir rentré une adresse et choisi au moins une crêpe pour passer une commande.");
paraph.appendChild(texte);
bloc.appendChild(paraph);
messageof=false;
messageof_adresse=false;
}
if (adresse!=="" && somme >0 && somme <= 40 ){
window.location = "http://localhost:8000/mes_commandes/"+nature+"_"+nutella+"_"+sucre+"_"+confiture+"_"+adresse+"_";
}
}
}
commander.addEventListener("click", f);
......@@ -8,9 +8,11 @@
{% block content %}
<div class="commandes">
TOUTES LES COMMANDES NON PRISES EN CHARGE
VIP
{% for commande in commandes %}
<div class="une_commande">
{% if commande.statut == 'a traiter'%}
{% if commande.statut == 'a traiter' and commande.commanditaire.role != "cotisant" %}
Commanditaire:{{commande.commanditaire}}
Adresse de Livraison:{{commande.adresse_livraison}}
Commandée le:{{commande.date}}
......@@ -30,33 +32,30 @@
{% endif %}
</div>
{%endfor%}
<div>
<div class="mes_commandes">
TOUTES MES LIVRAISONS
COTISANTS
{% for commande in commandes %}
<div class="une_commande">
{% if commande.statut != 'close' and commande.livreur.email == email %}
{% if commande.statut == 'a traiter'%}
Commanditaire:{{commande.commanditaire}}
Statut:{{commande.statut}}
Adresse de Livraison:{{commande.adresse_livraison}}
Commandée le:{{commande.date}}
Commandée le {{commande.date.day}}/{{commande.date.month}} à {{ commande.date.hour}}:{{commande.date.minute}}
{% if commande.crepe_nature != 0 %}
Crêpes nature : {{commande.crepe_nature}}
{% endif %}
{% if commande.crepe_confiture != 0 %}
Crêpes nature : {{commande.crepe_confiture}}
Crêpes confiture : {{commande.crepe_confiture}}
{% endif %}
{% if commande.crepe_nutella != 0 %}
Crêpes nature : {{commande.crepe_nutella}}
Crêpes nutella : {{commande.crepe_nutella}}
{% endif %}
{% if commande.crepe_sucre != 0 %}
Crêpes nature : {{commande.crepe_sucre}}
Crêpes sucre : {{commande.crepe_sucre}}
{% endif %}
{% comment %} <a class="clore" href="../clore/{{commande.pk}}">Clore la commande</a> {% endcomment %}
<a class="clore" href="{% url 'clore' pkrequete=commande.pk %}">Clore la commande</a>
<a class="prendre en charge" href="{% url 'prendre_en_charge' pkrequete=commande.pk %}"> Prendre en charge</a>
{% endif %}
</div>
{%endfor%}
<div>
{% endblock %}
\ No newline at end of file
......@@ -10,18 +10,18 @@
{% for commande in commandes %}
<div class="une_commande">
{% if commande.statut != "close" and commande.commanditaire.email == email %}
Vous avez commandé à {{commande.date}}:
Vous avez commandé le {{commande.date.day}}/{{commande.date.month}} à {{ commande.date.hour}}:{{commande.date.minute}}:
{% if commande.crepe_nature != 0 %}
Crêpes nature : {{commande.crepe_nature}}
{% endif %}
{% if commande.crepe_confiture != 0 %}
Crêpes nature : {{commande.crepe_confiture}}
Crêpes confiture : {{commande.crepe_confiture}}
{% endif %}
{% if commande.crepe_nutella != 0 %}
Crêpes nature : {{commande.crepe_nutella}}
Crêpes nutella : {{commande.crepe_nutella}}
{% endif %}
{% if commande.crepe_sucre != 0 %}
Crêpes nature : {{commande.crepe_sucre}}
Crêpes sucre : {{commande.crepe_sucre}}
{% endif %}
{% if commande.statut == "a traiter" %}
Votre commande n'est pas encore prise en charge
......
......@@ -13,7 +13,7 @@
{% if commande.statut != 'close' and commande.livreur.email == email %}
Commanditaire:{{commande.commanditaire}}
Adresse de Livraison:{{commande.adresse_livraison}}
Commandée le:{{commande.date}}
Commandée le {{commande.date.day}}/{{commande.date.month}} à {{ commande.date.hour}}:{{commande.date.minute}}
{% if commande.crepe_nature != 0 %}
Crêpes nature : {{commande.crepe_nature}}
{% endif %}
......
{% extends 'campagne/base.html'%}
{% load static %}
{% block cssEtTitre %}
<link rel="stylesheet" href="{% static 'campagne/css/hotline.css' %}" />
{% endblock %}
{% block content %}
<p>Vous devez patienter {{min}} min {{sec}} sec avant la prochaine commande.</p>
{% endblock %}
\ No newline at end of file
......@@ -11,7 +11,7 @@
{% if commande.statut == 'en cours' %}
Commanditaire:{{commande.commanditaire}}
Adresse de Livraison:{{commande.adresse_livraison}}
Commandée le:{{commande.date}}
Commandée le {{commande.date.day}}/{{commande.date.month}} à {{ commande.date.hour}}:{{commande.date.minute}}
{% if commande.crepe_nature != 0 %}
Crêpes nature : {{commande.crepe_nature}}
{% endif %}
......
......@@ -8,8 +8,25 @@ import requests
import json
# from cryptography.fernet import Fernet
from django.core.mail import send_mail
import datetime
encrypt={'A': 'b', 'B': '7', 'C': 'U', 'D': 'f', 'E': '_', 'F': 'A', 'G': '1', 'H': 'V', 'I': 'r', 'J': 'p', 'K': 'X', 'L': 'i', 'M': 'L', 'N': 'h', 'O': 'B', 'P': '8', 'Q': '2', 'R': 'W', 'S': 'l', 'T': '.', 'U': 'E', 'V': 'D', 'W': 'u', 'X': '-', 'Y': 't', 'Z': 'Y', 'a': 'O', 'b': 'G', 'c': 'Z', 'd': 'K', 'e': 'q', 'f': '9', 'g': 'T', 'h': 'S', 'i': 'M', 'j': 'Q', 'k': 'R', 'l': 'n', 'm': 'z', 'n': 'I', 'o': 's', 'p': 'k', 'q': 'o', 'r': 'y', 's': '/', 't': 'c', 'u': 'N', 'v': 'J', 'w': 'x', 'x': 'd', 'y': 'H', 'z': 'C', '0': '4', '1': '6', '2': '+', '3': 'j', '4': 'm', '5': 'w', '6': 'g', '7': 'e', '8': 'a', '9': '5', '+': 'P', '/': '3', '.': 'v', '-': 'F', '_': '0'}
decrypt={'b': 'A', '7': 'B', 'U': 'C', 'f': 'D', '_': 'E', 'A': 'F', '1': 'G', 'V': 'H', 'r': 'I', 'p': 'J', 'X': 'K', 'i': 'L', 'L': 'M', 'h': 'N', 'B': 'O', '8': 'P', '2': 'Q', 'W': 'R', 'l': 'S', '.': 'T', 'E': 'U', 'D': 'V', 'u': 'W', '-': 'X', 't': 'Y', 'Y': 'Z', 'O': 'a', 'G': 'b', 'Z': 'c', 'K': 'd', 'q': 'e', '9': 'f', 'T': 'g', 'S': 'h', 'M': 'i', 'Q': 'j', 'R': 'k', 'n': 'l', 'z': 'm', 'I': 'n', 's': 'o', 'k': 'p', 'o': 'q', 'y': 'r', '/': 's', 'c': 't', 'N': 'u', 'J': 'v', 'x': 'w', 'd': 'x', 'H': 'y', 'C': 'z', '4': '0', '6': '1', '+': '2', 'j': '3', 'm': '4', 'w': '5', 'g': '6', 'e': '7', 'a': '8', '5': '9', 'P': '+', '3': '/', 'v': '.', 'F': '-', '0': '_'}
def encryptmess(message):
mess=""
for i in range(len(message)):
mess=mess+encrypt[message[i]]
return mess
def decryptmess(message):
mess=""
for i in range(len(message)):
mess=mess+decrypt[message[i]]
return mess
def connexion(request):
return HttpResponseRedirect('https://auth.viarezo.fr/oauth/authorize/?redirect_uri=https://astegifetobegif.cs-campus.fr/intermediaire&client_id=2fe828e15647fc92437727b6646ce5c799c40991&response_type=code&state=sqdkfjhsqdkf&scope=default')
......@@ -31,7 +48,8 @@ def login(request): #on a le state et le authorization code dans le request
useer.prenom = r.json()['firstName']
useer.nom=r.json()['lastName']
useer.save()
reponse.set_cookie("token",access_token, secure=True)
token_crypté=encryptmess(access_token)
reponse.set_cookie("token",token_crypté, secure=True)
return reponse
def accueil(request):
......@@ -62,17 +80,31 @@ def hotline(request):
test[1])
return redirect(connexion)
def date_to_second(date):
return 24*3600*int(date.day)+3600*int(date.hour)+60*int(date.minute)+int(date.second)
def commande_passee(request, requete):
L = requete.split('_')
token=request.COOKIES.get('token')
token_crypté=request.COOKIES.get('token')
token=decryptmess(token_crypté)
r = requests.get("https://auth.viarezo.fr/api/user/show/me", headers={"Authorization" : "Bearer "+token})
mail = r.json()['email']
last_command_user=commande_crepe.objects.filter(commanditaire=utilisateur.objects.get(email=mail)).last()
date_derniere_commande=last_command_user.date
date_mtn = datetime.datetime.now()
last_command_second = date_to_second(date_derniere_commande)
mtn_second = date_to_second(date_mtn)
durée_dernière_commande=mtn_second-last_command_second
temps_entre_commandes=60*10
if durée_dernière_commande <= temps_entre_commandes:
patiente=temps_entre_commandes-durée_dernière_commande
return render(request,"campagne/patiente.html",{"min":patiente//60, "sec":patiente%60})
commande=commande_crepe.objects.create(adresse_livraison=L[4], crepe_nature=L[0], crepe_nutella=L[1], crepe_sucre=L[2], crepe_confiture=L[3],commanditaire=utilisateur.objects.get(email=mail))
commande.save()
send_mail('commande crêpes',
'commande de {{commande.commanditaire}} de {{commande.crepe_nature}} crêpes natures, de {{commande.crepe_sucre}} crêpes sucres, de {{commande.crepe_confiture}} crêpes confiture et de {{commande.crepe_nutella}} crêpes nutella',
'stepgifimstuck@gmail.com',
['stepgifimstuck@gmail.com'])
#send_mail('commande crêpes',
# 'commande de {{commande.commanditaire}} de {{commande.crepe_nature}} crêpes natures, de {{commande.crepe_sucre}} crêpes sucres, de {{commande.crepe_confiture}} crêpes confiture et de {{commande.crepe_nutella}} crêpes nutella',
# 'stepgifimstuck@gmail.com',
# ['stepgifimstuck@gmail.com'])
return redirect(mes_commandes)
def mes_commandes(request):
......@@ -117,7 +149,7 @@ def clore(request, pkrequete):
commande=commande_crepe.objects.get(pk=pkrequete)
commande.statut="close"
commande.save()
return redirect(mes_commandes)
return redirect(mes_livraisons)
return HttpResponse("Vous n'avez pas les autorisations requises pour accéder à cette page")
......@@ -127,7 +159,8 @@ def vip(request):
def check(request):
if request.COOKIES.get('token'):
token=request.COOKIES.get('token')
token_crypté=request.COOKIES.get('token')
token=decryptmess(token_crypté)
r = requests.get("https://auth.viarezo.fr/api/user/show/me", headers={"Authorization" : "Bearer "+token})
mail = r.json()['email']
role=utilisateur.objects.get(email=mail)
......
File added
No preview for this file type
......@@ -110,11 +110,11 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment