mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-20 07:23:47 +01:00
- LSformElement_password : autogénération de password
- index_ajax.php : Mutalisation de la gestion du retour de l'"imgload"
This commit is contained in:
parent
683916b6e6
commit
418e63d2a3
6 changed files with 184 additions and 24 deletions
|
@ -406,6 +406,12 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
|
|||
'label' => _('Mot de passe'),
|
||||
'ldap_type' => 'password',
|
||||
'html_type' => 'password',
|
||||
'html_options' => array(
|
||||
'generationTool' => true,
|
||||
'autoGenerate' => false,
|
||||
'chars' => 'abcdefgh',
|
||||
'lenght' => 5
|
||||
),
|
||||
'required' => 1,
|
||||
'rights' => array(
|
||||
'self' => 'w',
|
||||
|
|
|
@ -67,7 +67,29 @@ class LSformElement_password extends LSformElement {
|
|||
function getDisplay(){
|
||||
$return = $this -> getLabelInfos();
|
||||
if (!$this -> isFreeze()) {
|
||||
$return['html'] = "<input type='password' name='".$this -> name."[]' />\n";
|
||||
$numberId=rand();
|
||||
$value_txt='';
|
||||
$input_type='password';
|
||||
$autogenerate_html='';
|
||||
$class_txt='';
|
||||
|
||||
// AutoGenerate
|
||||
if (($this -> params['html_options']['generationTool'])||(!isset($this -> params['html_options']['generationTool']))) {
|
||||
if (($this -> params['html_options']['autoGenerate'])&&(empty($this -> values))) {
|
||||
$value_txt="value='".$this->generatePassword()."'";
|
||||
$input_type='text';
|
||||
}
|
||||
$class_txt="class='LSformElement_password_generate'";
|
||||
$id = "LSformElement_password_generate_btn_".$this -> name."_".$numberId;
|
||||
$autogenerate_html = "<img src='templates/images/generate.png' id='$id' class='LSformElement_password_generate_btn'/>\n";
|
||||
}
|
||||
|
||||
$id = "LSformElement_password_".$this -> name."_".$numberId;
|
||||
$return['html'] = "<input type='$input_type' name='".$this -> name."[]' $value_txt id='$id' $class_txt/>\n";
|
||||
$return['html'] .= $autogenerate_html;
|
||||
$id = "LSformElement_password_view_btn_".$this -> name."_".$numberId;
|
||||
$return['html'] .= "<img src='templates/images/view.png' id='$id' class='LSformElement_password_view_btn'/>\n";
|
||||
|
||||
if (!empty($this -> values)) {
|
||||
$return['html'] .= "* "._('Modification uniquement').".";
|
||||
}
|
||||
|
@ -83,6 +105,28 @@ class LSformElement_password extends LSformElement {
|
|||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function generatePassword() {
|
||||
if (isset($this -> params['html_options']['chars'])) {
|
||||
$chars=$this -> params['html_options']['chars'];
|
||||
}
|
||||
else {
|
||||
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||
}
|
||||
$nbChars=strlen($chars);
|
||||
|
||||
if (isset($this -> params['html_options']['lenght'])) {
|
||||
$lenght=$this -> params['html_options']['lenght'];
|
||||
}
|
||||
else {
|
||||
$lenght=8;
|
||||
}
|
||||
$retVal='';
|
||||
for($i=0;$i<$lenght;$i++){
|
||||
$retVal.=$chars[rand(0,$nbChars-1)];
|
||||
}
|
||||
return $retVal;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -24,6 +24,16 @@ var LSform = new Class({
|
|||
el.addEvent('click',this.onImageDeleteBtnClick.bind(this,el));
|
||||
}, this);
|
||||
|
||||
this.LSformElement_password_generate_inputHistory = [];
|
||||
$$('img.LSformElement_password_generate_btn').each(function(el) {
|
||||
el.addEvent('click',this.onLSformElement_password_generate_btnClick.bind(this,el));
|
||||
}, this);
|
||||
|
||||
$$('img.LSformElement_password_view_btn').each(function(el) {
|
||||
el.addEvent('click',this.onLSformElement_password_view_btnClick.bind(this,el));
|
||||
}, this);
|
||||
this.initialiseLSformElement_password_generate();
|
||||
|
||||
this.initialiseLSformElement_select_object();
|
||||
},
|
||||
|
||||
|
@ -37,6 +47,12 @@ var LSform = new Class({
|
|||
}, this);
|
||||
},
|
||||
|
||||
initialiseLSformElement_password_generate: function() {
|
||||
$$('input.LSformElement_password_generate').each(function(el) {
|
||||
el.addEvent('keyup',this.onLSformElement_password_generate_inputKeyUp.bind(this,el));
|
||||
}, this);
|
||||
},
|
||||
|
||||
zoomImg: function(event, src) {
|
||||
new Event(event).stop();
|
||||
varLSsmoothbox.openImg(src);
|
||||
|
@ -58,20 +74,21 @@ var LSform = new Class({
|
|||
img: img.id
|
||||
};
|
||||
LSdebug(data);
|
||||
varLSdefault.loadingImgDisplay(img);
|
||||
data.imgload = varLSdefault.loadingImgDisplay(img);
|
||||
new Ajax('index_ajax.php', {data: data, onComplete: this.onAddFieldBtnClickComplete.bind(this)}).request();
|
||||
},
|
||||
|
||||
onAddFieldBtnClickComplete: function(responseText, responseXML) {
|
||||
varLSdefault.loadingImgHide();
|
||||
var data = Json.evaluate(responseText);
|
||||
LSdebug(data);
|
||||
if ( data ) {
|
||||
if ( typeof(data.LSerror) != "undefined" ) {
|
||||
varLSdefault.loadingImgHide();
|
||||
varLSdefault.displayError(data.LSerror);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
varLSdefault.loadingImgHide(data.imgload);
|
||||
var li = new Element('li');
|
||||
var img = $(data.img);
|
||||
li.setHTML(data.html);
|
||||
|
@ -148,7 +165,6 @@ var LSform = new Class({
|
|||
|
||||
onLSformElement_select_object_addBtnClickComplete: function(responseText, responseXML) {
|
||||
var data = Json.evaluate(responseText);
|
||||
LSdebug(data);
|
||||
if ( data ) {
|
||||
if ( typeof(data.LSerror) != "undefined" ) {
|
||||
varLSdefault.displayError(data.LSerror);
|
||||
|
@ -196,6 +212,86 @@ var LSform = new Class({
|
|||
|
||||
LSformElement_select_object_deleteBtn: function(img) {
|
||||
img.getParent().remove();
|
||||
},
|
||||
|
||||
onLSformElement_password_generate_btnClick: function(img) {
|
||||
var getAttrNameAndId = /LSformElement_password_generate_btn_(.*)_([0-9]*)/
|
||||
var getAttrNameAndIdValues = getAttrNameAndId.exec(img.id);
|
||||
var attrName = getAttrNameAndIdValues[1];
|
||||
var fieldId = 'LSformElement_password_' + attrName + '_' + getAttrNameAndIdValues[2];
|
||||
|
||||
var data = {
|
||||
template: 'LSform',
|
||||
action: 'generatePassword',
|
||||
attribute: attrName,
|
||||
objecttype: $('LSform_objecttype').value,
|
||||
idform: $('LSform_idform').value,
|
||||
fieldId: fieldId
|
||||
};
|
||||
data.imgload=varLSdefault.loadingImgDisplay(img);
|
||||
new Ajax('index_ajax.php', {data: data, onComplete: this.onLSformElement_password_generate_btnClickComplete.bind(this)}).request();
|
||||
},
|
||||
|
||||
onLSformElement_password_generate_btnClickComplete: function(responseText, responseXML) {
|
||||
var data = Json.evaluate(responseText);
|
||||
if ( data ) {
|
||||
if ( typeof(data.LSerror) != "undefined" ) {
|
||||
varLSdefault.loadingImgHide();
|
||||
varLSdefault.displayError(data.LSerror);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
varLSdefault.loadingImgHide(data.imgload);
|
||||
this.changeInputType($(data.fieldId),'text');
|
||||
$(data.fieldId).value=data.generatePassword;
|
||||
this.LSformElement_password_generate_inputHistory[data.fieldId]=data.generatePassword;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onLSformElement_password_generate_inputKeyUp: function(input) {
|
||||
if (input.type=='text') {
|
||||
if((this.LSformElement_password_generate_inputHistory[input.id]!=input.value)&&(typeof(this.LSformElement_password_generate_inputHistory[input.id])!='undefined')&&(this.LSformElement_password_generate_inputHistory[input.id]!='')) {
|
||||
this.onLSformElement_password_generate_inputModify(input);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onLSformElement_password_generate_inputModify: function(input) {
|
||||
input.value='';
|
||||
input = this.changeInputType(input,'password');
|
||||
this.LSformElement_password_generate_inputHistory[input.id]='';
|
||||
input.focus();
|
||||
},
|
||||
|
||||
onLSformElement_password_view_btnClick: function(img) {
|
||||
var getAttrNameAndId = /LSformElement_password_view_btn_(.*)_([0-9]*)/
|
||||
var getAttrNameAndIdValues = getAttrNameAndId.exec(img.id);
|
||||
var attrName = getAttrNameAndIdValues[1];
|
||||
var fieldId = 'LSformElement_password_' + attrName + '_' + getAttrNameAndIdValues[2];
|
||||
|
||||
input = $(fieldId);
|
||||
|
||||
if (input.type=='password') {
|
||||
input = this.changeInputType(input,'text');
|
||||
}
|
||||
else {
|
||||
input = this.changeInputType(input,'password');
|
||||
}
|
||||
input.focus();
|
||||
},
|
||||
|
||||
changeInputType: function(input,newType) {
|
||||
var newInput = new Element('input');
|
||||
newInput.setProperty('name',input.getProperty('name'));
|
||||
newInput.setProperty('type',newType);
|
||||
newInput.setProperty('class',input.getProperty('class'));
|
||||
newInput.setProperty('id',input.getProperty('id'));
|
||||
newInput.setProperty('value',input.getProperty('value'));
|
||||
newInput.injectAfter(input);
|
||||
input.remove();
|
||||
this.initialiseLSformElement_password_generate();
|
||||
return newInput;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ switch($_REQUEST['template']) {
|
|||
$list = $GLOBALS['LSsession'] -> getSubDnLdapServerOptions($_SESSION['LSsession_topDn']);
|
||||
if (is_string($list)) {
|
||||
$list="<select name='LSsession_topDn' id='LSsession_topDn'>".$list."</select>";
|
||||
$data = array('list_topDn' => $list, 'imgload' => $_REQUEST['imgload']);
|
||||
$data = array('list_topDn' => $list);
|
||||
}
|
||||
else if (is_array($list)){
|
||||
$data = array('LSerror' => $GLOBALS['LSerror']->getErrors());
|
||||
|
@ -59,7 +59,7 @@ switch($_REQUEST['template']) {
|
|||
}
|
||||
break;
|
||||
case 'refreshField':
|
||||
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) && (isset($_REQUEST['imgload'])) ) {
|
||||
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn'])) && (isset($_REQUEST['idform'])) ) {
|
||||
$object = new $_REQUEST['objecttype']();
|
||||
//$object -> loadData($_REQUEST['objectdn']);
|
||||
$form = $object -> getForm($_REQUEST['idform']);
|
||||
|
@ -67,14 +67,31 @@ switch($_REQUEST['template']) {
|
|||
$val = $field -> getDisplay(true);
|
||||
if ( $val ) {
|
||||
$data = array(
|
||||
'html' => $val['html'],
|
||||
'imgload' => $_REQUEST['imgload']
|
||||
'html' => $val['html']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'LSerror' => $GLOBALS['LSerror']->getErrors(),
|
||||
'imgload' => $_REQUEST['imgload']
|
||||
'LSerror' => $GLOBALS['LSerror']->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'generatePassword':
|
||||
if ((isset($_REQUEST['attribute'])) && (isset($_REQUEST['objecttype'])) && (isset($_REQUEST['fieldId'])) && (isset($_REQUEST['idform'])) ) {
|
||||
$object = new $_REQUEST['objecttype']();
|
||||
$form = $object -> getForm($_REQUEST['idform']);
|
||||
$field=$form -> getElement($_REQUEST['attribute']);
|
||||
$val = $field -> generatePassword();
|
||||
if ( $val ) {
|
||||
$data = array(
|
||||
'generatePassword' => $val,
|
||||
'fieldId' => $_REQUEST['fieldId']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'LSerror' => $GLOBALS['LSerror']->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +101,7 @@ switch($_REQUEST['template']) {
|
|||
case 'LSrelation':
|
||||
switch($_REQUEST['action']) {
|
||||
case 'refreshSession':
|
||||
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['href'])) && (isset($_REQUEST['imgload']))) {
|
||||
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['href'])) ) {
|
||||
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
|
||||
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
|
||||
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
|
||||
|
@ -121,7 +138,6 @@ switch($_REQUEST['template']) {
|
|||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
}
|
||||
$data['imgload'] = $_REQUEST['imgload'];
|
||||
}
|
||||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
|
@ -129,7 +145,7 @@ switch($_REQUEST['template']) {
|
|||
}
|
||||
break;
|
||||
case 'refreshList':
|
||||
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['imgload']))) {
|
||||
if (isset($_REQUEST['id'])) {
|
||||
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
|
||||
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
|
||||
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
|
||||
|
@ -177,7 +193,6 @@ switch($_REQUEST['template']) {
|
|||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
}
|
||||
$data['imgload'] = $_REQUEST['imgload'];
|
||||
}
|
||||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
|
@ -185,7 +200,7 @@ switch($_REQUEST['template']) {
|
|||
}
|
||||
break;
|
||||
case 'deleteByDisplayValue':
|
||||
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['value'])) && (isset($_REQUEST['imgload']))) {
|
||||
if ((isset($_REQUEST['id'])) && (isset($_REQUEST['value']))) {
|
||||
if (isset($_SESSION['LSrelation'][$_REQUEST['id']])) {
|
||||
$conf = $_SESSION['LSrelation'][$_REQUEST['id']];
|
||||
if ($GLOBALS['LSsession']->loadLSobject($conf['objectType'])) {
|
||||
|
@ -232,7 +247,6 @@ switch($_REQUEST['template']) {
|
|||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
}
|
||||
$data['imgload'] = $_REQUEST['imgload'];
|
||||
}
|
||||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
|
@ -254,7 +268,6 @@ switch($_REQUEST['template']) {
|
|||
$_SESSION['LSselect'][$_REQUEST['objecttype']][]=$_REQUEST['objectdn'];
|
||||
}
|
||||
}
|
||||
$data=$_REQUEST['imgload'];
|
||||
break;
|
||||
case 'dropLSselectobject-item':
|
||||
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['objectdn']))) {
|
||||
|
@ -268,10 +281,9 @@ switch($_REQUEST['template']) {
|
|||
$_SESSION['LSselect'][$_REQUEST['objecttype']]=$result;
|
||||
}
|
||||
}
|
||||
$data=$_REQUEST['imgload'];
|
||||
break;
|
||||
case 'refreshSession':
|
||||
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['imgload'])) && (isset($_REQUEST['href'])) ) {
|
||||
if ((isset($_REQUEST['objecttype'])) && (isset($_REQUEST['values'])) && (isset($_REQUEST['href'])) ) {
|
||||
$_SESSION['LSselect'][$_REQUEST['objecttype']]=array();
|
||||
$values=json_decode($_REQUEST['values'],false);
|
||||
if (is_array($values)) {
|
||||
|
@ -280,7 +292,6 @@ switch($_REQUEST['template']) {
|
|||
}
|
||||
}
|
||||
$data=array(
|
||||
'imgload' => $_REQUEST['imgload'],
|
||||
'href' => $_REQUEST['href'],
|
||||
'values' => $values
|
||||
);
|
||||
|
@ -288,8 +299,7 @@ switch($_REQUEST['template']) {
|
|||
else {
|
||||
$GLOBALS['LSerror'] -> addErrorCode(1012);
|
||||
$data = array(
|
||||
'LSerror' => $GLOBALS['LSerror']->getErrors(),
|
||||
'imgload' => $_REQUEST['imgload']
|
||||
'LSerror' => $GLOBALS['LSerror']->getErrors()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
@ -301,6 +311,10 @@ if ($GLOBALS['LSerror']->errorsDefined()) {
|
|||
$data['LSerror'] = $GLOBALS['LSerror']->getErrors();
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['imgload'])) {
|
||||
$data['imgload'] = $_REQUEST['imgload'];
|
||||
}
|
||||
|
||||
$debug_txt = debug_print(true);
|
||||
if ($debug_txt != "") {
|
||||
$data['LSdebug'] = $debug_txt;
|
||||
|
|
|
@ -74,6 +74,6 @@ li.LSformElement_select_object_addBtn {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
img.LSformElement_select_object_deleteBtn {
|
||||
img.LSformElement_select_object_deleteBtn, img.LSformElement_password_view_btn, img.LSformElement_password_generate_btn {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
BIN
trunk/templates/images/generate.png
Normal file
BIN
trunk/templates/images/generate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 512 B |
Loading…
Reference in a new issue