From d3981aec143b0f0081c5292359d10cc1b1bec1d5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Jan 2011 17:41:26 +0000 Subject: [PATCH] New: Ask password when creating a user from a contact --- ChangeLog | 3 ++ htdocs/contact/fiche.php | 41 ++++++++++++++++++++++++--- htdocs/core/class/html.form.class.php | 6 +++- htdocs/user/class/user.class.php | 27 +++++++++--------- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a29202d24d..1a1f5fe677a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,10 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.1 compared to 3.0 ***** For users: - New: Can add information on current user on odt generation +- New: Prefix on third party is not used by default. Hidden option + SOCIETE_USEPREFIX can restore old feature. - New: Standing orders module use bank account from banks module +- New: Ask password when creating a user from a contact For developers: - New: External modules can add their menu manager diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 6b9f8a69d44..fce0b1006ea 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -94,13 +94,29 @@ else if ($result > 0) { + $db->begin(); + // Creation user $nuser = new User($db); $result=$nuser->create_from_contact($object,$_POST["login"]); - if ($result < 0) + if ($result > 0) + { + $result2=$nuser->setPassword($user,$_POST["password"],0,1,1); + if ($result2) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else { $msg=$nuser->error; + + $db->rollback(); } } else @@ -772,10 +788,27 @@ else include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); $login=dol_buildlogin($object->nom,$object->prenom); - // Create a form array - $formquestion=array(array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); + $generated_password=''; + if (!$ldap_sid) + { + if ($conf->global->USER_PASSWORD_GENERATED) + { + $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); + $nomfichier=$nomclass.".class.php"; + //print DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomclass; + require_once(DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomfichier); + $genhandler=new $nomclass($db,$conf,$langs,$user); + $generated_password=$genhandler->getNewGeneratedPassword(); + } + } + $password=$generated_password; - $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); + // Create a form array + $formquestion=array( + array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login), + array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password)); + + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion,'no'); if ($ret == 'html') print '
'; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 27422180287..c47a7a8935b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1806,7 +1806,7 @@ class Form * @param title title * @param question question * @param action action - * @param formquestion an array with forms complementary inputs + * @param formquestion an array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , )) * @param selectedchoice "" or "no" or "yes" * @param useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No * @param height Force height of box @@ -1831,6 +1831,10 @@ class Form { $more.=''.$input['label'].''."\n"; } + if ($input['type'] == 'password') + { + $more.=''.$input['label'].''."\n"; + } if ($input['type'] == 'select') { $more.=''; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index c41face2690..f143531bac8 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -808,12 +808,13 @@ class User extends CommonObject /** - * \brief Cree en base un utilisateur depuis l'objet contact - * \param contact Objet du contact source - * \param login Login to force - * \return int si erreur <0, si ok renvoie id compte cree + * Cree en base un utilisateur depuis l'objet contact + * @param contact Objet du contact source + * @param login Login to force + * @param password Password to force + * @return int <0 if error, if OK returns id of created user */ - function create_from_contact($contact,$login='') + function create_from_contact($contact,$login='',$password='') { global $conf,$user,$langs; @@ -1177,13 +1178,13 @@ class User extends CommonObject /** - * \brief Change le mot de passe d'un utilisateur - * \param user Object user de l'utilisateur qui fait la modification - * \param password Nouveau mot de passe en clair (a generer si non communique) - * \param changelater 1=Change password only after clicking on confirm email - * \param notrigger 1=Ne declenche pas les triggers - * \param nosyncmember Do not synchronize linked member - * \return string If OK return clear password, 0 if no change, < 0 if error + * Change password of a user + * @param user Object user of user making change + * @param password New password in clear text (to generate if not provided) + * @param changelater 1=Change password only after clicking on confirm email + * @param notrigger 1=Does not launch triggers + * @param nosyncmember Do not synchronize linked member + * @return string If OK return clear password, 0 if no change, < 0 if error */ function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0) { @@ -1345,7 +1346,7 @@ class User extends CommonObject $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root); } if (! empty($dolibarr_main_force_https)) $urlwithouturlroot=preg_replace('/http:/i','https:',$urlwithouturlroot); - + // TODO Use outputlangs to translate messages if (! $changelater) {