diff options
-rw-r--r-- | install/ui/test/data/ipa_init.json | 1 | ||||
-rw-r--r-- | install/ui/user.js | 185 | ||||
-rw-r--r-- | ipalib/plugins/internal.py | 1 |
3 files changed, 114 insertions, 73 deletions
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json index 7ceda5703..01201f69e 100644 --- a/install/ui/test/data/ipa_init.json +++ b/install/ui/test/data/ipa_init.json @@ -425,6 +425,7 @@ "current_password": "Current Password", "current_password_required": "Current password is required", "new_password": "New Password", + "new_password_required": "New password is required", "password_change_complete": "Password change complete", "password_must_match": "Passwords must match", "reset_password": "Reset Password", diff --git a/install/ui/user.js b/install/ui/user.js index 65d3de726..61db5315e 100644 --- a/install/ui/user.js +++ b/install/ui/user.js @@ -107,7 +107,8 @@ IPA.user.entity = function(spec) { 'uid', { factory: IPA.user_password_widget, - name: 'userpassword' + name: 'has_password', + metadata: IPA.get_entity_param('user', 'userpassword') }, { name: 'krbpasswordexpiration', @@ -430,118 +431,154 @@ IPA.user_adder_dialog = function(spec) { IPA.user_password_widget = function(spec) { spec = spec || {}; + spec.read_only = true; var that = IPA.input_widget(spec); + that.set_value = spec.set_value || '******'; + that.unset_value = spec.unset_value || ''; that.create = function(container) { that.widget_create(container); - $('<a/>', { - href: 'jslink', - title: 'userpassword', - text: IPA.messages.password.reset_password, - click: function() { - that.show_dialog(); - return false; - } + that.display_control = $('<label/>', { + name: that.name }).appendTo(container); }; - that.show_dialog = function() { - - var pkey = IPA.nav.get_state('user-pkey'); - var self_service = pkey === IPA.whoami.uid[0]; + that.update = function(values) { - var sections = []; - if (self_service) { - sections.push({ - fields: [ - { - name: 'current_password', - label: IPA.messages.password.current_password, - type: 'password' - } - ] - }); + if (values && values[0]) { + that.display_control.text(that.set_value); + } else { + that.display_control.text(that.unset_value); } + }; + + that.clear = function() { + that.display_control.text(''); + }; + + return that; +}; - sections.push({ +IPA.user_password_dialog = function(spec) { + + spec = spec || {}; + + spec.width = spec.width || 400; + spec.title = spec.title || IPA.messages.password.reset_password; + spec.sections = spec.sections || []; + + spec.sections.push( + { + name: 'input', fields: [ { + name: 'current_password', + label: IPA.messages.password.current_password, + type: 'password', + required: true + }, + { name: 'password1', label: IPA.messages.password.new_password, - type: 'password' + type: 'password', + required: true }, { name: 'password2', label: IPA.messages.password.verify_password, - type: 'password' + type: 'password', + required: true } ] }); - var dialog = IPA.dialog({ - entity: that.entity, - title: IPA.messages.password.reset_password, - width: 400, - sections: sections - }); + var that = IPA.dialog(spec); + that.get_pkey = function() { + return IPA.nav.get_state('user-pkey'); + }; - dialog.create_button({ - name: 'reset_password', - label: IPA.messages.password.reset_password, - click: function() { - - var record = {}; - dialog.save(record); + that.is_self_service = function() { + var pkey = that.get_pkey(); + var self_service = pkey === IPA.whoami.uid[0]; + return self_service; + }; - var current_password; + that.open = function() { - if (self_service) { - current_password = record.current_password[0]; - if (!current_password) { - alert(IPA.messages.password.current_password_required); - return; - } - } + var self_service = that.is_self_service(); + var section = that.widgets.get_widget('input'); - var new_password = record.password1[0]; - var repeat_password = record.password2[0]; + that.dialog_open(); + section.set_row_visible('current_password', self_service); + }; - if (new_password != repeat_password) { - alert(IPA.messages.password.password_must_match); - return; - } + that.create_buttons = function() { - that.set_password( - pkey, - current_password, - new_password, - function(data, text_status, xhr) { - alert(IPA.messages.password.password_change_complete); - dialog.close(); - // refresh password expiration field - var facet = IPA.current_entity.get_facet(); - facet.refresh(); - }, - function(xhr, text_status, error_thrown) { - dialog.close(); - } - ); - } + that.create_button({ + name: 'reset_password', + label: IPA.messages.password.reset_password, + click: that.on_reset_click }); - dialog.create_button({ + that.create_button({ name: 'cancel', label: IPA.messages.buttons.cancel, click: function() { - dialog.close(); + that.close(); } }); + }; + + that.on_reset_click = function() { + + var pkey = that.get_pkey(); + var self_service = that.is_self_service(); + + var record = {}; + that.save(record); - dialog.open(that.container); + var current_password; + + if (self_service) { + current_password = record.current_password[0]; + if (!current_password) { + alert(IPA.messages.password.current_password_required); + return; + } + } + + var new_password = record.password1[0]; + var repeat_password = record.password2[0]; + + if (IPA.is_empty(new_password)) { + alert(IPA.messages.password.new_password_required); + return; + } + + if (new_password != repeat_password) { + alert(IPA.messages.password.password_must_match); + return; + } + + that.set_password( + pkey, + current_password, + new_password, + function(data, text_status, xhr) { + alert(IPA.messages.password.password_change_complete); + that.close(); + // refresh password expiration field + var facet = IPA.current_entity.get_facet(); + facet.refresh(); + }, + function(xhr, text_status, error_thrown) { + that.close(); + } + ); }; that.set_password = function(pkey, current_password, password, on_success, on_error) { @@ -560,6 +597,8 @@ IPA.user_password_widget = function(spec) { command.execute(); }; + that.create_buttons(); + return that; }; diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py index 30ab91640..2ed57f69a 100644 --- a/ipalib/plugins/internal.py +++ b/ipalib/plugins/internal.py @@ -564,6 +564,7 @@ class i18n_messages(Command): "current_password": _("Current Password"), "current_password_required": _("Current password is required"), "new_password": _("New Password"), + "new_password_required": _("New password is required"), "password_change_complete": _("Password change complete"), "password_must_match": _("Passwords must match"), "reset_password": _("Reset Password"), |