summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2014-05-22 16:20:02 +0200
committerPetr Vobornik <pvoborni@redhat.com>2014-06-26 12:37:39 +0200
commit870db2f677dff01750aeec104c90fce3ca0e54be (patch)
tree024f578dd8f3a7c5b26e9c7ecf6b9d82339a272a
parente3de46767683c5050377cc5e683cd6e3d28ea4e9 (diff)
downloadfreeipa-870db2f677dff01750aeec104c90fce3ca0e54be.tar.gz
freeipa-870db2f677dff01750aeec104c90fce3ca0e54be.tar.xz
freeipa-870db2f677dff01750aeec104c90fce3ca0e54be.zip
webui: rebase user password dialog on password dialog and add otp support
https://fedorahosted.org/freeipa/ticket/4262 Reviewed-By: Endi Sukma Dewata <edewata@redhat.com>
-rw-r--r--install/ui/src/freeipa/dialogs/password.js11
-rw-r--r--install/ui/src/freeipa/ipa.js28
-rw-r--r--install/ui/src/freeipa/user.js187
-rw-r--r--ipatests/test_webui/test_user.py4
4 files changed, 75 insertions, 155 deletions
diff --git a/install/ui/src/freeipa/dialogs/password.js b/install/ui/src/freeipa/dialogs/password.js
index 35f96e4b7..fa672901d 100644
--- a/install/ui/src/freeipa/dialogs/password.js
+++ b/install/ui/src/freeipa/dialogs/password.js
@@ -51,6 +51,7 @@ dialogs.password.default_fields_pre_op = function(spec) {
spec.width = spec.width || 400;
spec.sections = spec.sections || [
{
+ name: 'general',
fields: [
{
name: name,
@@ -193,7 +194,7 @@ dialogs.password.dialog = function(spec) {
for (var j=0; j<fields.length; j++) {
var field = fields[j];
var values = field.save();
- if (!values || values.length === 0) continue;
+ if (!values || values.length === 0 || !field.enabled) continue;
if (field.flags.indexOf('no_command') > -1) continue;
if (values.length === 1) {
@@ -212,10 +213,12 @@ dialogs.password.dialog = function(spec) {
that.create_command = function() {
var options = that.make_otions();
+ var entity = null;
+ if (that.entity) entity = that.entity.name;
var command = rpc.command({
- entity: that.entity.name,
+ entity: entity,
method: that.method,
- args: that.pkeys,
+ args: that.args,
options: options,
on_success: function(data) {
that.on_success();
@@ -301,7 +304,7 @@ dialogs.password.action = function(spec) {
ds.$type = 'password';
}
var dialog = builder.build('dialog', ds);
- dialog.pkeys = facet.get_pkeys();
+ dialog.args = facet.get_pkeys();
dialog.succeeded.attach(function() {
if (that.refresh) facet.refresh();
});
diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js
index 66d92b6e0..be671d8f4 100644
--- a/install/ui/src/freeipa/ipa.js
+++ b/install/ui/src/freeipa/ipa.js
@@ -619,20 +619,20 @@ IPA.update_password_expiration = function() {
* @member IPA
*/
IPA.password_selfservice = function() {
- var reset_dialog = IPA.user_password_dialog({
- pkey: IPA.whoami.uid[0],
- on_success: function() {
- var command = IPA.get_whoami_command();
- var orig_on_success = command.on_success;
- command.on_success = function(data, text_status, xhr) {
- orig_on_success.call(this, data, text_status, xhr);
- IPA.update_password_expiration();
- };
- command.execute();
-
- IPA.notify_success(text.get('@i18n:password.password_change_complete'));
- reset_dialog.close();
- }
+ var reset_dialog = builder.build('dialog', {
+ $type: 'user_password',
+ args: [IPA.whoami.uid[0]]
+ });
+ reset_dialog.succeeded.attach(function() {
+ var command = IPA.get_whoami_command();
+ var orig_on_success = command.on_success;
+ command.on_success = function(data, text_status, xhr) {
+ orig_on_success.call(this, data, text_status, xhr);
+ IPA.update_password_expiration();
+ };
+ command.execute();
+
+ IPA.notify_success(text.get('@i18n:password.password_change_complete'));
});
reset_dialog.open();
};
diff --git a/install/ui/src/freeipa/user.js b/install/ui/src/freeipa/user.js
index 3685b116a..73298093b 100644
--- a/install/ui/src/freeipa/user.js
+++ b/install/ui/src/freeipa/user.js
@@ -22,18 +22,20 @@
*/
define([
+ './builder',
'./ipa',
'./jquery',
'./phases',
'./reg',
'./rpc',
'./text',
+ './dialogs/password',
'./details',
'./search',
'./association',
'./entity',
'./certificate'],
- function(IPA, $, phases, reg, rpc, text) {
+ function(builder, IPA, $, phases, reg, rpc, text, password_dialog) {
/**
* User module
@@ -509,155 +511,57 @@ IPA.user_password_widget = function(spec) {
return that;
};
-IPA.user_password_dialog = function(spec) {
+IPA.user.password_dialog_pre_op0 = function(spec) {
- spec = spec || {};
+ spec.password_name = spec.password_name || 'password';
+ return spec;
+};
- spec.width = spec.width || 400;
- spec.title = spec.title || '@i18n:password.reset_password';
- spec.sections = spec.sections || [];
+IPA.user.password_dialog_pre_op = function(spec) {
- spec.sections.push(
- {
- name: 'input',
- fields: [
- {
- name: 'current_password',
- label: '@i18n:password.current_password',
- $type: 'password',
- required: true
- },
- {
- name: 'password1',
- label: '@i18n:password.new_password',
- $type: 'password',
- required: true
- },
- {
- name: 'password2',
- label: '@i18n:password.verify_password',
- $type: 'password',
- validators: [{
- $type: 'same_password',
- other_field: 'password1'
- }],
- required: true
- }
- ]
- });
+ spec.sections[0].fields.splice(0, 0, {
+ name: 'current_password',
+ label: '@i18n:password.current_password',
+ $type: 'password',
+ required: true
+ }, {
+ name: 'otp',
+ label: '@i18n:password.otp',
+ $type: 'password'
+ });
- var that = IPA.dialog(spec);
+ spec.method = spec.method || 'passwd';
- IPA.confirm_mixin().apply(that);
+ return spec;
+};
- that.success_handler = spec.on_success;
- that.error_handler = spec.on_error;
- that.pkey = spec.pkey;
+IPA.user.password_dialog = function(spec) {
+
+ var that = password_dialog.dialog(spec);
that.is_self_service = function() {
- var self_service = that.pkey === IPA.whoami.uid[0];
+ var self_service = that.args[0] === IPA.whoami.uid[0];
return self_service;
};
that.open = function() {
-
- var self_service = that.is_self_service();
- var section = that.widgets.get_widget('input');
- var current_password_f = that.fields.get_field('current_password');
-
that.dialog_open();
- section.set_row_visible('current_password', self_service);
- current_password_f.set_required(self_service);
- that.focus_first_element();
- };
-
- that.create_buttons = function() {
-
- that.create_button({
- name: 'reset_password',
- label: '@i18n:password.reset_password',
- click: that.on_reset_click
- });
-
- that.create_button({
- name: 'cancel',
- label: '@i18n:buttons.cancel',
- click: function() {
- that.close();
- }
- });
- };
-
- that.on_confirm = function() {
- that.on_reset_click();
- };
-
- that.on_reset_click = function() {
-
- if (!that.validate()) return;
var self_service = that.is_self_service();
+ var current_pw_f = that.fields.get_field('current_password');
+ var current_pw_w = that.widgets.get_widget('general.current_password');
+ var otp_f = that.fields.get_field('otp');
+ var otp_w = that.widgets.get_widget('general.otp');
- var record = {};
- that.save(record);
+ current_pw_f.set_required(self_service);
+ current_pw_f.set_enabled(self_service);
+ current_pw_w.set_visible(self_service);
+ otp_f.set_enabled(self_service);
+ otp_w.set_visible(self_service);
- var current_password = self_service ? record.current_password[0] : undefined;
- var new_password = record.password1[0];
- var repeat_password = record.password2[0];
-
- that.set_password(
- that.pkey,
- current_password,
- new_password,
- that.on_reset_success,
- that.on_reset_error);
- };
-
- that.set_password = function(pkey, current_password, password, on_success, on_error) {
-
- var command = rpc.command({
- method: 'passwd',
- args: [ pkey ],
- options: {
- current_password: current_password,
- password: password
- },
- on_success: on_success,
- on_error: on_error
- });
-
- command.execute();
- };
-
- that.on_reset_success = function(data, text_status, xhr) {
-
- if (that.success_handler) {
- that.success_handler.call(this, data, text_status, xhr);
- } else {
- IPA.notify_success('@i18n:password.password_change_complete');
- that.close();
-
- // refresh password expiration field
- that.facet.refresh();
-
- if (that.is_self_service()) {
- var command = IPA.get_whoami_command();
- command.execute();
- }
- }
- };
-
- that.on_reset_error = function(xhr, text_status, error_thrown) {
-
- if (that.error_handler) {
- that.error_handler.call(this, xhr, text_status, error_thrown);
- } else {
- that.close();
- }
+ that.focus_first_element();
};
- that.create_buttons();
-
return that;
};
@@ -672,10 +576,17 @@ IPA.user.reset_password_action = function(spec) {
that.execute_action = function(facet) {
- var dialog = IPA.user_password_dialog({
- entity: facet.entity,
- facet: facet,
- pkey: facet.get_pkey()
+ var dialog = builder.build('dialog', {
+ $type: 'user_password',
+ args: [facet.get_pkey()]
+ });
+
+ dialog.succeeded.attach(function() {
+ facet.refresh();
+ if (dialog.is_self_service()) {
+ var command = IPA.get_whoami_command();
+ command.execute();
+ }
});
dialog.open();
@@ -688,8 +599,14 @@ exp.entity_spec = make_spec();
exp.register = function() {
var e = reg.entity;
var a = reg.action;
+ var d = reg.dialog;
e.register({type: 'user', spec: exp.entity_spec});
a.register('reset_password', IPA.user.reset_password_action);
+ d.copy('password', 'user_password', {
+ factory: IPA.user.password_dialog,
+ pre_ops: [IPA.user.password_dialog_pre_op]
+ });
+ d.register_pre_op('user_password', IPA.user.password_dialog_pre_op0, true);
};
phases.on('registration', exp.register);
diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py
index 766fdafb4..4c189db89 100644
--- a/ipatests/test_webui/test_user.py
+++ b/ipatests/test_webui/test_user.py
@@ -246,7 +246,7 @@ class test_user(UI_driver):
self.assert_dialog()
fields = [
- ('password', 'password1', password),
+ ('password', 'password', password),
('password', 'password2', password),
]
@@ -254,6 +254,6 @@ class test_user(UI_driver):
fields.append(('password', 'current_password', current))
self.fill_fields(fields)
- self.dialog_button_click('reset_password')
+ self.dialog_button_click('confirm')
self.wait_for_request(n=3)
self.assert_no_error_dialog()