From d1fe43c56fe211db035bd6a30ac06fcfc6f61557 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 18 Jun 2012 15:46:33 +0200 Subject: Same password validator This patch adds validator which compares passwords in two fields. In future it should be used in various password reset dialogs. A flags attribute was added to field. It's purpose is to define control flags. This patch uses it in details facet and adder dialog to not include fields to command option if the field has 'no_command' flag. Therefore there is no need to use hacks such as disabling of field or removing a value from command's option map when a non-command field is needed (ie verify password). https://fedorahosted.org/freeipa/ticket/2829 --- install/ui/field.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'install/ui/field.js') diff --git a/install/ui/field.js b/install/ui/field.js index 03401dff..84ec0c4d 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -50,6 +50,7 @@ IPA.field = function(spec) { that.writable = true; that.enabled = spec.enabled === undefined ? true : spec.enabled; + that.flags = spec.flags || []; that.undo = spec.undo === undefined ? true : spec.undo; @@ -480,6 +481,29 @@ IPA.unsupported_validator = function(spec) { return that; }; +IPA.same_password_validator = function(spec) { + + spec = spec || {}; + + var that = IPA.validator(spec); + that.other_field = spec.other_field; + + that.message = spec.message || IPA.messages.password.password_must_match; + + that.validate = function(value, context) { + + var other_field = context.container.fields.get_field(that.other_field); + var other_value = other_field.save(); + var this_value = context.save(); + + if (IPA.array_diff(this_value, other_value)) return that.false_result(); + + return that.true_result(); + }; + + return that; +}; + IPA.checkbox_field = function(spec) { spec = spec || {}; -- cgit