The reset password dialog for user has been modified to provide
a field to specify the current password when changing the user's
own password.

Ticket #2065

--
Endi S. Dewata
From 004bd7f1676255508fe11cf87e059607978f7593 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Fri, 4 Nov 2011 13:48:22 -0500
Subject: [PATCH] Added current password field.

The reset password dialog for user has been modified to provide
a field to specify the current password when changing the user's
own password.

Ticket #2065
---
 install/ui/test/data/ipa_init.json |    2 ++
 install/ui/user.js                 |   34 ++++++++++++++++++++++++++++------
 ipalib/plugins/internal.py         |    2 ++
 3 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 9ebb52aaffa1e412b014d12cfd8e330163e28a8d..44e6b8fc679fda6f8a8c1200c2d121df130cac54 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -332,6 +332,8 @@
                         }
                     },
                     "password": {
+                        "current_password": "Current Password",
+                        "current_password_required": "Current password is required",
                         "new_password": "New Password",
                         "password_change_complete": "Password change complete",
                         "password_must_match": "Passwords must match",
diff --git a/install/ui/user.js b/install/ui/user.js
index 60958cb43cf3f853c370554162600733f3d3d90d..04140afd9a8c00f89122186fcdf0c42e15c336a6 100644
--- a/install/ui/user.js
+++ b/install/ui/user.js
@@ -325,18 +325,29 @@ IPA.user_password_widget = function(spec) {
 
     that.show_dialog = function() {
 
+        that.pkey = IPA.nav.get_state('user-pkey');
+        that.self_service = that.pkey === IPA.whoami.uid[0];
+
         var dialog = IPA.dialog({
             title: IPA.messages.password.reset_password,
             width: 400
         });
 
-        var password1 = dialog.add_field(IPA.text_widget({
+        if (that.self_service) {
+            dialog.add_field(IPA.text_widget({
+                name: 'current_password',
+                label: IPA.messages.password.current_password,
+                type: 'password'
+            }));
+        }
+
+        dialog.add_field(IPA.text_widget({
             name: 'password1',
             label: IPA.messages.password.new_password,
             type: 'password'
         }));
 
-        var password2 = dialog.add_field(IPA.text_widget({
+        dialog.add_field(IPA.text_widget({
             name: 'password2',
             label: IPA.messages.password.verify_password,
             type: 'password'
@@ -350,6 +361,16 @@ IPA.user_password_widget = function(spec) {
                 var record = {};
                 dialog.save(record);
 
+                var current_password;
+
+                if (that.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];
 
@@ -359,6 +380,7 @@ IPA.user_password_widget = function(spec) {
                 }
 
                 that.set_password(
+                    current_password,
                     new_password,
                     function(data, text_status, xhr) {
                         alert(IPA.messages.password.password_change_complete);
@@ -382,20 +404,20 @@ IPA.user_password_widget = function(spec) {
         dialog.open(that.container);
     };
 
-    that.set_password = function(password, on_success, on_error) {
-        var user_pkey = IPA.nav.get_state('user-pkey');
+    that.set_password = function(current_password, password, on_success, on_error) {
 
         var args;
-        if (user_pkey === IPA.whoami.uid[0]) {
+        if (that.self_service) {
             args = [];
         } else {
-            args = [user_pkey];
+            args = [that.pkey];
         }
 
         var command = IPA.command({
             method: 'passwd',
             args: args,
             options: {
+                current_password: current_password,
                 password: password
             },
             on_success: on_success,
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 8c5b0955b1c2e2c1c0c2b15c0e026e24f9b3eefe..63eeba057eef9177db08129b49fdf266898df815 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -426,6 +426,8 @@ class i18n_messages(Command):
             },
         },
         "password": {
+            "current_password": _("Current Password"),
+            "current_password_required": _("Current password is required"),
             "new_password": _("New Password"),
             "password_change_complete": _("Password change complete"),
             "password_must_match": _("Passwords must match"),
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to