/** * User request for a verification token - send email with a link and request id * * @param uid int userid of user who requested the new token * @param msg int index of message to display (if any) * @return string form or meta redirect * */ function requesttoken($uid, $msg = 0) { global $_CONF, $_SYSTEM, $_TABLES, $LANG04; if (!isset($_SYSTEM['verification_token_ttl'])) { $_SYSTEM['verification_token_ttl'] = 86400; } $retval = ''; $uid = (int) $uid; $result = DB_query("SELECT uid,username,email,passwd,status FROM {$_TABLES['users']} WHERE uid = " . (int) $uid . " AND (account_type & " . LOCAL_USER . ")"); $nrows = DB_numRows($result); if ($nrows == 1) { $A = DB_fetchArray($result); if ($_CONF['usersubmission'] == 1 && $A['status'] == USER_ACCOUNT_AWAITING_APPROVAL) { echo COM_refresh($_CONF['site_url'] . '/index.php?msg=48'); } $verification_id = USER_createActivationToken($uid, $A['username']); $activation_link = $_CONF['site_url'] . '/users.php?mode=verify&vid=' . $verification_id . '&u=' . $uid; $T = new Template($_CONF['path_layout'] . 'email/'); $T->set_file(array('html_msg' => 'newuser_template_html.thtml', 'text_msg' => 'newuser_template_text.thtml')); $T->set_var(array('url' => $_CONF['site_url'] . '/users.php?mode=verify&vid=' . $verification_id . '&u=' . $uid, 'lang_site_or_password' => $LANG04[171], 'site_link_url' => $_CONF['site_url'], 'lang_activation' => sprintf($LANG04[172], $_SYSTEM['verification_token_ttl'] / 3600), 'lang_button_text' => $LANG04[203], 'title' => $_CONF['site_name'] . ': ' . $LANG04[16], 'site_name' => $_CONF['site_name'], 'username' => $A['username'])); $T->parse('output', 'html_msg'); $mailhtml = $T->finish($T->get_var('output')); $T->parse('output', 'text_msg'); $mailtext = $T->finish($T->get_var('output')); $msgData['htmlmessage'] = $mailhtml; $msgData['textmessage'] = $mailtext; $msgData['subject'] = $_CONF['site_name'] . ': ' . $LANG04[16]; $to = array(); $from = array(); $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['noreply_mail']); $to = COM_formatEmailAddress('', $A['email']); COM_mail($to, $msgData['subject'], $msgData['htmlmessage'], $from, true, 0, '', $msgData['textmessage']); COM_updateSpeedlimit('verifytoken'); if ($msg) { echo COM_refresh($_CONF['site_url'] . "/index.php?msg={$msg}"); } else { echo COM_refresh($_CONF['site_url'] . '/index.php'); } } else { COM_updateSpeedlimit('verifytoken'); echo COM_refresh($_CONF['site_url'] . '/users.php?mode=getnewtoken'); } return $retval; }
/** * Create a new password and send it to the user * * @param string $username user's login name * @param string $useremail user's email address * @param int $uid user id of user * @param string $passwd user's password (optional) * @return bool true = success, false = an error occured * */ function USER_createAndSendPassword($username, $useremail, $uid, $passwd = '') { global $_CONF, $_SYSTEM, $_TABLES, $LANG04; if (!isset($_SYSTEM['verification_token_ttl'])) { $_SYSTEM['verification_token_ttl'] = 86400; } $activation_link = ''; $uid = (int) $uid; $storedPassword = DB_getItem($_TABLES['users'], 'passwd', 'uid=' . $uid); $userStatus = DB_getItem($_TABLES['users'], 'status', 'uid=' . $uid); if ($passwd == '' && substr($storedPassword, 0, 4) == '$H$9') { // no need to update password } else { if ($passwd == '') { $passwd = USER_createPassword(8); } $passwd2 = SEC_encryptPassword($passwd); DB_change($_TABLES['users'], 'passwd', "{$passwd2}", 'uid', $uid); } if (file_exists($_CONF['path_data'] . 'welcome_email.txt')) { $template = new Template($_CONF['path_data']); $template->set_file(array('mail' => 'welcome_email.txt')); $template->set_var('auth_info', "{$LANG04['2']}: {$username}\n{$LANG04['4']}: {$passwd}"); $template->set_var('site_url', $_CONF['site_url']); $template->set_var('site_name', $_CONF['site_name']); $template->set_var('site_slogan', $_CONF['site_slogan']); $template->set_var('lang_text1', $LANG04[15]); $template->set_var('lang_text2', $LANG04[14]); $template->set_var('lang_username', $LANG04[2]); $template->set_var('lang_password', $LANG04[4]); $template->set_var('username', $username); $template->set_var('password', $passwd); $template->set_var('name', COM_getDisplayName($uid)); $template->parse('output', 'mail'); $mailtext = $template->get_var('output'); } else { if ($userStatus == USER_ACCOUNT_AWAITING_VERIFICATION) { $verification_id = USER_createActivationToken($uid, $username); $activation_link = $_CONF['site_url'] . '/users.php?mode=verify&vid=' . $verification_id . '&u=' . $uid; $mailtext = $LANG04[168] . $_CONF['site_name'] . ".\n\n"; $mailtext .= $LANG04[170] . "\n\n"; $mailtext .= "----------------------------\n"; $mailtext .= $LANG04[2] . ': ' . $username . "\n"; $mailtext .= $LANG04[171] . ': ' . $_CONF['site_url'] . "\n"; $mailtext .= "----------------------------\n\n"; $mailtext .= sprintf($LANG04[172], $_SYSTEM['verification_token_ttl'] / 3600) . "\n\n"; $mailtext .= $activation_link . "\n\n"; $mailtext .= $LANG04[173] . "\n\n"; $mailtext .= $LANG04[174] . "\n\n"; $mailtext .= "--\n"; $mailtext .= $_CONF['site_name'] . "\n"; $mailtext .= $_CONF['site_url'] . "\n"; } else { $mailtext = $LANG04[168] . $_CONF['site_name'] . ".\n\n"; $mailtext .= $LANG04[170] . "\n\n"; $mailtext .= "----------------------------\n"; $mailtext .= $LANG04[2] . ': ' . $username . "\n"; if ($passwd != '') { $mailtext .= $LANG04[4] . ": {$passwd}\n"; } $mailtext .= $LANG04[171] . ': ' . $_CONF['site_url'] . "\n"; $mailtext .= "----------------------------\n\n"; $mailtext .= $LANG04[14] . "\n\n"; $mailtext .= "--\n"; $mailtext .= $_CONF['site_name'] . "\n"; $mailtext .= $_CONF['site_url'] . "\n"; } } $subject = $_CONF['site_name'] . ': ' . $LANG04[16]; if ($_CONF['site_mail'] !== $_CONF['noreply_mail']) { $mailfrom = $_CONF['noreply_mail']; global $LANG_LOGIN; $mailtext .= LB . LB . $LANG04[159]; } else { $mailfrom = $_CONF['site_mail']; } $to = array(); $from = array(); $from = COM_formatEmailAddress($_CONF['site_name'], $mailfrom); $to = COM_formatEmailAddress($username, $useremail); $subject = COM_undoSpecialChars(strip_tags($subject)); return COM_mail($to, $subject, $mailtext, $from, false); }
/** * User request for a verification token - send email with a link and request id * * @param uid int userid of user who requested the new token * @param msg int index of message to display (if any) * @return string form or meta redirect * */ function requesttoken($uid, $msg = 0) { global $_CONF, $_SYSTEM, $_TABLES, $LANG04; if (!isset($_SYSTEM['verification_token_ttl'])) { $_SYSTEM['verification_token_ttl'] = 86400; } $retval = ''; $uid = (int) $uid; $result = DB_query("SELECT uid,username,email,passwd,status FROM {$_TABLES['users']} WHERE uid = " . (int) $uid . " AND (account_type & " . LOCAL_USER . ")"); $nrows = DB_numRows($result); if ($nrows == 1) { $A = DB_fetchArray($result); if ($_CONF['usersubmission'] == 1 && $A['status'] == USER_ACCOUNT_AWAITING_APPROVAL) { echo COM_refresh($_CONF['site_url'] . '/index.php?msg=48'); } $verification_id = USER_createActivationToken($uid, $A['username']); $activation_link = $_CONF['site_url'] . '/users.php?mode=verify&vid=' . $verification_id . '&u=' . $uid; $mailtext = $LANG04[168] . $_CONF['site_name'] . ".\n\n"; $mailtext .= $LANG04[170] . "\n\n"; $mailtext .= "----------------------------\n"; $mailtext .= $LANG04[2] . ': ' . $A['username'] . "\n"; $mailtext .= $LANG04[171] . ': ' . $_CONF['site_url'] . "\n"; $mailtext .= "----------------------------\n\n"; $mailtext .= sprintf($LANG04[172], $_SYSTEM['verification_token_ttl'] / 3600) . "\n\n"; $mailtext .= $activation_link . "\n\n"; $mailtext .= $LANG04[173] . "\n\n"; $mailtext .= $LANG04[174] . "\n\n"; $mailtext .= "--\n"; $mailtext .= $_CONF['site_name'] . "\n"; $mailtext .= $_CONF['site_url'] . "\n"; $subject = $_CONF['site_name'] . ': ' . $LANG04[16]; if ($_CONF['site_mail'] !== $_CONF['noreply_mail']) { $mailfrom = $_CONF['noreply_mail']; global $LANG_LOGIN; $mailtext .= LB . LB . $LANG04[159]; } else { $mailfrom = $_CONF['site_mail']; } $to = array(); $to = COM_formatEmailAddress('', $A['email']); $from = array(); $from = COM_formatEmailAddress('', $mailfrom); COM_mail($to, $subject, $mailtext, $from); COM_updateSpeedlimit('verifytoken'); if ($msg) { echo COM_refresh($_CONF['site_url'] . "/index.php?msg={$msg}"); } else { echo COM_refresh($_CONF['site_url'] . '/index.php'); } } else { COM_updateSpeedlimit('verifytoken'); echo COM_refresh($_CONF['site_url'] . '/users.php?mode=getnewtoken'); } return $retval; }
/** * Create a new password and send it to the user * * @param string $username user's login name * @param string $useremail user's email address * @param int $uid user id of user * @param string $passwd user's password (optional) * @return bool true = success, false = an error occured * */ function USER_createAndSendPassword($username, $useremail, $uid, $passwd = '') { global $_CONF, $_SYSTEM, $_TABLES, $LANG04; if (!isset($_SYSTEM['verification_token_ttl'])) { $_SYSTEM['verification_token_ttl'] = 86400; } $activation_link = ''; $uid = (int) $uid; $storedPassword = DB_getItem($_TABLES['users'], 'passwd', 'uid=' . $uid); $userStatus = DB_getItem($_TABLES['users'], 'status', 'uid=' . $uid); if ($passwd == '' && substr($storedPassword, 0, 4) == '$H$9') { // no need to update password } else { if ($passwd == '') { $passwd = USER_createPassword(8); } $passwd2 = SEC_encryptPassword($passwd); DB_change($_TABLES['users'], 'passwd', "{$passwd2}", 'uid', $uid); } if (file_exists($_CONF['path_data'] . 'welcome_email.txt')) { $template = new Template($_CONF['path_data']); $template->set_file(array('mail' => 'welcome_email.txt')); $template->set_var('auth_info', "{$LANG04['2']}: {$username}\n{$LANG04['4']}: {$passwd}"); $template->set_var('site_url', $_CONF['site_url']); $template->set_var('site_name', $_CONF['site_name']); $template->set_var('site_slogan', $_CONF['site_slogan']); $template->set_var('lang_text1', $LANG04[15]); $template->set_var('lang_text2', $LANG04[14]); $template->set_var('lang_username', $LANG04[2]); $template->set_var('lang_password', $LANG04[4]); $template->set_var('username', $username); $template->set_var('password', $passwd); $template->set_var('name', COM_getDisplayName($uid)); $template->parse('output', 'mail'); $mailtext = $template->get_var('output'); } else { $T = new Template($_CONF['path_layout'] . 'email/'); $T->set_file(array('html_msg' => 'newuser_template_html.thtml', 'text_msg' => 'newuser_template_text.thtml')); if ($userStatus == USER_ACCOUNT_AWAITING_VERIFICATION) { $verification_id = USER_createActivationToken($uid, $username); $T->set_var(array('url' => $_CONF['site_url'] . '/users.php?mode=verify&vid=' . $verification_id . '&u=' . $uid, 'lang_site_or_password' => $LANG04[171], 'site_link_url' => $_CONF['site_url'], 'lang_activation' => sprintf($LANG04[172], $_SYSTEM['verification_token_ttl'] / 3600), 'lang_button_text' => $LANG04[203])); } else { $T->set_var(array('url' => $_CONF['site_url'] . '/usersettings.php', 'lang_site_or_password' => $LANG04[4], 'site_link_url' => '', 'lang_activation' => $LANG04[14], 'lang_button_text' => 'Change Password', 'passwd' => $passwd)); } $T->set_var(array('title' => $_CONF['site_name'] . ': ' . $LANG04[16], 'site_name' => $_CONF['site_name'], 'username' => $username)); $T->parse('output', 'html_msg'); $mailhtml = $T->finish($T->get_var('output')); $T->parse('output', 'text_msg'); $mailtext = $T->finish($T->get_var('output')); } $msgData['htmlmessage'] = $mailhtml; $msgData['textmessage'] = $mailtext; $msgData['subject'] = $_CONF['site_name'] . ': ' . $LANG04[16]; $to = array(); $from = array(); $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['noreply_mail']); $to = COM_formatEmailAddress('', $useremail); // $msgData['from']['name'] = $_CONF['site_name']; // $msgData['from']['email'] = $_CONF['noreply_mail']; // $msgData['to']['email'] = $useremail; // $msgData['to']['name'] = $username; // return COM_emailNotification($msgData); return COM_mail($to, $msgData['subject'], $msgData['htmlmessage'], $from, true, 0, '', $msgData['textmessage']); }