LSformElement_password : Added a view hashed password button.
authorBenjamin Renard <brenard@aconit.easter-eggs.fr>
Tue, 27 Apr 2010 13:52:45 +0000 (15:52 +0200)
committerBenjamin Renard <brenard@aconit.easter-eggs.fr>
Tue, 27 Apr 2010 13:52:45 +0000 (15:52 +0200)
public_html/conf/LSobjects/config.LSobjects.LSpeople.php
public_html/images/default/view_hash.png [new file with mode: 0644]
public_html/includes/class/class.LSformElement_password.php
public_html/includes/js/LSformElement_password_field.js

index b2c8fe1..5a27e3b 100644 (file)
@@ -463,6 +463,7 @@ $GLOBALS['LSobjects']['LSpeople'] = array (
       'html_type' => 'password',
       'html_options' => array(
         'generationTool' => true,
+        'viewHash' => true,
         'autoGenerate' => false,
         'lenght' => 8,
         'chars' => array (
diff --git a/public_html/images/default/view_hash.png b/public_html/images/default/view_hash.png
new file mode 100644 (file)
index 0000000..d8e23ec
Binary files /dev/null and b/public_html/images/default/view_hash.png differ
index dce28f9..b59d9d5 100644 (file)
@@ -124,6 +124,7 @@ class LSformElement_password extends LSformElement {
           'generate' => _('Generate a password.'),
           'verify' => _('Compare with stored password.'),
           'view' => _('Display password.'),
+          'viewHash' => _('Display hashed password.'),
           'hide' => _('Hide password.'),
           'mail' => _("The password will be sent by mail if changed. Click to disable automatic notification."),
           'nomail' => _("The password will not be sent if changed. Click to enable automatic notification."),
@@ -137,6 +138,7 @@ class LSformElement_password extends LSformElement {
       
       $params = array(
         'generate' => ($this -> params['html_options']['generationTool']==True),
+        'viewHash' => ($this -> params['html_options']['viewHash']==True),
         'verify' => (!$this -> attr_html -> attribute -> ldapObject-> isNew())
       );
       if (isset($this -> params['html_options']['mail'])) {
@@ -233,6 +235,24 @@ class LSformElement_password extends LSformElement {
       }
     }
   }
+
+  public static function ajax_viewHash(&$data) {
+    if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) ) {
+      if (LSsession ::loadLSobject($_REQUEST['objecttype'])) {
+        $object = new $_REQUEST['objecttype']();
+        $object -> loadData($_REQUEST['objectdn']);
+        if (LSsession::canAccess($_REQUEST['objecttype'],$_REQUEST['objectdn'],null,$_REQUEST['attribute'])) {
+          $values = $object -> getValue($_REQUEST['attribute']);
+          if (is_string($values[0])) {
+            $data = array (
+              'hash' => $values[0]
+            );
+          }
+        }
+      }
+    }
+  }
+
 }
   
 ?>
index 4d6e388..c447bfb 100644 (file)
@@ -7,6 +7,16 @@ var LSformElement_password_field = new Class({
     },
     
     initialiseLSformElement_password_field: function() {
+      // ViewHashBtn
+      if (this.params['viewHash'] && varLSform.objectdn!= "") {
+        this.viewHashBtn = new Element('img');
+        this.viewHashBtn.src = varLSdefault.imagePath('view_hash.png');
+        this.viewHashBtn.addClass('btn');
+        this.viewHashBtn.addEvent('click',this.onViewHashBtnClick.bind(this));
+        this.viewHashBtn.injectAfter(this.input);
+        varLSdefault.addHelpInfo(this.viewHashBtn,'LSformElement_password','viewHash');
+      }
+      
       // Mail
       if (this.params['mail']) {
         if ((this.params.mail['canEdit']==1)||(!$type(this.params.mail['canEdit']))) {
@@ -209,5 +219,28 @@ var LSformElement_password_field = new Class({
         }
         (function(){this.verifyFx.start(this.bgColor);}).delay(1000, this);
       }
+    },
+
+    onViewHashBtnClick: function() {
+      var data = {
+        template:   'LSformElement_password',
+        action:     'viewHash',
+        attribute:  this.name,
+        objecttype: varLSform.objecttype,
+        objectdn:   varLSform.objectdn
+      };
+      data.imgload=varLSdefault.loadingImgDisplay(this.viewHashBtn);
+      new Request({url: 'index_ajax.php', data: data, onSuccess: this.onViewHashBtnClickComplete.bind(this)}).send();
+    },
+    
+    onViewHashBtnClickComplete: function(responseText, responseXML) {
+      var data = JSON.decode(responseText);
+      if ( varLSdefault.checkAjaxReturn(data) ) {
+        if (data.hash) {
+          // ok
+          this.input.value=data.hash;
+          this.changeInputType('view');
+        }
+      }
     }
 });