Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * Владельца пока показывает только пользователям с полным доступом.
  * @param $group_id
  * @return string
  */
 public static function adminParamsForm($group_id)
 {
     /** @var User $current_user_obj */
     $current_user_obj = Auth::currentUserObj();
     if (!$current_user_obj) {
         return '';
     }
     if (!$current_user_obj->getHasFullAccess()) {
         return '';
     }
     $html = '';
     $html .= '<h2>Владельцы</h2>';
     $group_obj = Group::factory($group_id);
     $html .= CRUDForm::html($group_obj, [new CRUDFormRow('Owner user', new CRUDFormWidgetInput(User::_OWNER_USER_ID, true)), new CRUDFormRow('Owner group', new CRUDFormWidgetInput(User::_OWNER_GROUP_ID, true))]);
     return $html;
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 5
0
 /**
  * @param $obj InterfaceOwner
  * Does not saves object - designed to be called from constructor.
  */
 public static function assignCurrentUserAsOwnerToObj($obj)
 {
     Assert::assert($obj instanceof InterfaceOwner);
     Assert::assert($obj instanceof InterfaceLoad);
     static $__inprogress = [];
     $inprogress_key = FullObjectId::getFullObjectId($obj);
     if (array_key_exists($inprogress_key, $__inprogress)) {
         return;
     }
     $__inprogress[$inprogress_key] = 1;
     // заполняем при создании объекта
     if (!$obj->getId()) {
         $current_user_id = Auth::currentUserId();
         if ($current_user_id) {
             $obj->setOwnerUserId($current_user_id);
             $current_user_obj = User::factory($current_user_id);
             $obj->setOwnerGroupId($current_user_obj->getPrimaryGroupId());
         }
     }
     unset($__inprogress[$inprogress_key]);
 }
Exemplo n.º 6
0
 /**
  * Владельца и полный доступ пока показывает только пользователям с полным доступом.
  * @param $user_id
  * @return string
  */
 public static function adminParamsForm($user_id)
 {
     /** @var User $current_user_obj */
     $current_user_obj = Auth::currentUserObj();
     if (!$current_user_obj) {
         return '';
     }
     if (!$current_user_obj->getHasFullAccess()) {
         return '';
     }
     $html = '';
     $html .= '<h2>Владельцы и полный доступ</h2>';
     $user_obj = User::factory($user_id);
     $html .= CRUDForm::html($user_obj, [new CRUDFormRow('Owner user', new CRUDFormWidgetInput(User::_OWNER_USER_ID, true)), new CRUDFormRow('Owner group', new CRUDFormWidgetInput(User::_OWNER_GROUP_ID, true)), new CRUDFormRow('Primary group', new CRUDFormWidgetInput(User::_PRIMARY_GROUP_ID, true)), new CRUDFormRow('Has full access', new CRUDFormWidgetInput(User::_HAS_FULL_ACCESS))]);
     return $html;
 }
Exemplo n.º 7
0
 public function currentUserName()
 {
     return Auth::currentUserLogin();
 }