From fb983c3c062a3bbac20adc28801eafe0a9228b1c Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@gmail.com>
Date: Wed, 28 Feb 2018 10:54:19 +0100
Subject: [PATCH] Fixed auth

Updated templates
---
 config.json                |  2 +-
 src/css/style.css          |  1 +
 src/ldap_auth/ldap_auth.js | 23 ++++++++++++-----------
 src/server.js              |  3 +++
 src/views/home.pug         | 11 ++++++++---
 src/views/login.pug        |  6 +++---
 6 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/config.json b/config.json
index 83bf03f..cecc4e9 100644
--- a/config.json
+++ b/config.json
@@ -1,6 +1,6 @@
 {
 	"ldap": {
-		"server": "ldap://frankiz.eleves.polytechnique.fr:636",
+		"server": "ldap://frankiz.eleves.polytechnique.fr:389",
 		"searchBase": "ou=eleves,dc=frankiz,dc=net",
 		"searchFilter": "(uid={{username}})"
 	},
diff --git a/src/css/style.css b/src/css/style.css
index 6d221f4..4d2b77a 100644
--- a/src/css/style.css
+++ b/src/css/style.css
@@ -9,6 +9,7 @@ body {
 
 form {
     margin-bottom: 1em;
+    margin-top: 1em;
 }
 
 .form-group {
diff --git a/src/ldap_auth/ldap_auth.js b/src/ldap_auth/ldap_auth.js
index a9015f2..9fd2fea 100644
--- a/src/ldap_auth/ldap_auth.js
+++ b/src/ldap_auth/ldap_auth.js
@@ -1,24 +1,25 @@
 /**
  * @file ldap_auth
- * @summary Setup de l'auth ldap avec passport-ldapauth
+ * @summary Configuration de l'authentification LDAP du backend via passport-ldap
  */
-
 import passport from 'passport';
 import LdapStrategy from 'passport-ldapauth';
 import session from 'express-session';
 import fs from 'fs';
 
+let config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
+
+passport.use(new LdapStrategy({
+    server: {
+        url: config.ldap.server,
+        searchBase: config.ldap.searchBase,
+        searchFilter: config.ldap.searchFilter
+    }
+}));
+
 function setupLdapAuth(server) {
-    var config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
     
-    passport.use(new LdapStrategy({
-        server: {
-            url: config.ldap.server,
-            searchBase: config.ldap.searchBase,
-            searchFilter: config.ldap.searchFilter
-        }
-    }));
-
+    // Define new login strategy
     server.use(session({ 
         secret: config.sessionSecret,
         //store: a modifier avant de lancer en prod
diff --git a/src/server.js b/src/server.js
index 9317a63..3ddcb19 100644
--- a/src/server.js
+++ b/src/server.js
@@ -45,6 +45,7 @@ const typeDefs = `
     type Group {
         name: String!
         id: ID!
+        website: String
         updatedAt: String!
         description: String
         school: String!
@@ -62,8 +63,10 @@ const schema = makeExecutableSchema({
     resolvers
 });
 
+// Charge le middleware express pour GraphQL
 server.use('/graphql', bodyParser.json(), graphqlExpress({schema}));
 
+// GraphiQL est une console interactive pour faire des requêtes au schéma GraphQL
 server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql'}));
 
 
diff --git a/src/views/home.pug b/src/views/home.pug
index e0b402e..1f7ed3b 100644
--- a/src/views/home.pug
+++ b/src/views/home.pug
@@ -2,8 +2,9 @@ extends layout.pug
 
 block content
     h1 Welcome to API server
+    h2 Query the database
     p Hello, world! This is server talking to you live on port #{port}!
-    p "Interface BDD" du back
+    p You can use the REST API to query the database using the form below.
     form(action="/db", method="get")
         div.form-group
             label(for="table") Table
@@ -13,7 +14,11 @@ block content
             input.form-control(type="search", name="columns")
         button.form-control(type="submit") Search
     |
-    a(href="/graphql") Check GraphQL
+    h2 GraphiQL
+    p 
+        | GraphiQL is an interactive environment to make GraphQL
+        | requests to the database.
+    a(href="/graphiql") Check it out.
     |
     form(action="/logout", method="post")
-        button.form-control(type="submit") Se deconnecter
+        button.form-control(type="submit") Logout
diff --git a/src/views/login.pug b/src/views/login.pug
index 18abbff..c1b6c7c 100644
--- a/src/views/login.pug
+++ b/src/views/login.pug
@@ -1,9 +1,9 @@
 extends layout.pug
 
 block content
-    h1 Welcome to API server
-    p Hello, world! This is server talking to you live on port #{port}!
-    p Vous devez vous connecter pour acceder aux BDD ("interface admin").
+    h1 Sigma backend API
+    p Veuillez vous connecter.
+    p Please log in.
     form(action="/loginAttempt", method="post")
         div.form-group
             label(for="username") Frankiz ID
-- 
GitLab