This is an automated email from the git hooks/post-receive script. New commit to branch feature/save-login-in-cookie in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 729b8a026f591cc4b7ce41a1b3fc50d756fb396d Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Mar 8 14:41:41 2017 +0100 enregistrement du la connexion dans le cooki du navigateur --- pollen-ui-riot-js/src/main/web/js/AuthService.js | 15 +++----- pollen-ui-riot-js/src/main/web/js/FetchService.js | 3 +- pollen-ui-riot-js/src/main/web/js/Session.js | 44 +++++++++++++--------- pollen-ui-riot-js/src/main/web/tag/Header.tag.html | 4 +- pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html | 7 +--- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/js/AuthService.js b/pollen-ui-riot-js/src/main/web/js/AuthService.js index 06d085b..b1d9368 100644 --- a/pollen-ui-riot-js/src/main/web/js/AuthService.js +++ b/pollen-ui-riot-js/src/main/web/js/AuthService.js @@ -28,15 +28,11 @@ class AuthService extends FetchService { } signIn(login, password) { - return this.fetch("/v1/login", "POST", { - Authorization: "Basic " + btoa(login + ":" + password) - }, null).then((auth) => { - if (!auth) { - return Promise.reject(false); - } - this.session.signIn(auth, this); - return true; - }); + return this.fetch( + "/v1/login", + "POST", + {Authorization: "Basic " + btoa(login + ":" + password)}, + null); } signUp(user) { @@ -46,7 +42,6 @@ class AuthService extends FetchService { } signOut() { - this.session.signOut(); return this.get("/v1/logout"); } diff --git a/pollen-ui-riot-js/src/main/web/js/FetchService.js b/pollen-ui-riot-js/src/main/web/js/FetchService.js index e2a1883..a8f112c 100644 --- a/pollen-ui-riot-js/src/main/web/js/FetchService.js +++ b/pollen-ui-riot-js/src/main/web/js/FetchService.js @@ -21,8 +21,7 @@ class FetchService { constructor() { - this.session = require("./Session"); - this.endPoint = this.session.configuration.endPoint; + this.endPoint = window.pollenConf.endPoint; } fetch(url, method, headers, body) { diff --git a/pollen-ui-riot-js/src/main/web/js/Session.js b/pollen-ui-riot-js/src/main/web/js/Session.js index 9bfbc03..5c70ffd 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -19,6 +19,7 @@ * #L% */ let singleton = require("./Singleton"); +let authService = require("./AuthService"); class Session { @@ -54,7 +55,7 @@ class Session { start() { if (this.isConnected()) { - this.user = this.connect(require("./AuthService")); + this.user = this.connect(); } else { this.user = Promise.resolve(); } @@ -110,9 +111,9 @@ class Session { return document.cookie.indexOf("pollen-connected=true") !== -1; } - connect(userService) { + connect() { console.info("Connect::"); - return userService.connectedUserPromise().then((user) => { + return authService.connectedUserPromise().then((user) => { if (!user) { console.info("Connect error"); this.user = null; @@ -126,26 +127,33 @@ class Session { }); } - signIn(auth, userService) { - console.info("SignIn::"); - console.info(auth); - userService.userPromise(auth).then((user) => { - if (!user) { - console.info("SignIn error"); - this.user = null; - return Promise.reject(); - } - console.info("SignIn user::"); - console.info(user); - this.user = Promise.resolve(user); - this.emitConnected(user); - return user; + signIn(login, password) { + return authService.signIn(login, password).then(auth => { + console.info("SignIn::"); + console.info(auth); + document.cookie = JSON.stringify(auth); + return authService.userPromise(auth).then((user) => { + if (!user) { + console.info("SignIn error"); + this.user = null; + return Promise.reject(); + } + console.info("SignIn user::"); + console.info(user); + this.user = user; + this.emitConnected(user); + return Promise.resolve(user); + }); + }); } signOut() { - delete this.user; + return authService.signOut().then(() => { + document.cookie = ""; + delete this.user; + }); } } diff --git a/pollen-ui-riot-js/src/main/web/tag/Header.tag.html b/pollen-ui-riot-js/src/main/web/tag/Header.tag.html index b5504ab..e528b71 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Header.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Header.tag.html @@ -60,7 +60,6 @@ require("./HeaderI18n.tag.html"); <script type="es6"> let route = require("riot-route"); - let authService = require("../js/AuthService"); let session = require("../js/Session"); this.installBundle(session, "header"); @@ -68,6 +67,7 @@ require("./HeaderI18n.tag.html"); this.signIn = () => { route("signin?url=" + window.location.hash.substring(1)); }; + this.signOut = () => { let callback = () => { this.user = null; @@ -76,7 +76,7 @@ require("./HeaderI18n.tag.html"); route("home"); }; - authService.signOut().then(callback, callback); + session.signOut().then(callback, callback); }; diff --git a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html index 04665a2..85b2d6c 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html @@ -43,7 +43,6 @@ require("./popup/NewPassword.tag.html"); <NewPassword ref="newPassword"/> <script type="es6"> - let authService = require("../js/AuthService"); let session = require("../js/Session"); let route = require("riot-route"); @@ -60,14 +59,12 @@ require("./popup/NewPassword.tag.html"); this.message = ""; - authService.signIn(this.refs.login.value, this.refs.password.value) + session.signIn(this.refs.login.value, this.refs.password.value) .then(() => { let back = this.opts.url || "/"; // console.info("After login url:" +back); route(back); - this.update(); - }) - .catch(() => { + }, () => { this.message = this.__.error_signin; this.update(); }); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.