public function sqlConditionAndPlaceholderValueForUserId($user_id)
 {
     $user_obj = User::factory($user_id);
     if ($user_obj->getHasFullAccess()) {
         return ['', []];
         // do not filter
     }
     $current_user_usertogroup_ids_arr = UserToGroup::getIdsArrForUserIdByCreatedAtDesc($user_id);
     $current_user_groups_ids_arr = [];
     foreach ($current_user_usertogroup_ids_arr as $usertogroup_id) {
         $usertogroup_obj = UserToGroup::factory($usertogroup_id);
         $current_user_groups_ids_arr[] = $usertogroup_obj->getGroupId();
     }
     $placeholder_values_arr = [];
     $where = ' (';
     $where .= '(owner_user_id = ?)';
     $placeholder_values_arr[] = $user_id;
     if (count($current_user_groups_ids_arr) > 0) {
         $user_groups_placeholders_arr = array_fill(0, count($current_user_groups_ids_arr), '?');
         $where .= ' or (owner_group_id in (' . implode($user_groups_placeholders_arr) . '))';
         $placeholder_values_arr = array_merge($placeholder_values_arr, $current_user_groups_ids_arr);
     }
     $where .= ') ';
     return [$where, $placeholder_values_arr];
 }
Пример #2
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);
 }
Пример #3
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]);
 }
Пример #4
0
 public static function commonParamsForm($user_id)
 {
     $html = '';
     $html .= '<h2>Параметры</h2>';
     $user_obj = User::factory($user_id);
     $html .= CRUDForm::html($user_obj, [new CRUDFormRow('Login', new CRUDFormWidgetInput('login')), new CRUDFormRow('Комментарий', new CRUDFormWidgetTextarea('description'))]);
     return $html;
 }