From c9ec2062e27a6dca58a6d6257c4cdd5a95b758fc Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 27 Apr 2010 15:52:45 +0200 Subject: [PATCH] LSformElement_password : Added a view hashed password button. --- .../LSobjects/config.LSobjects.LSpeople.php | 1 + public_html/images/default/view_hash.png | Bin 0 -> 779 bytes .../class/class.LSformElement_password.php | 20 +++++++++++ .../js/LSformElement_password_field.js | 33 ++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 public_html/images/default/view_hash.png diff --git a/public_html/conf/LSobjects/config.LSobjects.LSpeople.php b/public_html/conf/LSobjects/config.LSobjects.LSpeople.php index b2c8fe1a..5a27e3b8 100644 --- a/public_html/conf/LSobjects/config.LSobjects.LSpeople.php +++ b/public_html/conf/LSobjects/config.LSobjects.LSpeople.php @@ -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 index 0000000000000000000000000000000000000000..d8e23ec9329a160181b5dd14079e95d769e681ff GIT binary patch literal 779 zcmV+m1N8ifP)JNR5;6R zlTA!qRTRg6@6BT%D1r!D5(}0f7+??^@jDV1BqUmldz&sajk_i;>)xf?E={XR8-;~U zTChZ*#`+PPnvkG?B9K6gb;1k-Grarmz2~@iGbqYQZccJ@@9+Ho=bjs=Diaqz9#GZK z6$&UXDT*qfN}BX=iMLp@yMFu12i*V>>4EbKPv!bMgZqE&qFTEIDNIm-;%=D(qliYQ zs74BaS9AR*gV%;m(%F$iQv#xrR+Y4RdrKpY4G}ND`5s3As6Lz<=wkZrZxjj@R0II2 zsZd2lDV8e4CgI;vwLlPMBc2@WqUW(zya!c5MDbqnA~;bFV#{Zf3&#Nz?}g3#C9+{1 zaU5e!f|GRLks+$f()K_-qIwJf5HC1yF~;!Lb3Lj2R2{0y<@sND;$V`C&#p3ADg0l7 z^@6t!=R-bS_!(mz&MV#tj({OI&ohH1n)~19#3LVZ@5A2l(-&7~4gt;yiM1pG8rBok z)j_C8AoRxbjPfsp$*d@79`#bsiTxjP*D#STEJAbcVmul6xIr zS)!rsabmwk$LMgQD;F;PqreN+Sd8_l9j_!+$e*qiTi77Xx@76B~49=xNSlyLfC}bgym~1@zP4^d{i5l#Ce=?7%Ny2`rHqUMBniA zD`RMKi@@)(c=LdyP$Uq`)<)^=vsc%r4twCe;uD`*5aEU9pBNrJLz2Hl6g9IrmoU5c z248PRkTT2n_t&YFV58fe*<5d*O+HQosR$j002ov JPDHLkV1g02XZ-*G literal 0 HcmV?d00001 diff --git a/public_html/includes/class/class.LSformElement_password.php b/public_html/includes/class/class.LSformElement_password.php index dce28f98..b59d9d58 100644 --- a/public_html/includes/class/class.LSformElement_password.php +++ b/public_html/includes/class/class.LSformElement_password.php @@ -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] + ); + } + } + } + } + } + } ?> diff --git a/public_html/includes/js/LSformElement_password_field.js b/public_html/includes/js/LSformElement_password_field.js index 4d6e3883..c447bfbd 100644 --- a/public_html/includes/js/LSformElement_password_field.js +++ b/public_html/includes/js/LSformElement_password_field.js @@ -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'); + } + } } });