public function __construct() { try { $this->db = DB::init()->connect(); } catch (Exception $ex) { $ex->getMessage(); } }
protected function checkRolesForAction($action) { $reqRoles = $this->requiredRoles(); $alterRegRoles = []; if ($reqRoles) { foreach ($reqRoles as $key => $value) { $alterRegRoles[strtolower($key . 'Action')] = $value; } if (array_key_exists($action = strtolower($action), $alterRegRoles)) { $roles = $alterRegRoles[$action]; if (Session::get('user_id')) { $user = PrivilegedUser::getUserRoleById(DB::init()->connect(), Session::get('user_id')); } else { $user = ['role_id' => 5, 'role_name' => 'Guest']; } return in_array($user['role_id'], $roles); } } return TRUE; }
function __construct() { $this->db = DB::init()->connect(); }
protected function __construct() { $this->db = DB::init()->connect(); $this->permissions = array(); }
public function getPermsByRoleIdAction() { header('Content-type: application/json; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); if (filter_has_var(INPUT_GET, 'id')) { $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); } else { throw new Exception('Не удалось получить id роли'); } $perms = Role::getRolePerms(DB::init()->connect(), $id)->getPermissions(); echo json_encode($perms); }
public function editUserAction() { $fc = FrontController::getInstance(); $model = new AdminModel('Редактирование пользователя'); $userModel = new UserUpdateTableModel(); $userModel->setTable('user'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $userModel->setData('userUpdate'); $userModel->updateRecord(); header('Location: /admin/profile/id/' . $userModel->getId()); exit; } else { $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT); if (!$id) { header('Location: /admin/notFound'); exit; } $userModel->setId($id); $user = []; $db = DB::init()->connect(); $userModel->readRecordsById(); $userModel->readUserAddress(); $userModel->readUserPhones(); $roles = PrivilegedUser::getUserRoleById($db, $id); $model->setData(['profile' => $userModel->getRecordsById(), 'contacts' => $userModel->getUserContacts(), 'role' => $roles, 'allRoles' => Role::getRoles($db), 'perms' => Role::getRolePerms($db, $roles['role_id'])->getPermissions()]); } $output = $model->render('../views/admin/user/editUser.php', 'admin'); $fc->setPage($output); }