Commit 79bb411d384e721377c176d252847e5bd8312617
1 parent
3c5e66e0
Possibilité de se connecter
Showing
3 changed files
with
58 additions
and
3 deletions
Show diff stats
api/.htaccess
@@ -9,7 +9,7 @@ ErrorDocument 500 '{"status":"erreur_interne"}\n' | @@ -9,7 +9,7 @@ ErrorDocument 500 '{"status":"erreur_interne"}\n' | ||
9 | ErrorDocument 503 '{"status":"service_indisponible"}\n' | 9 | ErrorDocument 503 '{"status":"service_indisponible"}\n' |
10 | 10 | ||
11 | RewriteEngine On | 11 | RewriteEngine On |
12 | -RewriteBase /api/ | 12 | +RewriteBase /~geoffrey/10p5-server/api/ |
13 | 13 | ||
14 | RewriteCond %{REQUEST_FILENAME} !-d | 14 | RewriteCond %{REQUEST_FILENAME} !-d |
15 | RewriteCond %{REQUEST_FILENAME}\.php -f | 15 | RewriteCond %{REQUEST_FILENAME}\.php -f |
index.html
@@ -42,7 +42,7 @@ | @@ -42,7 +42,7 @@ | ||
42 | </div> | 42 | </div> |
43 | </div> | 43 | </div> |
44 | <div class="row"> | 44 | <div class="row"> |
45 | - <a href="main.php" id="connecter" class="btn-large waves-effect waves-light">Se connecter</a> | 45 | + <a href="#!" id="connecter" class="btn-large waves-effect waves-light">Se connecter</a> |
46 | </div> | 46 | </div> |
47 | </form> | 47 | </form> |
48 | </div> | 48 | </div> |
js/init.js
1 | +// Constantes | ||
2 | +var JETON_TAILLE = 30 // Taille d'un jeton | ||
3 | +var JETON_DUREE = 10*60 // Temps de validité du jeton en secondes | ||
4 | + | ||
5 | +var TRANSACTION_CREATION = 1 | ||
6 | +var TRANSACTION_RECHARGEMENT = 2 | ||
7 | +var TRANSACTION_PAIEMENT = 3 | ||
8 | +var TRANSACTION_VIDANGE = 4 | ||
9 | + | ||
10 | +var TRANSACTION_DUREE = 60 | ||
11 | + | ||
12 | +// Informations de connexion | ||
13 | + | ||
14 | +var login, droit, jeton, debut; | ||
15 | + | ||
16 | +// Fonctions pour Materialize | ||
1 | $(function(){ | 17 | $(function(){ |
2 | $('.button-collapse').sideNav(); | 18 | $('.button-collapse').sideNav(); |
3 | $('.modal-trigger').leanModal() | 19 | $('.modal-trigger').leanModal() |
4 | - Materialize.toast("Connecté en tant que vigou", 4000); | ||
5 | }); // end of document ready | 20 | }); // end of document ready |
6 | 21 | ||
22 | +// Fonctions communes | ||
23 | + | ||
24 | +function APIbrute(chemin, donnees, cb) { | ||
25 | + var url = "api/" + chemin; | ||
26 | + $.post(url, donnees, function(data) { | ||
27 | + cb(data['status'], data); | ||
28 | + }) | ||
29 | + | ||
30 | +} | ||
31 | + | ||
32 | +function toast(texte) { | ||
33 | + Materialize.toast(texte, 4000); | ||
34 | +} | ||
35 | + | ||
36 | +// Connexion | ||
37 | +$("#connecter").click(function() { | ||
38 | + var login = $("#login").val(); | ||
39 | + var mdp = $("#mdp").val(); | ||
40 | + APIbrute("utilisateur/connexion", {login: login , mdp: mdp} , function(retour, donnees) { | ||
41 | + switch(retour) { | ||
42 | + case "identifiants_invalides": | ||
43 | + toast("Identifiants invalides") | ||
44 | + break; | ||
45 | + | ||
46 | + case "ok": | ||
47 | + login = donnees.login; | ||
48 | + droit = donnees.droit; | ||
49 | + jeton = donnees.jeton; | ||
50 | + toast("Correctement identifié en tant que " + login + " pour 10 minutes") | ||
51 | + break; | ||
52 | + | ||
53 | + default: | ||
54 | + toast("Erreur interne"); | ||
55 | + break; | ||
56 | + } | ||
57 | + }); | ||
58 | +}); | ||
59 | + | ||
60 | +// Placeholder | ||
7 | function vendu() { | 61 | function vendu() { |
8 | var interieur = $("<span>").text("Vendu 1 bière à KAE1EET2YI (15,30 € → 13,50 €) ").append( | 62 | var interieur = $("<span>").text("Vendu 1 bière à KAE1EET2YI (15,30 € → 13,50 €) ").append( |
9 | $("<a>").attr("href", "#!").text("Annuler") | 63 | $("<a>").attr("href", "#!").text("Annuler") |
@@ -14,3 +68,4 @@ function vendu() { | @@ -14,3 +68,4 @@ function vendu() { | ||
14 | function soldeInsuffisant() { | 68 | function soldeInsuffisant() { |
15 | $("#soldeInsuffisant").openModal(); | 69 | $("#soldeInsuffisant").openModal(); |
16 | } | 70 | } |
71 | + |