27if (!defined(
'WEBPORTAL')) {
28 define(
'WEBPORTAL', 1);
30if (!defined(
'NOLOGIN')) {
33if (!defined(
'NOREQUIREUSER')) {
34 define(
'NOREQUIREUSER', 1);
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU', 1);
39if (!defined(
'NOREQUIRESOC')) {
40 define(
'NOREQUIRESOC', 1);
42if (!defined(
'EVEN_IF_ONLY_LOGIN_ALLOWED')) {
43 define(
'EVEN_IF_ONLY_LOGIN_ALLOWED', 1);
45if (!defined(
'NOIPCHECK')) {
46 define(
'NOIPCHECK', 1);
50if (!function_exists(
'dol_getprefix')) {
60 function dol_getprefix($mode =
'')
62 global $dolibarr_main_instance_unique_id,
63 $dolibarr_main_cookie_cryptkey;
65 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ?
66 (empty($dolibarr_main_cookie_cryptkey) ?
'' :
67 $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
71 if (!empty($tmp_instance_unique_id)) {
72 return sha1(
'webportal' . $tmp_instance_unique_id);
74 return sha1(
'webportal' . $_SERVER[
'SERVER_NAME'].$_SERVER[
'DOCUMENT_ROOT'].DOL_DOCUMENT_ROOT);
79include __DIR__.
'/../../main.inc.php';
80require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
81require_once DOL_DOCUMENT_ROOT .
'/societe/class/societeaccount.class.php';
82require_once DOL_DOCUMENT_ROOT .
'/public/webportal/lib/webportal.lib.php';
83require_once DOL_DOCUMENT_ROOT .
'/webportal/class/context.class.php';
84require_once DOL_DOCUMENT_ROOT .
'/webportal/class/webportalmember.class.php';
85require_once DOL_DOCUMENT_ROOT .
'/webportal/class/webportalpartnership.class.php';
96@phan-var-force string $sessionname
97@phan-var-force string $sessiontimeout
112$hookmanager->initHooks(array(
'main',
'webportal'));
114$logged_user =
new User($db);
115$anti_spam_session_key =
'dol_antispam_value';
117if (!defined(
'NOREQUIREDB') && empty($conf->webportal->enabled)) {
121if (!defined(
'WEBPORTAL_NOREQUIRETRAN') || (!defined(
'WEBPORTAL_NOLOGIN') && !empty(
$context->controllerInstance->accessNeedLoggedUser))) {
122 if (!is_object($langs)) {
123 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
125 $langcode = (
GETPOST(
'lang',
'aZ09', 1) ?
GETPOST(
'lang',
'aZ09', 1) : (empty($logged_user->
conf->MAIN_LANG_DEFAULT) ?
getDolGlobalString(
'MAIN_LANG_DEFAULT',
'auto') : $logged_user->
conf->MAIN_LANG_DEFAULT));
126 if (defined(
'MAIN_LANG_DEFAULT')) {
127 $langcode = constant(
'MAIN_LANG_DEFAULT');
129 $langs->setDefaultLang($langcode);
131 $langs->loadLangs(array(
'website',
'main'));
137if (
getDolGlobalInt(
'WEBPORTAL_LOGIN_BY_MODULE') && !empty($conf->modules_parts[
'webportallogin']) && is_array($conf->modules_parts[
'webportallogin'])) {
138 foreach ($conf->modules_parts[
'webportallogin'] as $module => $file) {
143} elseif (!defined(
'WEBPORTAL_NOLOGIN') && !empty(
$context->controllerInstance->accessNeedLoggedUser)) {
147 $hookmanager->initHooks(array(
'login'));
149 "webportal_sessionname" => $sessionname,
150 "webportal_anti_spam_session_key" => $anti_spam_session_key,
152 $reshook = $hookmanager->executeHooks(
'beforeLoginAuthentication', $parameters, $context);
155 } elseif (empty($reshook)) {
156 $admin_error_messages = array();
157 $webportal_logged_thirdparty_account_id = isset($_SESSION[
"webportal_logged_thirdparty_account_id"]) && $_SESSION[
"webportal_logged_thirdparty_account_id"] > 0 ? $_SESSION[
"webportal_logged_thirdparty_account_id"] : 0;
158 $webportal_logged_member_account_id = isset($_SESSION[
"webportal_logged_member_account_id"]) && $_SESSION[
"webportal_logged_member_account_id"] > 0 ? $_SESSION[
"webportal_logged_member_account_id"] : 0;
162 $langs->loadLangs(array(
"other",
"help",
"admin"));
164 $action =
GETPOST(
'action_login',
'alphanohtml');
166 if ($action ==
'login') {
167 $login =
GETPOST(
'login',
'alphanohtml');
168 $password =
GETPOST(
'password',
'password');
172 $context->setEventMessage($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login")),
'errors');
173 $focus_element =
'login';
176 if (empty($password)) {
177 $context->setEventMessage($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Password")),
'errors');
178 if (empty($focus_element)) {
179 $focus_element =
'password';
194 $thirdparty_account_id =
$context->getThirdPartyAccountFromLogin($login, $password);
195 if ($thirdparty_account_id <= 0) {
197 dol_syslog($langs->transnoentitiesnoconv(
'WebPortalErrorFetchThirdPartyAccountFromLogin', $login), LOG_WARNING);
199 $_SESSION[
"webportal_logged_thirdparty_account_id"] = $thirdparty_account_id;
200 $webportal_logged_thirdparty_account_id = $thirdparty_account_id;
206 $member_account_id =
$context->getMemberAccountFromLogin($login, $password);
207 if ($member_account_id <= 0) {
209 dol_syslog($langs->transnoentitiesnoconv(
'WebPortalErrorFetchMemberAccountFromLogin', $login), LOG_WARNING);
211 $_SESSION[
"webportal_logged_member_account_id"] = $member_account_id;
212 $webportal_logged_member_account_id = $member_account_id;
218 dol_syslog($langs->transnoentitiesnoconv(
'WebPortalErrorNoFetchMethod'), LOG_WARNING);
222 $context->setEventMessage($langs->transnoentitiesnoconv(
'WebPortalErrorAuthentication'),
'errors');
226 if (empty($webportal_logged_thirdparty_account_id) && empty($webportal_logged_member_account_id)) {
237 if (!$error &&
$context->userIsLog()) {
238 $logged_member =
null;
239 $websiteaccount =
null;
244 $result = $logged_member->fetch($webportal_logged_member_account_id);
249 dol_syslog(
"Can't load member account (ID: $webportal_logged_member_account_id) even if session logged.", LOG_WARNING);
251 session_set_cookie_params(0,
'/',
null, !empty($dolibarr_main_force_https),
true);
252 session_name($sessionname);
255 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedMember', (
string) $webportal_logged_member_account_id);
257 $context->setEventMessage($error_msg,
'errors');
261 $result = $websiteaccount->fetch($webportal_logged_thirdparty_account_id);
267 dol_syslog(
"Can't load third-party account (ID: $webportal_logged_thirdparty_account_id) even if session logged.", LOG_WARNING);
269 session_set_cookie_params(0,
'/',
null, !empty($dolibarr_main_force_https),
true);
270 session_name($sessionname);
273 $context->setEventMessage($langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedThirdPartyAccount', $webportal_logged_thirdparty_account_id),
'errors');
282 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalSetupNotComplete');
284 $context->setEventMessages($error_msg,
null,
'errors');
288 $result = $logged_user->fetch($user_id);
291 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedUser', (
string) $user_id);
293 $context->setEventMessages($error_msg,
null,
'errors');
300 $logged_thirdparty = $websiteaccount->thirdparty;
301 if (!$logged_thirdparty || !($logged_thirdparty->id > 0)) {
302 $result = $websiteaccount->fetch_thirdparty();
305 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedThirdParty', (
string) $websiteaccount->fk_soc);
308 $context->setEventMessage($error_msg,
'errors');
314 $logged_thirdparty = $websiteaccount->thirdparty;
318 $result = $logged_member->fetch(0,
'', $websiteaccount->thirdparty->id);
321 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedMember', (
string) $websiteaccount->thirdparty->id);
323 $context->setEventMessage($error_msg,
'errors');
326 if (
isModEnabled(
'partnership') && !$error && $logged_member->id > 0) {
330 $result = $logged_partnership->fetch(0,
'', $logged_member->id, $websiteaccount->thirdparty->id);
333 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedPartnership', (
string) $websiteaccount->thirdparty->id, (
string) $logged_member->id);
335 $context->setEventMessage($error_msg,
'errors');
340 if ($logged_thirdparty->default_lang != $langs->defaultlang && !defined(
'WEBPORTAL_NOREQUIRETRAN')) {
341 if (!is_object($langs)) {
342 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
344 $langs->setDefaultLang($logged_thirdparty->default_lang);
346 $langs->loadLangs(array(
'website',
'main'));
349 $context->logged_thirdparty = $logged_thirdparty;
350 if (!empty($logged_partnership)) {
351 $context->logged_partnership = $logged_partnership;
359 $context->logged_user = $logged_user;
360 if (!empty($logged_member)) {
361 $context->logged_member = $logged_member;
374 "webportal_sessionname" => $sessionname,
375 "webportal_anti_spam_session_key" => $anti_spam_session_key,
377 $reshook = $hookmanager->executeHooks(
'afterLoginFailed', $parameters, $context);
384 "webportal_sessionname" => $sessionname,
385 "webportal_anti_spam_session_key" => $anti_spam_session_key,
387 $reshook = $hookmanager->executeHooks(
'afterLogin', $parameters, $context);
static getInstance()
Singleton method to create one instance of this object.
Class for SocieteAccount.
Class to manage translations.
Class to manage Dolibarr users.
Class for WebPortalMember.
Class for WebPortalPartnership.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
$context
@method int call_trigger(string $triggerName, ?User $user)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.