New: Ask password when creating a user from a contact

This commit is contained in:
Laurent Destailleur 2011-01-29 17:41:26 +00:00
parent ca90ebabe0
commit d3981aec14
4 changed files with 59 additions and 18 deletions

View File

@ -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

View File

@ -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 '<br>';
}

View File

@ -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.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
}
if ($input['type'] == 'password')
{
$more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="password" class="flat" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'"></td></tr>'."\n";
}
if ($input['type'] == 'select')
{
$more.='<tr><td valign="top">';

View File

@ -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)
{