function Contacts_createPortalLoginDetails($entityData) { vimport('modules.Settings.CustomerPortal.helpers.CustomerPortalPassword'); $encodePass = vglobal('encode_customer_portal_passwords'); $adb = PearDatabase::getInstance(); $wsId = $entityData->getId(); $parts = explode('x', $wsId); $entityId = $parts[1]; $email = $entityData->get('email'); if (($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') && $entityData->get('contactstatus') != 'Inactive') { $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?"; $result = $adb->pquery($sql, array($entityId)); $insert = false; if ($adb->num_rows($result) == 0) { $insert = true; } else { $dbusername = $adb->query_result($result, 0, 'user_name'); $isactive = $adb->query_result($result, 0, 'isactive'); if ($email == $dbusername && $isactive == 1 && !$entityData->isNew()) { $update = false; } else { if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') { $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=1 WHERE id=?"; $adb->pquery($sql, array($email, $entityId)); $password = $adb->query_result($result, 0, 'user_password'); $update = true; } else { $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?"; $adb->pquery($sql, array($email, 0, $entityId)); $update = false; } } } if ($insert == true) { $password = makeRandomPassword(); $truePassword = $password; if ($encodePass) { $password = CustomerPortalPassword::encryptPassword($password, $email); $params = array($entityId, $email, $password, 'C', 1, CustomerPortalPassword::getCryptType(), $truePassword); $sql = "INSERT INTO vtiger_portalinfo(`id`, `user_name`, `user_password`, `type`, `isactive`, `crypt_type`, `password_sent`) VALUES(" . generateQuestionMarks($params) . ")"; } else { $params = array($entityId, $email, $password, 'C', 1, $truePassword); $sql = "INSERT INTO vtiger_portalinfo(`id`, `user_name`, `user_password`, `type`, `isactive`, `password_sent`) VALUES(" . generateQuestionMarks($params) . ")"; } $adb->pquery($sql, $params); } } else { $sql = "UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?"; $adb->pquery($sql, array($email, $entityId)); } }
/** function used to send mail to the customer when he forgot the password and want to retrieve the password * @param string $mailid - email address of the customer * return message about the mail sending whether entered mail id is correct or not or is there any problem in mail sending */ function send_mail_for_password($mailid) { $adb = PearDatabase::getInstance(); $log = vglobal('log'); vimport('modules.Settings.CustomerPortal.helpers.CustomerPortalPassword'); $log->debug("Entering customer portal function send_mail_for_password"); $adb->println("Inside the function send_mail_for_password({$mailid})."); $sql = "select * from vtiger_portalinfo where user_name = ?;"; $res = $adb->pquery($sql, array($mailid)); if ($adb->num_rows($res) > 0) { $user_name = $adb->query_result($res, 0, 'user_name'); $isactive = $adb->query_result($res, 0, 'isactive'); $record = $adb->query_result($res, 0, 'id'); // generate new temp password for portal user $password = makeRandomPassword(); $truePassword = $password; $password = CustomerPortalPassword::encryptPassword($password, $user_name); $params = array($password, CustomerPortalPassword::getCryptType(), $truePassword, $record); $sql = 'UPDATE vtiger_portalinfo SET `user_password` = ?, `crypt_type` = ?, `password_sent` = ? WHERE `id` = ? LIMIT 1;'; $adb->pquery($sql, $params); $data = array('id' => '104', 'to_email' => $mailid, 'module' => 'Contacts', 'record' => $record, 'user_name' => $user_name, 'password' => $truePassword); $recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates'); } $succes = false; if ($mailid == '') { $masage = 'LBL_NO_MAIL_ADDRESS'; } elseif ($adb->num_rows($res) == 0) { $masage = 'LBL_EMAIL_ADDRESS_NOT_FOUND'; } elseif ($isactive == 0) { $masage = 'LBL_LOGIN_REVOKED'; } elseif (!$recordModel->sendMailFromTemplate($data)) { $masage = 'LBL_MAIL_COULDNOT_SENT'; } else { $succes = true; $masage = 'LBL_PASSWORD_HAS_BEEN_SENT'; $params = array(1, $record); $sql = 'UPDATE vtiger_portalinfo SET `password_sent` = ? WHERE `id` = ? LIMIT 1;'; $adb->pquery($sql, $params); } $ret_msg = array('succes' => $succes, 'masage' => $masage); $adb->println("Exit from send_mail_for_password. {$ret_msg}"); $log->debug("Exiting customer portal function send_mail_for_password"); return $ret_msg; }