From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Mon, 16 Apr 2018 21:09:05 +0200 Subject: Main merge to user management system - files are now at /main/public/ --- .../assets/userfrosting/js/pages/sign-in.js | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js (limited to 'main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js') diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js new file mode 100755 index 0000000..40a8628 --- /dev/null +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js @@ -0,0 +1,39 @@ +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/sign-in + */ +$(document).ready(function() { + /** + * If there is a redirect parameter in the query string, redirect to that page. + * Otherwise, if there is a UF-Redirect header, redirect to that page. + * Otherwise, redirect to the home page. + */ + function redirectOnLogin(jqXHR) { + var components = URI.parse(window.location.href); + var query = URI.parseQuery(components['query']); + + if (query && query['redirect']) { + // Strip leading slashes from redirect strings + var redirectString = site.uri.public + '/' + query['redirect'].replace(/^\/+/, ""); + // Strip excess trailing slashes for clean URLs. e.g. if redirect=%2F + redirectString = redirectString.replace(/\/+$/, "/"); + // Redirect + window.location.replace(redirectString); + } else if (jqXHR.getResponseHeader('UF-Redirect')) { + window.location.replace(jqXHR.getResponseHeader('UF-Redirect')); + } else { + window.location.replace(site.uri.public); + } + } + + $("#sign-in").ufForm({ + validators: page.validators.login, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function(event, data, textStatus, jqXHR) { + redirectOnLogin(jqXHR); + }); +}); -- cgit v1.2.3