From 79bb411d384e721377c176d252847e5bd8312617 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Mon, 2 May 2016 12:05:06 +0200 Subject: [PATCH] Possibilité de se connecter --- api/.htaccess | 2 +- index.html | 2 +- js/init.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/api/.htaccess b/api/.htaccess index 32a7a28..e385f2d 100644 --- a/api/.htaccess +++ b/api/.htaccess @@ -9,7 +9,7 @@ ErrorDocument 500 '{"status":"erreur_interne"}\n' ErrorDocument 503 '{"status":"service_indisponible"}\n' RewriteEngine On -RewriteBase /api/ +RewriteBase /~geoffrey/10p5-server/api/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f diff --git a/index.html b/index.html index 0854e1f..7fa307e 100644 --- a/index.html +++ b/index.html @@ -42,7 +42,7 @@
- Se connecter + Se connecter
diff --git a/js/init.js b/js/init.js index a316b24..0b1c921 100644 --- a/js/init.js +++ b/js/init.js @@ -1,9 +1,63 @@ +// Constantes +var JETON_TAILLE = 30 // Taille d'un jeton +var JETON_DUREE = 10*60 // Temps de validité du jeton en secondes + +var TRANSACTION_CREATION = 1 +var TRANSACTION_RECHARGEMENT = 2 +var TRANSACTION_PAIEMENT = 3 +var TRANSACTION_VIDANGE = 4 + +var TRANSACTION_DUREE = 60 + +// Informations de connexion + +var login, droit, jeton, debut; + +// Fonctions pour Materialize $(function(){ $('.button-collapse').sideNav(); $('.modal-trigger').leanModal() - Materialize.toast("Connecté en tant que vigou", 4000); }); // end of document ready +// Fonctions communes + +function APIbrute(chemin, donnees, cb) { + var url = "api/" + chemin; + $.post(url, donnees, function(data) { + cb(data['status'], data); + }) + +} + +function toast(texte) { + Materialize.toast(texte, 4000); +} + +// Connexion +$("#connecter").click(function() { + var login = $("#login").val(); + var mdp = $("#mdp").val(); + APIbrute("utilisateur/connexion", {login: login , mdp: mdp} , function(retour, donnees) { + switch(retour) { + case "identifiants_invalides": + toast("Identifiants invalides") + break; + + case "ok": + login = donnees.login; + droit = donnees.droit; + jeton = donnees.jeton; + toast("Correctement identifié en tant que " + login + " pour 10 minutes") + break; + + default: + toast("Erreur interne"); + break; + } + }); +}); + +// Placeholder function vendu() { var interieur = $("").text("Vendu 1 bière à KAE1EET2YI (15,30 € → 13,50 €) ").append( $("").attr("href", "#!").text("Annuler") @@ -14,3 +68,4 @@ function vendu() { function soldeInsuffisant() { $("#soldeInsuffisant").openModal(); } + -- libgit2 0.21.2