- config.inc.php : Changement du domaine d'exemple. ls.com existe

- LSmail :
  -> Le sujet n'était pas encore paramètrable d'avance : c'est fait.
  -> Adpatation index_ajax.php
  -> Ajout d'une méthode JS d'export des infos du mail saisie
- LSformElement_password : Ajout d'une possibilité d'envoie du mot de passe
  par mail lors de sa modification
- LSattribute : Ajout d'un binding applicatif pour l'execution de fonction/
  méthode lors d'évenement (a agrémenter)
- LSldapObject : Utilisation des evenements pour le binding onModify des
  attributs
- LSaddons :: Mail : Ajout d'un header 'To:' systématiquement.
- LSform : Ajout de la méthode JS getValue()
This commit is contained in:
Benjamin Renard 2008-10-31 12:12:31 +00:00
parent e0208a456a
commit e340850741
13 changed files with 392 additions and 74 deletions

View file

@ -27,6 +27,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'posixAccount',
'sambaSamAccount',
),
'orderby' => 'displayValue', // Valeurs possibles : 'displayValue' ou 'subDn'
'rdn' => 'uid',
'container_dn' => 'ou=people',
'container_auto_create' => array(
@ -66,6 +67,13 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'label' => _('Identifiant'),
'ldap_type' => 'ascii',
'html_type' => 'text',
'html_options' => array(
'generate_value_format' => '%{givenName:1}.%{sn}',
'autoGenerateOnModify' => true, // default : false
'withoutAccent' => 1,
'replaceSpaces' => '.',
'lowerCase' => 1
),
'required' => 1,
'check_data' => array (
'alphanumeric' => array(
@ -340,7 +348,31 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'generationTool' => true,
'autoGenerate' => false,
'chars' => 'abcdefgh',
'lenght' => 5
'lenght' => 5,
'mail' => array(
'send' => 1,
'ask' => 1,
'subject' => "LSexample : votre nouveau mot de passe",
'msg' => "Votre mot de passe vient d'etre modifie.\nNouveau mot de passe : %{mdp}",
'mail_attr' => 'mail'
)
),
'check_data' => array(
'password' => array(
'msg' => 'Le mot de passe doit contenir entre 8 et 10 caractères.',
'params' => array(
'minLength' => 8,
'maxLength' => 10,
'prohibitedValues' => array(
'azertyui',
'12345678'
),
'regex' => array(
'[a-z]+',
'[0-9]+'
)
)
)
),
'required' => 1,
'rights' => array(

View file

@ -65,7 +65,7 @@ $GLOBALS['LSconfig'] = array(
'recoverPassword' => array(
'mailAttr' => 'mail',
'recoveryHashAttr' => 'lsRecoveryHash',
'recoveryEmailSender' => 'noreply-recover@lsexample.net',
'recoveryEmailSender' => 'noreply-recover@ls.com',
'recoveryHashMail' => array(
'subject' => 'LSexample : Récupération de votre mot de passe.',
'msg' => "Pour poursuivre le processus de récupération de votre mot de passe,\nmerci de cliquer de vous rendre à l'adresse suivante :\n%{url}"
@ -75,7 +75,7 @@ $GLOBALS['LSconfig'] = array(
'msg' => "Votre nouveau mot de passe : %{mdp}"
)
),
'emailSender' => 'noreply@lsexample.net',
'emailSender' => 'noreply@ls.com',
'LSobjects' => array (
'LSeepeople',
'LSeegroup'

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

View file

@ -142,6 +142,7 @@
if (!isset($headers['From']) && ($GLOBALS['LSsession'] -> getEmailSender() != "")) {
$headers['From'] = $GLOBALS['LSsession'] -> getEmailSender();
}
$headers["To"] = $to;
$ret = $mail_obj -> send($to,$headers,$msg);

View file

@ -42,6 +42,8 @@ class LSattribute {
var $is_validate=false;
var $_finalUpdateData=false;
var $_myRights=NULL;
var $_events=array();
var $_objectEvents=array();
/**
* Constructeur
@ -520,6 +522,133 @@ class LSattribute {
return $this -> config['dependAttrs'];
}
/**
* Ajouter une action lors d'un événement
*
* @param[in] $event string Le nom de l'événement
* @param[in] $fct string Le nom de la fonction à exectuer
* @param[in] $params mixed Paramètres pour le lancement de la fonction
* @param[in] $class Nom de la classe possèdant la méthode $fct à executer
*
* @retval void
*/
function addEvent($event,$fct,$params,$class=NULL) {
$this -> _events[$event][] = array(
'function' => $fct,
'params' => $params,
'class' => $class
);
}
/**
* Ajouter une action sur un objet lors d'un événement
*
* @param[in] $event string Le nom de l'événement
* @param[in] $obj object L'objet dont la méthode doit être executé
* @param[in] $meth string Le nom de la méthode
* @param[in] $params mixed Paramètres d'execution de la méthode
*
* @retval void
*/
function addObjectEvent($event,&$obj,$meth,$params=NULL) {
$this -> _objectEvents[$event][] = array(
'obj' => $obj,
'meth' => $meth,
'params' => $params
);
}
/**
* Lance les actions à executer lors d'un événement
*
* @param[in] $event string Le nom de l'événement
*
* @retval boolean True si tout c'est bien passé, false sinon
*/
function fireEvent($event) {
$return = true;
if(isset($this -> config[$event])) {
if (!is_array($this -> config[$event])) {
$funcs = array($this -> config[$event]);
}
else {
$funcs = $this -> config[$event];
}
foreach($funcs as $func) {
if(function_exists($func)) {
if(!$func($this -> ldapObject)) {
$return = false;
}
}
else {
$return = false;
}
}
}
if (is_array($this -> _events[$event])) {
foreach ($this -> _events[$event] as $e) {
if ($e['class']) {
if (class_exists($e['class'])) {
$obj = new $e['class']();
if (method_exists($obj,$e['fct'])) {
try {
$obj -> $e['fct']($e['params']);
}
catch(Exception $er) {
$return = false;
LSdebug("Event ".$event." : Erreur durant l'execution de la méthode ".$e['fct']." de la classe ".$e['class']);
}
}
else {
LSdebug("Event ".$event." : La méthode ".$e['fct']." de la classe ".$e['class']." n'existe pas.");
$return = false;
}
}
else {
$return = false;
LSdebug("Event ".$event." : La classe ".$e['class']." n'existe pas");
}
}
else {
if (function_exists($e['fct'])) {
try {
$e['fct']($e['params']);
}
catch(Exception $er) {
LSdebug("Event ".$event." : Erreur durant l'execution de la function ".$e['fct']);
$return = false;
}
}
else {
LSdebug("Event ".$event." : la function ".$e['fct']." n'existe pas");
$return = false;
}
}
}
}
if (is_array($this -> _objectEvents[$event])) {
foreach ($this -> _objectEvents[$event] as $e) {
if (method_exists($e['obj'],$e['meth'])) {
try {
$e['obj'] -> $e['meth']($e['params']);
}
catch(Exception $er) {
$return = false;
LSdebug("Event ".$event." : Erreur durant l'execution de la méthode ".$e['meth']." sur l'objet.");
}
}
else {
LSdebug("Event ".$event." : La méthode ".$e['meth']." de l'objet n'existe pas.");
$return = false;
}
}
}
return $return;
}
}
?>

View file

@ -34,6 +34,8 @@ class LSformElement_password extends LSformElement {
var $fieldTemplate = 'LSformElement_password_field.tpl';
var $template = 'LSformElement_password.tpl';
var $sendMail = false;
/**
* Recupère la valeur de l'élement passée en POST
@ -56,6 +58,40 @@ class LSformElement_password extends LSformElement {
$this -> form -> _notUpdate[$this -> name] == true;
return true;
}
//Mail
if (isset($_POST['LSformElement_password_'.$this -> name.'_send'])) {
if ($_POST['LSformElement_password_'.$this -> name.'_send']==1) {
$this -> sendMail = true;
LSdebug ('send by form');
}
}
else if ($this -> params['html_options']['mail']['send']==1) {
$this -> sendMail = true;
LSdebug ('send by config');
}
if ($this -> sendMail && $GLOBALS['LSsession'] -> loadLSaddon('mail')) {
$msg = getFData($this -> params['html_options']['mail']['msg'],$return[$this -> name][0]);
$subject = $this -> params['html_options']['mail']['subject'];
if (isset($_POST['LSformElement_password_'.$this -> name.'_msg'])) {
$msgInfos = json_decode($_POST['LSformElement_password_'.$this -> name.'_msg']);
if ($msgInfos -> subject) {
$subject = $msgInfos -> subject;
}
if ($msgInfos -> msg) {
$msg = getFData($msgInfos -> msg,$return[$this -> name][0]);
}
if ($msgInfos -> mail) {
$mail = $msgInfos -> mail;
}
}
$this -> sendMail = array (
'subject' => $subject,
'msg' => $msg,
'mail' => $mail
);
$this -> attr_html -> attribute -> addObjectEvent('after_modify',$this,'send');
}
}
return $retval;
}
@ -80,6 +116,9 @@ class LSformElement_password extends LSformElement {
'generate' => ($this -> params['html_options']['generationTool']==True),
'verify' => (!$this -> attr_html -> attribute -> ldapObject-> isNew())
);
if (isset($this -> params['html_options']['mail'])) {
$params['mail'] = $this -> params['html_options']['mail'];
}
$GLOBALS['LSsession'] -> addJSconfigParam($this -> name,$params);
$GLOBALS['LSsession'] -> addJSscript('LSformElement_password_field.js');
@ -99,6 +138,39 @@ class LSformElement_password extends LSformElement {
}
return $GLOBALS['LSsession'] -> checkUserPwd($this -> attr_html -> attribute -> ldapObject,$pwd);
}
function send($params) {
if (is_array($this -> sendMail)) {
$mail = (String)$this -> sendMail['mail'];
Lsdebug($mail);
if ($mail=="") {
$mail_attr = $this -> attr_html -> attribute -> ldapObject -> attrs[$this -> params['html_options']['mail']['mail_attr']];
if ($mail_attr instanceOf LSattribute) {
$mail = $mail_attr -> getValue();
$mail=$mail[0];
}
else {
LSdebug("L'attribut $mail_attr pour l'envoie du nouveau mot de passe n'existe pas.");
return;
}
}
if (checkEmail($mail,NULL,true)) {
if (sendMail(
$mail,
$this -> sendMail['subject'],
$this -> sendMail['msg']
)) {
$GLOBALS['LSsession'] -> addInfo(_('Mail de changement de mot de passe envoyé.'));
}
}
else {
LSdebug('Adresse mail incorrect : '.$mail);
return;
}
}
return true;
}
}
?>

View file

@ -318,26 +318,7 @@ class LSldapObject {
}
// $this -> attrs[*] => before_modify
foreach($new_data as $attr_name => $attr_val) {
if(isset($this -> config['attrs'][$attr_name]['before_modify'])) {
if (!is_array($this -> config['attrs'][$attr_name]['before_modify'])) {
$funcs = array($this -> config['attrs'][$attr_name]['before_modify']);
}
else {
$funcs = $this -> config['attrs'][$attr_name]['before_modify'];
}
foreach($funcs as $func) {
if(function_exists($func)) {
if(!$func($this)) {
$GLOBALS['LSerror'] -> addErrorCode(309,array('func' => $func,'attr' => $attr_name));
return;
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(308,array('func' => $func,'attr' => $attr_name));
return;
}
}
}
$this -> attrs[$attr_name] -> fireEvent('before_modify');
}
if ($this -> submitChange($idForm)) {
@ -364,26 +345,7 @@ class LSldapObject {
// $this -> attrs[*] => After Modify
foreach($new_data as $attr_name => $attr_val) {
if(isset($this -> config['attrs'][$attr_name]['after_modify'])) {
if (!is_array($this -> config['attrs'][$attr_name]['after_modify'])) {
$funcs = array($this -> config['attrs'][$attr_name]['after_modify']);
}
else {
$funcs = $this -> config['attrs'][$attr_name]['after_modify'];
}
foreach($funcs as $func) {
if(function_exists($func)) {
if(!$func($this)) {
$GLOBALS['LSerror'] -> addErrorCode(307,array('func' => $func,'attr' => $attr_name));
return;
}
}
else {
$GLOBALS['LSerror'] -> addErrorCode(306,array('func' => $func,'attr' => $attr_name));
return;
}
}
}
$this -> attrs[$attr_name] -> fireEvent('after_modify');
}
return true;
}

View file

@ -33,6 +33,32 @@ var LSform = new Class({
LSdebug('Pas de reinitialise pour ' + fieldType);
}
}
},
getValue: function(fieldName) {
var retVal = Array();
var ul = $(fieldName);
if ($type(ul)) {
var elements = ul.getElements('input');
elements.combine(ul.getElements('textarea'));
elements.combine(ul.getElements('select'));
var getName = new RegExp('([a-zA-Z0-9]*)(\[.*\])?');
elements.each(function(el){
var name = getName.exec(el.name);
LSdebug(name);
if (name) {
if (name[1]==fieldName) {
if ($type(el.value)) {
if (el.value!="") {
retVal.include(el.value);
}
}
}
}
},this);
}
return retVal;
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {

View file

@ -8,6 +8,38 @@ var LSformElement_password_field = new Class({
},
initialiseLSformElement_password_field: function() {
// Mail
if (this.params['mail']) {
if ((this.params.mail['canEdit']==1)||(!$type(this.params.mail['canEdit']))) {
this.editMailBtn = new Element('img');
this.editMailBtn.src = varLSdefault.imagePath('mail-edit.png');
this.editMailBtn.addClass('btn');
this.editMailBtn.addEvent('click',this.onEditMailBtnClick.bind(this));
this.LSmail_open = 0;
this.editMailBtn.injectAfter(this.input);
}
if (this.params.mail['ask']) {
this.mailBtn = new Element('img');
this.mailBtn.addClass('btn');
this.mailBtn.addEvent('click',this.onMailBtnClick.bind(this));
this.mailInput = new Element('input');
this.mailInput.setProperties({
name: 'LSformElement_password_' + this.name + '_send',
type: 'hidden'
});
if (this.params.mail['send']) {
this.mailInput.value = 1;
this.mailBtn.src = varLSdefault.imagePath('nomail.png');
}
else {
this.mailInput.value = 0;
this.mailBtn.src = varLSdefault.imagePath('mail.png');
}
this.mailBtn.injectAfter(this.input);
this.mailInput.injectAfter(this.mailBtn);
}
}
// ViewBtn
this.viewBtn = new Element('img');
this.viewBtn.src = varLSdefault.imagePath('view.png');
@ -44,6 +76,57 @@ var LSformElement_password_field = new Class({
}
},
onMailBtnClick: function() {
if (this.mailInput.value==1) {
this.mailInput.value = 0;
this.mailBtn.src = varLSdefault.imagePath('mail.png');
}
else {
this.mailInput.value = 1;
this.mailBtn.src = varLSdefault.imagePath('nomail.png');
}
},
onEditMailBtnClick: function(btn) {
if(!$type(this.LSmail)) {
this.LSmail = new LSmail();
this.LSmail.addEvent('close',this.onLSmailClose.bind(this));
this.LSmail.addEvent('valid',this.onLSmailValid.bind(this));
}
var mail = varLSform.getValue(this.params.mail['mail_attr']);
this.LSmail_open = 1;
this.LSmail.setMails(mail);
this.LSmail.setSubject(this.params.mail['subject']);
this.LSmail.setMsg(this.params.mail['msg']);
this.LSmail.open(this.editMailBtn);
},
onLSmailClose: function(LSmail) {
LSdebug('LSformElement_password : close LSmail');
this.LSmail_open = 0;
},
onLSmailValid: function(LSmail) {
LSdebug('LSformElement_password : valid LSmail');
this.setMail(LSmail.getMail());
},
setMail: function(mail) {
if ($type(mail)) {
if (!$type(this.msgInput)) {
this.msgInput = new Element('input');
this.msgInput.setProperties({
name: 'LSformElement_password_' + this.name + '_msg',
type: 'hidden'
});
this.msgInput.injectAfter(this.editMailBtn);
}
this.msgInput.value = JSON.encode(mail);
}
},
onGenerateBtnClick: function() {
var data = {
template: 'LSform',

View file

@ -1,8 +1,9 @@
var LSmail = new Class({
initialize: function(mails,msg){
initialize: function(mails,subject,msg){
this.href = "LSmail.php";
this.setMails(mails);
this.setMsg(msg);
this.setSubject(subject);
this.object = {};
this.opened = 0;
this.listeners = {
@ -29,6 +30,15 @@ var LSmail = new Class({
}
},
setSubject: function(subject) {
if ($type(subject)) {
this.subject = subject;
}
else {
this.subject = "";
}
},
setObject: function(type,dn) {
this.object = {
type: type,
@ -43,7 +53,8 @@ var LSmail = new Class({
action: 'display',
object: this.object,
mails: this.mails,
msg: this.msg
msg: this.msg,
subject: this.subject
};
if ($type(startElement)) {
@ -57,7 +68,6 @@ var LSmail = new Class({
onOpenGetHtmlComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {
//varLSsmoothbox.setRefreshElement(this);
varLSsmoothbox.asNew();
varLSsmoothbox.addEvent('valid',this.onLSsmoothboxValid.bind(this));
varLSsmoothbox.addEvent('close',this.onLSsmoothboxClose.bind(this));
@ -94,6 +104,10 @@ var LSmail = new Class({
}
},
getMail: function() {
return this.sendInfos;
},
onSendComplete: function(responseText, responseXML) {
var data = JSON.decode(responseText);
if ( varLSdefault.checkAjaxReturn(data) ) {

View file

@ -354,38 +354,37 @@ if (!isset($_ERRORS)) {
case 'LSmail':
switch($_REQUEST['action']) {
case 'display':
if ((isset($_REQUEST['object'])) && (isset($_REQUEST['mails'])) && (isset($_REQUEST['msg'])) ) {
if (isset($_REQUEST['object']['type']) && isset($_REQUEST['object']['dn'])) {
if ($GLOBALS['LSsession']->loadLSobject($_REQUEST['object']['type'])) {
$obj = new $_REQUEST['object']['type']();
$obj -> loadData($_REQUEST['object']['dn']);
$msg = $obj -> getFData($_REQUEST['msg']);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['object']['type']);
}
if (isset($_REQUEST['object']['type']) && isset($_REQUEST['object']['dn'])) {
if ($GLOBALS['LSsession']->loadLSobject($_REQUEST['object']['type'])) {
$obj = new $_REQUEST['object']['type']();
$obj -> loadData($_REQUEST['object']['dn']);
$msg = $obj -> getFData($_REQUEST['msg']);
$subject = $obj -> getFData($_REQUEST['subject']);
}
else {
$msg = $_REQUEST['msg'];
$GLOBALS['LSerror'] -> addErrorCode(1004,$_REQUEST['object']['type']);
}
$GLOBALS['Smarty'] -> assign('LSmail_msg',$msg);
if (is_array($_REQUEST['mails'])) {
$GLOBALS['Smarty'] -> assign('LSmail_mails',$_REQUEST['mails']);
}
else if(empty($_REQUEST['mails'])) {
$GLOBALS['Smarty'] -> assign('LSmail_mails',array($_REQUEST['mails']));
}
$GLOBALS['Smarty'] -> assign('LSmail_mail_label',_('E-mail'));
$GLOBALS['Smarty'] -> assign('LSmail_subject_label',_('Sujet'));
$GLOBALS['Smarty'] -> assign('LSmail_msg_label',_('Message'));
$data = array(
'html' => $GLOBALS['Smarty'] -> fetch('LSmail.tpl')
);
}
else {
$GLOBALS['LSerror'] -> addErrorCode(1012);
}
$msg = $_REQUEST['msg'];
$subject = $_REQUEST['subject'];
}
$GLOBALS['Smarty'] -> assign('LSmail_msg',$msg);
$GLOBALS['Smarty'] -> assign('LSmail_subject',$subject);
if (is_array($_REQUEST['mails'])) {
$GLOBALS['Smarty'] -> assign('LSmail_mails',$_REQUEST['mails']);
}
else if(empty($_REQUEST['mails'])) {
$GLOBALS['Smarty'] -> assign('LSmail_mails',array($_REQUEST['mails']));
}
$GLOBALS['Smarty'] -> assign('LSmail_mail_label',_('E-mail'));
$GLOBALS['Smarty'] -> assign('LSmail_subject_label',_('Sujet'));
$GLOBALS['Smarty'] -> assign('LSmail_msg_label',_('Message'));
$data = array(
'html' => $GLOBALS['Smarty'] -> fetch('LSmail.tpl')
);
break;
case 'send':
if (isset($_REQUEST['infos'])) {

View file

@ -15,7 +15,7 @@
</dd>
<dt class='LSform'>{$LSmail_subject_label}</dt>
<dd class='LSform'>
<input type='text' name='LSmail_subject' id='LSmail_subject'/>
<input type='text' name='LSmail_subject' id='LSmail_subject' value="{$LSmail_subject}"/>
</dd>
<dt class='LSform'>{$LSmail_msg_label}</dt>
<dd class='LSform'>