public static function saveOrUpdateObjectFromFormData() { $model_class_name = POSTAccess::getRequiredPostValue(self::FIELD_CLASS_NAME); $object_id = POSTAccess::getOptionalPostValue(self::FIELD_OBJECT_ID); \OLOG\CheckClassInterfaces::exceptionIfClassNotImplementsInterface($model_class_name, \OLOG\Model\InterfaceSave::class); $new_prop_values_arr = []; $null_fields_arr = []; $reflect = new \ReflectionClass($model_class_name); foreach ($reflect->getProperties() as $prop_obj) { if (!$prop_obj->isStatic()) { // игнорируем статические свойства класса - они относятся не к объекту, а только к классу (http://www.php.net/manual/en/language.oop5.static.php), и в них хранятся настройки ActiveRecord и CRUD $prop_name = $prop_obj->getName(); // сейчас если поля нет в форме - оно не будет изменено в объекте. это позволяет показывать в форме только часть полей, на остальные форма не повлияет if (array_key_exists($prop_name, $_POST)) { // Проверка на заполнение обязательных полей делается на уровне СУБД, через нот нулл в таблице $new_prop_values_arr[$prop_name] = $_POST[$prop_name]; } // чтение возможных NULL if (array_key_exists($prop_name . "___is_null", $_POST)) { if ($_POST[$prop_name . "___is_null"]) { $null_fields_arr[$prop_name] = 1; } } } } $obj = null; if ($object_id) { $obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $object_id); } else { $obj = new $model_class_name(); } $obj = CRUDFieldsAccess::setObjectFieldsFromArray($obj, $new_prop_values_arr, $null_fields_arr); $obj->save(); return $obj->getId(); }
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 static function optionalFieldValue($field_name) { $field_value = POSTAccess::getOptionalPostValue($field_name); // чтение возможных NULL if (POSTAccess::getOptionalPostValue($field_name . "___is_null", '') == "1") { $field_value = null; } return $field_value; }
protected static function deleteModelOperation() { $model_class_name = POSTAccess::getRequiredPostValue(CRUDTableWidgetDelete::FIELD_CLASS_NAME); \OLOG\CheckClassInterfaces::exceptionIfClassNotImplementsInterface($model_class_name, \OLOG\Model\InterfaceDelete::class); $model_id = POSTAccess::getRequiredPostValue(CRUDTableWidgetDelete::FIELD_OBJECT_ID); $obj = CRUDObjectLoader::createAndLoadObject($model_class_name, $model_id); $obj->delete(); $redirect_url = POSTAccess::getOptionalPostValue(CRUDTableWidgetDelete::FIELD_REDIRECT_AFTER_DELETE_URL, ''); if ($redirect_url != '') { Redirects::redirect($redirect_url); } \OLOG\Redirects::redirectToSelf(); }
public function action() { Exits::exit403If(!Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_USERS])); $user_id = $this->user_id; $user_obj = User::factory($user_id); Exits::exit403If(!OwnerCheck::currentUserOwnsObj($user_obj)); Operations::matchOperation(self::OPERATION_SET_PASSWORD, function () use($user_id) { $new_password = POSTAccess::getOptionalPostValue(self::FIELD_NAME_PASSWORD); $new_password_hash = password_hash($new_password, PASSWORD_BCRYPT); $user_obj = User::factory($user_id); $user_obj->setPasswordHash($new_password_hash); $user_obj->save(); }); $html = ''; $html .= '<div class="row"><div class="col-md-6">'; $html .= self::commonParamsForm($user_id); $html .= self::passwordForm(); $html .= self::userOperatorsTable($user_id); $html .= self::adminParamsForm($user_id); $html .= '</div><div class="col-md-6">'; if (Operator::currentOperatorHasAnyOfPermissions([Permissions::PERMISSION_PHPAUTH_MANAGE_USERS_PERMISSIONS])) { $html .= '<h2>Разрешения</h2>'; $html .= HTML::div('', '', function () use($user_id) { $new_permissiontouser_obj = new PermissionToUser(); $new_permissiontouser_obj->setUserId($user_id); echo CRUDTable::html(PermissionToUser::class, '', [new \OLOG\CRUD\CRUDTableColumn('Разрешение', new \OLOG\CRUD\CRUDTableWidgetText('{' . Permission::class . '.{this->permission_id}->title}')), new \OLOG\CRUD\CRUDTableColumn('Удалить', new \OLOG\CRUD\CRUDTableWidgetDelete())], [new CRUDTableFilterEqualInvisible('user_id', $user_id)], ''); echo CallapsibleWidget::buttonAndCollapse('Показать все неназначенные разрешения', function () use($user_id) { $html = CRUDTable::html(Permission::class, '', [new CRUDTableColumn('Разрешение', new CRUDTableWidgetTextWithLink('{this->title}', (new PermissionAddToUserAction($user_id, '{this->id}'))->url())), new CRUDTableColumn('', new CRUDTableWidgetTextWithLink('Добавить пользователю', (new PermissionAddToUserAction($user_id, '{this->id}'))->url(), 'btn btn-default btn-xs'))], [new CRUDTableFilterNotInInvisible('id', PermissionToUser::getPermissionIdsArrForUserId($user_id))], 'id', '79687tg8976rt87'); return $html; }); }); } $html .= self::userInGroupsTable($user_id); $html .= '</div></div>'; AdminLayoutSelector::render($html, $this); }