branch feature/1_socialauth updated (d20e8ccc -> dfd6aa67)
This is an automated email from the git hooks/post-receive script. New change to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git from d20e8ccc refs #1 permettre d'ajouter des comptes tiers à un compte existant new dfd6aa67 refs #1 ajout de credentials depuis le profil The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit dfd6aa671245b7543c18afbfc2d69eb063e537b2 Author: Kevin Morin <morin@codelutin.com> Date: Tue Sep 5 16:08:48 2017 +0200 refs #1 ajout de credentials depuis le profil Summary of changes: .../org/chorem/pollen/rest/api/v1/AuthApi.java | 2 +- pollen-ui-riot-js/src/main/web/i18n.json | 8 +++- 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 +- 9 files changed, 124 insertions(+), 41 deletions(-) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 dfd6aa671245b7543c18afbfc2d69eb063e537b2 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/i18n.json | 8 +++- 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 +- 9 files changed, 124 insertions(+), 41 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/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 93c25c00..a39cf222 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -13,7 +13,7 @@ "main_editPoll" : "Edition du sondage", "main_userProfile" : "Mon profil", "main_favoriteLists" : "Listes de votants", - "main_emailAlreadyUsed": "L'adresse email du compte avec lequel vous essayez de vous connecter, est déjà utilisée par un autre compte Pollen.", + "main_emailOrProviderAccountAlreadyUsed": "L'adresse email du compte avec lequel vous essayez de vous connecter, est déjà utilisée par un autre compte Pollen.", "pagination_all": "Tous", "pagination_resultsPerPage": "Résultats par page", "summary_choices": "Choix", @@ -201,6 +201,7 @@ "signin_password_placeholder": "Entrez votre mot de passe", "signin_lostpassword": "Mot de passe perdu ?", "signin_connexion": "Se connecter", + "signin_signinWithProvider": "Ou connectez vous avec votre compte :", "signin_error_signin_emailOrPasswordInvalid": "Courriel ou mot de passe invalide", "signin_error_signin_banned": "Compte bloqué", "signin_error_signin_emailNotValidated": "Vous devez valider votre compte avant de pouvoir vous connecter. Relevez vos emails, nous vous avons envoyé un lien de validation.", @@ -395,6 +396,7 @@ "userProfile_repeatPassword_error": "Les deux mots de passe ne sont pas identiques.", "userProfile_savePassword": "Enregistrer", "userProfile_updatedPassword": "Votre mot de passe a été mis à jour", + "userProfile_linkProvider": "Associez un compte externe pour vous connecter à Pollen :", "choice_description_placeholder": "Vous pouvez saisir une description pour ce choix", "date-picker_today": "Aujourd'hui", "date-picker_dateplaceholder": "Date", @@ -568,7 +570,7 @@ "main_editPoll" : "Poll edition", "main_userProfile" : "My profile", "main_favoriteLists" : "List of favorites", - "main_emailAlreadyUsed": "The email address of the account you are connecting with is already used by another Pollen account.", + "main_emailOrProviderAccountAlreadyUsed": "The email address of the account you are connecting with is already used by another Pollen account.", "pagination_all": "All", "pagination_resultsPerPage": "Results per page", "summary_choices": "Choices", @@ -752,6 +754,7 @@ "signin_password_placeholder": "Enter your password", "signin_lostpassword": "Lost password?", "signin_connexion": "Connect", + "signin_signinWithProvider": "Or connect with your account:", "signin_error_signin_emailOrPasswordInvalid": "Email or password invalid", "signin_error_signin_banned": "Bloked account", "signin_error_signin_emailNotValidated": "You must validate your account before connecting. Check your emails, we sent you an activation link.", @@ -939,6 +942,7 @@ "userProfile_repeatPassword_error": "The two passwords are not identical.", "userProfile_savePassword": "Save", "userProfile_updatedPassword": "Your password has been updated", + "userProfile_linkProvider": "Link an external account to connect to Pollen:", "choice_description_placeholder": "You can enter a description for this choice", "date-picker_today": "Today", "date-picker_dateplaceholder": "Date", 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 2c5da6ed..12227adf 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -171,7 +171,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>.
participants (1)
-
chorem.org scm