diff --git a/src/main/java/com/erudika/scoold/controllers/SigninController.java b/src/main/java/com/erudika/scoold/controllers/SigninController.java index 5d619f7d..904fcd8a 100755 --- a/src/main/java/com/erudika/scoold/controllers/SigninController.java +++ b/src/main/java/com/erudika/scoold/controllers/SigninController.java @@ -75,18 +75,15 @@ public String get(@RequestParam(name = "returnto", required = false, defaultValu } @GetMapping(path = "/signin", params = {"access_token", "provider"}) - public String getAuth(@RequestParam("access_token") String accessToken, @RequestParam("provider") String provider, + public String signinGet(@RequestParam("access_token") String accessToken, @RequestParam("provider") String provider, HttpServletRequest req, HttpServletResponse res) { - if (!utils.isAuthenticated(req)) { - User u = utils.getParaClient().signIn(provider, accessToken, false); - if (u != null) { - HttpUtils.setStateParam(Config.AUTH_COOKIE, u.getPassword(), req, res, true); - } else { - verifyEmailIfNecessary(provider, "Anonymous", accessToken.split(":")[0], req); - return "redirect:" + signinlink + "?code=3&error=true"; - } - } - return "redirect:" + getBackToUrl(req); + return getAuth(provider, accessToken, req, res); + } + + @PostMapping(path = "/signin", params = {"access_token", "provider"}) + public String signinPost(@RequestParam("access_token") String accessToken, @RequestParam("provider") String provider, + HttpServletRequest req, HttpServletResponse res) { + return getAuth(provider, accessToken, req, res); } @GetMapping("/signin/success") @@ -171,6 +168,19 @@ public String globals(HttpServletRequest req, HttpServletResponse res) { return sb.toString(); } + private String getAuth(String provider, String accessToken, HttpServletRequest req, HttpServletResponse res) { + if (!utils.isAuthenticated(req)) { + User u = utils.getParaClient().signIn(provider, accessToken, false); + if (u != null) { + HttpUtils.setStateParam(Config.AUTH_COOKIE, u.getPassword(), req, res, true); + } else { + verifyEmailIfNecessary(provider, "Anonymous", accessToken.split(":")[0], req); + return "redirect:" + signinlink + "?code=3&error=true"; + } + } + return "redirect:" + getBackToUrl(req); + } + private String getBackToUrl(HttpServletRequest req) { String backtoFromCookie = Utils.urlDecode(HttpUtils.getStateParam("returnto", req)); return (StringUtils.isBlank(backtoFromCookie) ? HOMEPAGE : backtoFromCookie); diff --git a/src/main/resources/static/scripts/signin.js b/src/main/resources/static/scripts/signin.js index 2fb0ae78..ac51e60b 100644 --- a/src/main/resources/static/scripts/signin.js +++ b/src/main/resources/static/scripts/signin.js @@ -1,27 +1,4 @@ /* global FB_APP_ID, gapi, FB, GOOGLE_CLIENT_ID, GITHUB_APP_ID, LINKEDIN_APP_ID, APPID, ENDPOINT, TWITTER_APP_ID, MICROSOFT_APP_ID */ - -function onClick(buttonId, fn) { - var loginBtn = document.getElementById(buttonId); - if (loginBtn) { - if (document.body.attachEvent) { - loginBtn.attachEvent("onclick", fn); - } else { - loginBtn.addEventListener("click", fn); - } - } -} - -function onSubmit(formId, fn) { - var form = document.getElementById(formId); - if (form) { - if (document.body.attachEvent) { - form.attachEvent("onsubmit", fn); - } else { - form.addEventListener("submit", fn); - } - } -} - /************************ * Facebook integration * ************************/ @@ -34,7 +11,7 @@ if (FB_APP_ID && FB_APP_ID.trim() !== "") { fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); - onClick('fb-login-btn', function () { + $('#fb-login-btn').on('click', function () { FB.login(function(response) { if (response.authResponse) { window.location = "/signin?provider=facebook&access_token=" + response.authResponse.accessToken; @@ -58,16 +35,15 @@ if (GOOGLE_CLIENT_ID && GOOGLE_CLIENT_ID.trim() !== "") { gjs.parentNode.insertBefore(js, gjs); }(document, 'script', 'google-jssdk')); - var gpLoginBtn = document.getElementById('gp-login-btn'); function gpLogin() { - if (gpLoginBtn) { + if ($('gp-login-btn').length) { gapi.load('auth2', function(){ auth2 = gapi.auth2.init({ client_id: GOOGLE_CLIENT_ID, scope: 'https://www.googleapis.com/auth/plus.me' }); - auth2.attachClickHandler(document.getElementById('gp-login-btn'), {}, function(googleUser) { + auth2.attachClickHandler($('#gp-login-btn').get(0), {}, function(googleUser) { window.location = "/signin?provider=google&access_token=" + googleUser.getAuthResponse(true).access_token; }, function(error) { window.location = "/signin?code=3&error=true"; @@ -80,7 +56,7 @@ if (GOOGLE_CLIENT_ID && GOOGLE_CLIENT_ID.trim() !== "") { * GitHub integration * **********************/ if (GITHUB_APP_ID && GITHUB_APP_ID.trim() !== "") { - onClick('gh-login-btn', function () { + $('#gh-login-btn').on('click', function () { window.location = "https://github.com/login/oauth/authorize?" + "response_type=code&client_id=" + GITHUB_APP_ID + "&scope=user:email&state=" + (new Date().getTime()) + @@ -92,7 +68,7 @@ if (GITHUB_APP_ID && GITHUB_APP_ID.trim() !== "") { * LinkedIn integration * ************************/ if (LINKEDIN_APP_ID && LINKEDIN_APP_ID.trim() !== "") { - onClick('in-login-btn', function () { + $('#in-login-btn').on('click', function () { window.location = "https://www.linkedin.com/uas/oauth2/authorization?" + "response_type=code&client_id=" + LINKEDIN_APP_ID + "&scope=r_emailaddress&state=" + (new Date().getTime()) + @@ -104,7 +80,7 @@ if (LINKEDIN_APP_ID && LINKEDIN_APP_ID.trim() !== "") { * Twitter integration * ***********************/ if (TWITTER_APP_ID && TWITTER_APP_ID.trim() !== "") { - onClick('tw-login-btn', function () { + $('#tw-login-btn').on('click', function () { window.location = ENDPOINT + "/twitter_auth?appid=" + APPID; return false; }); @@ -113,7 +89,7 @@ if (TWITTER_APP_ID && TWITTER_APP_ID.trim() !== "") { * Microsoft integration * *************************/ if (MICROSOFT_APP_ID && MICROSOFT_APP_ID.trim() !== "") { - onClick('ms-login-btn', function () { + $('#ms-login-btn').on('click', function () { window.location = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?" + "response_type=code&client_id=" + MICROSOFT_APP_ID + "&scope=https%3A%2F%2Fgraph.microsoft.com%2Fuser.read&state=" + APPID + @@ -124,24 +100,20 @@ if (MICROSOFT_APP_ID && MICROSOFT_APP_ID.trim() !== "") { /******************** * LDAP integration * ********************/ -onSubmit('ldap-login-form', function (e) { - e.preventDefault(); - var username = document.getElementById("username"); - var password = document.getElementById("password"); +$('#ldap-login-form').on('submit', function () { + var username = $("#username").val(); + var password = $("#password").val(); if (username && password) { - window.location = "/signin?provider=ldap&access_token=" + username.value + ":" + password.value; + $(this).find("input[name='access_token']").val(username + ":" + password); } - return false; }); /******************* * Password Auth * *******************/ -onSubmit('password-login-form', function (e) { - e.preventDefault(); - var email = document.getElementById("email"); - var passw = document.getElementById("passw"); +$('#password-login-form').on('submit', function () { + var email = $("#email").val(); + var passw = $("#passw").val(); if (email && passw) { - window.location = "/signin?provider=password&access_token=" + email.value + "::" + passw.value; + $(this).find("input[name='access_token']").val(email + "::" + passw); } - return false; }); \ No newline at end of file diff --git a/src/main/resources/templates/base.vm b/src/main/resources/templates/base.vm index 94e36615..354338b3 100755 --- a/src/main/resources/templates/base.vm +++ b/src/main/resources/templates/base.vm @@ -221,8 +221,11 @@ #end - #if($includeGAjs) - + #if ($request.getRequestURI().startsWith($signinlink)) + + #end + #if ($includeGAjs) + #end \ No newline at end of file diff --git a/src/main/resources/templates/signin.vm b/src/main/resources/templates/signin.vm index 215c43b2..9a377f87 100755 --- a/src/main/resources/templates/signin.vm +++ b/src/main/resources/templates/signin.vm @@ -60,13 +60,16 @@ #if($passwordLoginEnabled)

$!lang.get('signin.password')

-
+ + #sectoken(false "SIGNIN_PASS")
- +
- +
+ +

@@ -77,13 +80,16 @@ #if($ldapLoginEnabled)

LDAP

-
+ + #sectoken(false "SIGNIN_LDAP")
- +
- +
+ +
@@ -146,5 +152,3 @@
#end - - \ No newline at end of file