Skip to content

Commit

Permalink
Debug v20 - Fix option ADHERENT_CREATE_EXTERNAL_USER_LOGIN.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 20, 2024
1 parent 23bfc5d commit 442e798
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
13 changes: 7 additions & 6 deletions htdocs/adherents/admin/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,17 +518,18 @@
print $form->selectyesno('ADHERENT_LOGIN_NOT_REQUIRED', (getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED') ? 0 : 1), 1, false, 0, 1);
print "</td></tr>\n";

// Create an external user login after an online payment of a membership subscription
// TODO Move this into the validate() method of the member.
print '<tr class="oddeven"><td>'.$langs->trans("MemberCreateAnExternalUserForSubscriptionValidated").'</td><td>';
print $form->selectyesno('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', getDolGlobalInt('ADHERENT_CREATE_EXTERNAL_USER_LOGIN'), 1, false, 0, 1);
print "</td></tr>\n";

// Send mail information is on by default
print '<tr class="oddeven"><td>'.$langs->trans("MemberSendInformationByMailByDefault").'</td><td>';
print $form->selectyesno('ADHERENT_DEFAULT_SENDINFOBYMAIL', getDolGlobalInt('ADHERENT_DEFAULT_SENDINFOBYMAIL'), 1, false, 0, 1);
print "</td></tr>\n";

// Create an external user login for each new member subscription validated
print '<tr class="oddeven"><td>'.$langs->trans("MemberCreateAnExternalUserForSubscriptionValidated").'</td><td>';
print $form->selectyesno('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', getDolGlobalInt('ADHERENT_CREATE_EXTERNAL_USER_LOGIN'), 1, false, 0, 1);
print "</td></tr>\n";

// Create an external user login for each new member subscription validated
// Publish member information on public annuary
$linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.((int) $conf->entity) : '');
print '<tr class="oddeven"><td>'.$langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist).'</td><td>';
print $form->selectyesno('MEMBER_PUBLIC_ENABLED', getDolGlobalInt('MEMBER_PUBLIC_ENABLED'), 1, false, 0, 1);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/langs/en_US/admin.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,8 @@ MemberCodeChecker=Options for automatic generation of member codes
AdherentLoginRequired=Manage a login/password for each member
AdherentLoginRequiredDesc=Add a value for a login and a password on the member file. If the member is linked to a user, updating the member login and password will also update the user login and password.
AdherentMailRequired=Email required to create a new member
MemberSendInformationByMailByDefault=Checkbox to send mail confirmation to members (validation or new subscription) is on by default
MemberCreateAnExternalUserForSubscriptionValidated=Create an external user login for each new member subscription validated
MemberSendInformationByMailByDefault=The checkbox to send an email confirmation to members (validation or new subscription) is on by default
MemberCreateAnExternalUserForSubscriptionValidated=Create automatically an external user (with a login to connect to the application) after an online payment of a membership subscription
VisitorCanChooseItsPaymentMode=Visitor can choose from any available payment modes
MEMBER_REMINDER_EMAIL=Enable automatic reminder <b>by email</b> of expired subscriptions. Note: Module <strong>%s</strong> must be enabled and correctly setup to send reminders.
MembersDocModules=Document templates for documents generated from member record
Expand Down
58 changes: 40 additions & 18 deletions htdocs/public/payment/paymentok.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,9 @@
}

if (!$error) {
// If payment using Strip, save the Stripe payment info into societe_account
if ($paymentmethod == 'stripe' && $autocreatethirdparty && $option == 'bankviainvoice') {
$thirdparty_id = $object->fk_soc;
$thirdparty_id = ($object->socid ? $object->socid : $object->fk_soc);

dol_syslog("Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0, '_payment');

Expand Down Expand Up @@ -722,7 +723,7 @@
}
} else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
$sql .= " VALUES (".((int) $object->fk_soc).", '', '".$db->escape($stripecu)."', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])."', ".((int) $servicestatus).", ".((int) $conf->entity).", '".$db->idate(dol_now())."', 0)";
$sql .= " VALUES (".$thirdparty_id.", '', '".$db->escape($stripecu)."', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])."', ".((int) $servicestatus).", ".((int) $conf->entity).", '".$db->idate(dol_now())."', 0)";
$resql = $db->query($sql);
if (!$resql) { // should not happen
$error++;
Expand Down Expand Up @@ -756,6 +757,42 @@
$db->rollback();
}

// Set string to use to send email info
$infouserlogin = '';

// Create external user
if (getDolGlobalString('ADHERENT_CREATE_EXTERNAL_USER_LOGIN')) {
$nuser = new User($db);
$tmpuser = dol_clone($object, 0); // $object is type Adherent

// Check if a user login already exists for this member or not
$found = 0;
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE fk_member = ".((int) $object->id);
$resqlcount = $db->query($sql);
if ($resqlcount) {
$objcount = $db->fetch_object($resqlcount);
if ($objcount) {
$found = $objcount->nb;
}
}

if (!$found) {
$result = $nuser->create_from_member($tmpuser, $object->login);
$newpassword = $nuser->setPassword($user, '');

if ($result < 0) {
$outputlangs->load("errors");
$postactionmessages[] = 'Error in create external user : '.$nuser->error;
} else {
$infouserlogin = $outputlangs->trans("Login").': '.$nuser->login.' '."\n".$outputlangs->trans("Password").': '.$newpassword;
$postactionmessages[] = $langs->trans("NewUserCreated", $nuser->login);
}
} else {
$outputlangs->load("errors");
$postactionmessages[] = 'No user created because a user linked to member already exists';
}
}

// Send email to member
if (!$error) {
dol_syslog("Send email to customer to ".$object->email." if we have to (sendalsoemail = ".$sendalsoemail.")", LOG_DEBUG, 0, '_payment');
Expand Down Expand Up @@ -785,22 +822,7 @@

$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);

// Create external user
if (getDolGlobalString('ADHERENT_CREATE_EXTERNAL_USER_LOGIN')) {
$infouserlogin = '';
$nuser = new User($db);
$tmpuser = dol_clone($object, 0);

$result = $nuser->create_from_member($tmpuser, $object->login);
$newpassword = $nuser->setPassword($user, '');

if ($result < 0) {
$outputlangs->load("errors");
$postactionmessages[] = 'Error in create external user : '.$nuser->error;
} else {
$infouserlogin = $outputlangs->trans("Login").': '.$nuser->login.' '."\n".$outputlangs->trans("Password").': '.$newpassword;
$postactionmessages[] = $langs->trans("NewUserCreated", $nuser->login);
}
if ($infouserlogin) {
$substitutionarray['__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
}

Expand Down

0 comments on commit 442e798

Please sign in to comment.