public static function init() { date_default_timezone_set('Europe/Moscow'); DBConfig::setDBSettingsObj(AuthConstants::DB_NAME_PHPAUTH, new DBSettings('localhost', 'db_phpauthdemo', 'root', '1')); CacheConfig::addServerSettingsObj(new MemcacheServerSettings('localhost', 11211)); AuthConfig::setExtraCookiesArr(['ignore_nginx_cache' => 1]); AuthConfig::setAdminActionsBaseClassname(AdminDemoActionsBase::class); LayoutsConfig::setAdminLayoutClassName(LayoutBootstrap::class); // AuthConfig::setUserEventClass(UserEvents::class); //AuthConfig::setFullAccessCookieName('php_auth'); /* $conf['return_false_if_no_route'] = true; // for local php server $conf['php-bt'] = [ 'menu_classes_arr' => [ \OLOG\Auth\Admin\AuthAdminMenu::class ], 'application_title' => 'Auth demo' ]; $conf['php_auth'] = [ 'full_access_cookie_name' => 'jkhbsdfhjvkdfvjgvasdc' ]; return $conf; */ }
public function action() { $user_id = Auth::currentUserId(); if ($user_id) { $html = LoginTemplate::getContent('Пользователь уже авторизован', false); LayoutBootstrap::render($html); return; } if (!array_key_exists('login', $_POST) && !array_key_exists('password', $_POST)) { $content = LoginTemplate::getContent(); LayoutBootstrap::render($content); return; } /* $is_ip_Banned = UMSHelper::checkBanByCurrentIP(); if ($is_ip_Banned) { $content = UMSSignonTemplate::getContent('Ваш вход заблокирован'); UMSLayoutTemplate::render("Авторизация", $content); return; } */ $login = POSTAccess::getOptionalPostValue('login'); $password = POSTAccess::getOptionalPostValue('password'); $user_id = Auth::getUserIdByCredentials($login, $password); if (!$user_id || $password == "") { $content = LoginTemplate::getContent('Неправильный адрес или пароль'); LayoutBootstrap::render($content); return; } $user_obj = User::factory($user_id); /* if ($user_obj->isBanned()) { $content = UMSSignonTemplate::getContent('Ваш аккаунт забанен'); UMSLayoutTemplate::render("Авторизация", $content); return; } if (!$user_obj->getEmailIsConfirmed()) { $resend_activation_main_url = UMSResendUMSEmailActivationAction::getUrl($user_obj->getId()); $content = UMSSignonTemplate::getContent('Ваша учетная запись не активирована.<br><a href="' . $resend_activation_main_url . '">Отправить ссылку повторно</a>'); UMSLayoutTemplate::render("Авторизация", $content); return; } */ Auth::startUserSession($user_obj->getId()); // set extra cookies if (!empty(AuthConfig::getExtraCookiesArr())) { $extra_cookies_arr = AuthConfig::getExtraCookiesArr(); foreach ($extra_cookies_arr as $cookie_name => $cookie_value) { setcookie($cookie_name, $cookie_value, time() + Auth::SESSION_LIFETIME_SECONDS, '/', Auth::sessionCookieDomain(), false, true); } } $redirect = '/'; $success_redirect_url = POSTAccess::getOptionalPostValue('success_redirect_url', ''); if ($success_redirect_url != '') { $redirect = $success_redirect_url; } \OLOG\Redirects::redirect($redirect); }
public function currentUserName() { $admin_actions_base_classname = AuthConfig::getAdminActionsBaseClassname(); if (CheckClassInterfaces::classImplementsInterface($admin_actions_base_classname, InterfaceCurrentUserName::class)) { return (new $admin_actions_base_classname())->currentUserName(); } return ''; }
public function action() { Auth::logout(); // remove extra cookies if (!empty(AuthConfig::getExtraCookiesArr())) { $extra_cookies_arr = AuthConfig::getExtraCookiesArr(); foreach ($extra_cookies_arr as $cookie_name => $cookie_value) { //setcookie($cookie_name, $cookie_value, time() + Auth::SESSION_LIFETIME_SECONDS, '/', Auth::sessionCookieDomain()); setcookie($cookie_name, "", 1000, '/', Auth::sessionCookieDomain(), false, true); } } $redirect = '/'; if (isset($_GET['destination'])) { $redirect = Sanitize::sanitizeUrl($_GET['destination']); } \OLOG\Redirects::redirect($redirect); }
public function sqlConditionAndPlaceholderValueForCurrentUser() { // check full access cookie $auth_cookie_name = AuthConfig::getFullAccessCookieName(); if ($auth_cookie_name) { if (isset($_COOKIE[$auth_cookie_name])) { return ['', []]; // do not filter } } // check current user $current_user_id = Auth::currentUserId(); if (!$current_user_id) { return [' 1=2 ', []]; // no current user, select nothing } return $this->sqlConditionAndPlaceholderValueForUserId($current_user_id); }
public function afterSave() { $this->removeFromFactoryCache(); if (AuthConfig::getUserAfterSaveCallbackClassName()) { \OLOG\CheckClassInterfaces::exceptionIfClassNotImplementsInterface(AuthConfig::getUserAfterSaveCallbackClassName(), InterfaceUserAfterSaveCallback::class); $events_class = AuthConfig::getUserAfterSaveCallbackClassName(); $events_class::userAfterSaveCallback($this); } }