From 5c32ac3e59438a5c8608685e4f7a2dcc80595e77 Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Thu, 12 Jul 2018 13:23:42 +0300 Subject: [PATCH] Add "bounce" logic from "reset_password.js" This should add support for https://pagure.io/freeipa/issue/4440 Fixes: https://pagure.io/freeipa/issue/7619 Reviewed-By: Petr Vobornik Reviewed-By: Serhii Tsymbaliuk --- install/ui/src/freeipa/widgets/LoginScreen.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/install/ui/src/freeipa/widgets/LoginScreen.js b/install/ui/src/freeipa/widgets/LoginScreen.js index ce7681c7c..b4af193bb 100644 --- a/install/ui/src/freeipa/widgets/LoginScreen.js +++ b/install/ui/src/freeipa/widgets/LoginScreen.js @@ -66,6 +66,8 @@ define(['dojo/_base/declare', "certificate, please make sure you have valid " + "personal certificate. ", + continue_msg: "Continue to next page", + form_auth_failed: "Login failed due to an unknown reason", krb_auth_failed: "Authentication with Kerberos failed", @@ -77,6 +79,8 @@ define(['dojo/_base/declare', password_change_complete: "Password change complete", + redirect_msg: "You will be redirected in ${count}s", + krbprincipal_expired: "Kerberos Principal you entered is expired", invalid_password: "The password or username you entered is incorrect", @@ -293,6 +297,69 @@ define(['dojo/_base/declare', }.bind(this)); }, + parse_uri: function() { + var opts = {}; + if (window.location.search.length > 1) { + var couples = window.location.search.substr(1).split("&"); + for (var i=0,l=couples.length; i < l; i++) { + var couple = couples[i].split("="); + var key = decodeURIComponent(couple[0]); + var value = couple.length > 1 ? decodeURIComponent(couple[1]) : ''; + opts[key] = value; + } + } + return opts; + }, + + redir_count_down: function(redir_url, redir_delay) { + var val_summary = this.get_widget('validation'); + val_summary.add_info('redirect', + this.redirect_msg.replace('${count}', Math.max(redir_delay, 0))); + + if (redir_delay <= 0) { + window.location = redir_url; + return; + } + window.setTimeout(this.redir_count_down.bind(this), 1000, + redir_url, redir_delay-1); + }, + + /* If password reset was initiated due to a failed log in to some + * external application one could use a redirection to the desired URL + * after a successfull password reset. + * + * The next uri components are supported: + * - 'url' destination URL, which must be URI encoded + * - 'delay' time in seconds to delay before redirection + * + * For example, + * https://ipa.demo1.freeipa.org/ipa/ui/reset_password.html?url=http%3A%2F%2Fpvoborni.fedorapeople.org%2Fdoc%2F%23!%2Fguide%2FDebugging&delay=5 + */ + redirect: function() { + var opts = this.parse_uri(); + var url = opts['url']; + var delay = parseInt(opts['delay'], 10); + + var val_summary = this.get_widget('validation'); + // button for manual redirection + if (url) { + val_summary.add_success( + 'login', + "".concat( + this.password_change_complete, + ' ', + this.continue_msg, '' + ) + ); + } else { + return; + } + + if (delay <= 0 || delay > 0) { // NaN check + this.redir_count_down(url, delay); + } + }, + reset_password: function() { var psw_f = this.get_field('password');