This is an automated email from the git hooks/post-receive script. New commit to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 0975e601980fb223ec2691e40008a085b20df618 Author: Kevin Morin <morin@codelutin.com> Date: Tue Sep 5 16:08:48 2017 +0200 refs #1 ajout de credentials depuis le profil --- .../org/chorem/pollen/rest/api/v1/AuthApi.java | 2 +- pollen-ui-riot-js/src/main/web/js/AuthService.js | 19 ++++++-- pollen-ui-riot-js/src/main/web/js/Session.js | 2 +- pollen-ui-riot-js/src/main/web/js/UserService.js | 11 +++++ pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html | 35 +++++++++++--- pollen-ui-riot-js/src/main/web/tag/SignIn.tag.html | 28 +++-------- .../src/main/web/tag/UserProfile.tag.html | 56 ++++++++++++++++++++-- .../src/main/web/tag/admin/Users.tag.html | 4 +- 8 files changed, 118 insertions(+), 39 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java index 776a4f6c..f7cc206a 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthApi.java @@ -216,7 +216,7 @@ public class AuthApi { String providerReturn) throws Exception { - SocialAuthManager socialAuthManager = + (SocialAuthManager) request.getSession().getAttribute(ApiUtils.SOCIAL_AUTH_MANAGER_SESSION_KEY); //socialAuthManager request.getSession().removeAttribute(ApiUtils.SOCIAL_AUTH_MANAGER_SESSION_KEY); 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 3fd1d1f1..aed4e7c4 100644 --- a/pollen-ui-riot-js/src/main/web/js/AuthService.js +++ b/pollen-ui-riot-js/src/main/web/js/AuthService.js @@ -25,6 +25,20 @@ class AuthService extends FetchService { constructor() { super(); + this.providerIcons = { + "amazon": "amazon", + "facebook": "facebook-official", + "flickr": "flickr", + "foursquare": "foursquare", + "github": "github", + "googleplus": "google", + "instagram": "instagram", + "linkedin": "linkedin", + "linkedin2": "linkedin", + "stackexchange": "stack-exchange", + "twitter": "twitter", + "yahoo": "yahoo" + }; } signIn(login, password) { @@ -73,10 +87,9 @@ class AuthService extends FetchService { } signInProvider(query) { - return this.fetch( + return this.post( "/v1/login/" + query.loginProvider, - "POST", - {Authorization: JSON.stringify(query)}); + JSON.stringify(query)); } getAllLoginProviders() { 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 57e5396e..83049c93 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -174,7 +174,7 @@ class Session { } getProviderRedirectionUrl(provider) { - return this.pollenUIContext.uiEndPoint + "/?loginProvider=" + provider; + return this.pollenUIContext.uiEndPoint + "/?loginProvider=" + provider + "&action=signin"; } } diff --git a/pollen-ui-riot-js/src/main/web/js/UserService.js b/pollen-ui-riot-js/src/main/web/js/UserService.js index 58fe4c6e..32735ae2 100644 --- a/pollen-ui-riot-js/src/main/web/js/UserService.js +++ b/pollen-ui-riot-js/src/main/web/js/UserService.js @@ -62,6 +62,17 @@ class UserService extends FetchService { return this.post(url, body); } + linkProvider(userId, query) { + let url = this._getUrlPrefix(userId) + "/credentials/" + query.loginProvider; + let body = JSON.stringify(query); + return this.post(url, body); + } + + + unlinkProvider(userId, credentialId) { + let url = this._getUrlPrefix(userId) + "/credentials/" + credentialId; + return this.doDelete(url); + } } module.exports = singleton(UserService); diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html index a64d7482..dbcddc0d 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag.html @@ -53,9 +53,11 @@ require("./popup/InformationPopup.tag.html"); <script type="es6"> let session = require("../js/Session"); - session.start(); this.installBundle(session, "main"); + + session.start(); this.pageTitle = undefined; + let userService = require("../js/UserService"); this.onLocaleChange = () => { this.updatePageTitle(); @@ -135,7 +137,7 @@ require("./popup/InformationPopup.tag.html"); }); route("/poll", () => { - if (!session.isConnected() && !session.getUser.administrator) { + if (!session.isConnected() && !session.getUser().administrator) { route("/signin?url=/poll"); } else { this.bus.trigger("pageChanged", "admin_polls"); @@ -144,7 +146,7 @@ require("./popup/InformationPopup.tag.html"); }); route("/user", () => { - if (!session.isConnected() && !session.getUser.administrator) { + if (!session.isConnected() && !session.getUser().administrator) { route("/signin?url=/user"); } else { this.bus.trigger("pageChanged", "admin_users"); @@ -233,19 +235,40 @@ require("./popup/InformationPopup.tag.html"); route(() => { var q = route.query(); if (q.loginProvider != null) { + if (q.action === "signin") { session.signInProvider(q).then(() => { let currentPage = localStorage.getItem("currentPage"); localStorage.removeItem("currentPage"); - location.href = session.pollenUIContext.uiEndPoint + "/" + currentPage; + location.replace(session.pollenUIContext.uiEndPoint + "/" + currentPage); }, (e) => { let currentPage = localStorage.getItem("currentPage"); localStorage.removeItem("currentPage"); - console.log(e); e.text().then(label => { - location.href = session.pollenUIContext.uiEndPoint + "/" + currentPage + "?error=" + label; + location.replace(session.pollenUIContext.uiEndPoint + "/" + currentPage + "?error=" + label); }); }); + } else if (q.action === "link" && session.isConnected()) { + let callback = (user) => { + userService.linkProvider(user.id, q).then((accountName) => { + location.replace(session.pollenUIContext.uiEndPoint + "/#user/profile"); + }, (e) => { + e.text().then(label => { + location.replace(session.pollenUIContext.uiEndPoint + "/#user/profile?error=" + label); + }); + }); + }; + + if (session.getUser()) { + callback(session.getUser()); + } else { + this.bus.on("user", (user) => { + callback(user); + this.bus.off("user", callback); + }); + } + } + } else { this.bus.trigger("pageChanged", "home"); riot.mount(this.refs.content, "home"); 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 10f992e7..ada0bdf3 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 @@ -53,12 +53,12 @@ require("./components/HumanInput.tag.html"); <p><a onclick="{newPassword}">{__.lostpassword}</a></p> </div> <div class="o-form-element align-center" if="{loginProviders.length > 0}"> - <p>Ou connectez vous avec votre compte :</p> + <p>{__.signinWithProvider}</p> <p> <a each="{loginProvider in loginProviders}" class="provider-link" onclick="{signinWithProvider(loginProvider)}"> - <i class="fa fa-{providerIcons[loginProvider]}" if="{providerIcons[loginProvider]}"></i> - <span if="{!providerIcons[loginProvider]}">{loginProvider}</span> + <i class="fa fa-{authService.providerIcons[loginProvider]}" if="{authService.providerIcons[loginProvider]}"></i> + <span if="{!authService.providerIcons[loginProvider]}">{loginProvider}</span> </a> </p> </div> @@ -81,25 +81,10 @@ require("./components/HumanInput.tag.html"); this.message = ""; this.openSignIn = false; - this.providerIcons = { - "amazon": "amazon", - "facebook": "facebook-official", - "flickr": "flickr", - "foursquare": "foursquare", - "github": "github", - "googleplus": "google", - "instagram": "instagram", - "linkedin": "linkedin", - "linkedin2": "linkedin", - "stackexchange": "stack-exchange", - "twitter": "twitter", - "yahoo": "yahoo" - }; - - let authService = require("../js/AuthService"); + this.authService = require("../js/AuthService"); this.loginProviders = []; this.on("mount", () => { - authService.getActiveLoginProviders().then((result) => { + this.authService.getActiveLoginProviders().then((result) => { this.loginProviders = result; this.update(); }); @@ -140,9 +125,8 @@ require("./components/HumanInput.tag.html"); this.signinWithProvider = (provider) => (e) => { let currentPage = location.hash || "#"; localStorage.setItem("currentPage", currentPage); - let authService = require("../js/AuthService"); let redirection = encodeURIComponent(this.session.getProviderRedirectionUrl(provider)); - authService.getLoginProviderUrl(provider, redirection).then(result => { + this.authService.getLoginProviderUrl(provider, redirection).then(result => { location.href = result; }); }; diff --git a/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html b/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html index f7e2eda0..d036bbe2 100644 --- a/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html @@ -59,6 +59,28 @@ require("./components/HumanInput.tag.html"); {__.saveIdentity} </button> </div> + + <div> + <div each="{credential in user.credentials}" class="credential"> + <i if="{authService.providerIcons[credential.provider]}" + class="fa fa-{authService.providerIcons[credential.provider]}"></i> + <span if="{!authService.providerIcons[credential.provider]}">{credential.userName}</span> + <span>{credential.userName}</span> + <a if="{user.withPassword && user.email || user.credentials.length > 1}" + onclick="{unlinkProvider(credential.id)}">X</a> + </div> + </div> + + <div class="o-form-element align-center" if="{loginProviders.length > 0}"> + <p>{__.linkProvider}</p> + <p> + <a each="{loginProvider in loginProviders}" class="provider-link" + onclick="{linkProvider(loginProvider)}"> + <i class="fa fa-{authService.providerIcons[loginProvider]}" if="{authService.providerIcons[loginProvider]}"></i> + <span if="{!authService.providerIcons[loginProvider]}">{loginProvider}</span> + </a> + </p> + </div> </form> <form ref="password-form" class="password-form"> @@ -130,16 +152,22 @@ require("./components/HumanInput.tag.html"); this.errors = {}; this.user = session.getUser() || {}; let userService = require("../js/UserService"); - let authService = require("../js/AuthService"); + this.authService = require("../js/AuthService"); let Message = require("../js/Message"); + this.loginProviders = []; + this.authService.getActiveLoginProviders().then((result) => { + this.loginProviders = result; + this.update(); + }); + this.onUserChange = (user) => { this.user = user || {}; this.update(); }; this.resendValidation = () => { - authService.resendValidation(this.user.email); + this.authService.resendValidation(this.user.email); }; this.submitIdentity = e => { @@ -179,8 +207,8 @@ require("./components/HumanInput.tag.html"); } this.refs.newPassword.value = ""; this.refs.repeatPassword.value = ""; - this.user.withPassword = true; this.update(); + session.updateUser(); this.bus.trigger("message", new Message(this._l("updatedPassword"), "success")); }) .catch((errors) => { @@ -190,6 +218,20 @@ require("./components/HumanInput.tag.html"); } }; + this.linkProvider = (provider) => (e) => { + let redirection = encodeURIComponent(location.origin + location.pathname + + "?loginProvider=" + provider + "&action=link"); + this.authService.getLoginProviderUrl(provider, redirection).then(result => { + location.assign(result); + }); + }; + + this.unlinkProvider = (credentialId) => (e) => { + userService.unlinkProvider(this.user.id, credentialId).then(result => { + console.log("ok"); + }); + }; + this.listen("user", this.onUserChange); </script> @@ -208,6 +250,14 @@ require("./components/HumanInput.tag.html"); padding: 0 5px; } + .credential { + font-size: 1.5em; + } + + .provider-link { + font-size: 2em; + } + </style> </UserProfile> diff --git a/pollen-ui-riot-js/src/main/web/tag/admin/Users.tag.html b/pollen-ui-riot-js/src/main/web/tag/admin/Users.tag.html index 286538ad..fa33c0f6 100644 --- a/pollen-ui-riot-js/src/main/web/tag/admin/Users.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/admin/Users.tag.html @@ -47,11 +47,9 @@ require("./UserCard.tag.html"); this.lazyLoad = pagination => { return userService.users(pagination, this.search.value).then((result) => { - if (!this.loaded) { + this.loaded = true; this.count = result.pagination.count; - this.loaded = true; this.update(); - } return result; }); }; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.