public function getLastData() { $updatepass = CRequest::param("updatepass"); if ($updatepass) { if (\Yii::$app->user->identity->username == "admin") { #如果是demo,则不允许修改密码。 if (CConfig::param("is_demo")) { echo json_encode(["statusCode" => "300", "message" => "demo是为了让大家看,admin账户不允许修改密码,请自己添加账户"]); exit; } } $AdminUserResetPassword = new AdminUserResetPassword(); $AdminUserResetPassword->attributes = $updatepass; if ($AdminUserResetPassword->validate()) { $AdminUserResetPassword->updatePassword(); echo json_encode(["statusCode" => "200", "message" => 'Update Password Success']); } else { $errors = $AdminUserResetPassword->errors; echo json_encode(["statusCode" => "300", "message" => CModel::getErrorStr($errors)]); } exit; } $adminUser = \Yii::$app->user->identity; $current_account = $adminUser->username; $editUrl = CUrl::getUrl("fecadmin/myaccount/index"); return ['current_account' => $current_account, 'editUrl' => $editUrl]; }
public static function getSuperUserConfig() { $superUser = ['admin']; $configSuperUser = CConfig::param('super_admin_user'); if (is_array($configSuperUser) && !empty($configSuperUser)) { $superUser = array_merge($superUser, $configSuperUser); $superUser = array_unique($superUser); } return $superUser; }
public function actionRemoteindex() { $key = CRequest::param("key"); $configKey = CConfig::param("remote_get_access_token_key"); $username = CRequest::param("username"); $usercode = CRequest::param("usercode") ? CRequest::param("usercode") : ''; if ($configKey && $key == $configKey && $username) { $user = $this->getCurrentUser($username, $usercode); if (isset($user['access_token'])) { echo json_encode(["status" => "success", "access_token" => $user['access_token']]); } } }
public function init() { parent::init(); $theme = CConfig::getCurrentTheme(); # 定义views文件所在路径 $dir = \basename($this->_currentDir); basename(dirname($_SERVER['PHP_SELF'])); $viewPath = __DIR__ . "/Theme/" . $theme . "/" . strtolower($dir); $this->setViewPath($viewPath); # 定义模块专属的layout 文件 appadmin/code/Blog/Theme/default/article/layouts/main.php //$this->layout = "main.php"; # 加载配置文件 $config_file_dir = $this->_currentDir . '/etc/config.php'; if (file_exists($config_file_dir)) { if (($params_data = (require $config_file_dir)) && !empty($params_data)) { Yii::configure($this, ['params' => $params_data]); } } $this->params['blockDir'] = str_replace("\\controllers", "", $this->controllerNamespace); }
public static function saveSystemLog() { $logConfig = CConfig::param("systemlog"); //var_dump($logConfig); if (!is_array($logConfig) || !isset($logConfig['enable']) || !$logConfig['enable']) { return; } $systemLog = new AdminLog(); $user = Yii::$app->user->identity; if ($user) { $url_key = '/' . Yii::$app->controller->module->id . '/' . Yii::$app->controller->id; $username = $user['username']; $person = $user['person']; $currentData = date('Y-m-d H:i:s'); $url = CUrl::getCurrentUrl(); $systemLog->account = $username; $systemLog->person = $person; $systemLog->created_at = $currentData; $systemLog->url = $url; $systemLog->url_key = $url_key; $systemLog->menu = self::getMenuByUrlKey($url_key); $systemLog->save(); } }
public function getDefaultToken() { return CConfig::getDefaultModuleToken(); }
public function delete() { //$request_param = CRequest::param(); //$this->_param = $request_param; //$this->initParam(); if ($role_id = CRequest::param($this->_paramKey)) { $model = AdminRole::findOne([$this->_paramKey => $role_id]); if ($model->role_id) { # 不允许删除admin if (CConfig::param("is_demo")) { if ($model->role_id == 4) { echo json_encode(["statusCode" => "300", "message" => 'demo版本,不允许编辑admin']); exit; } } $innerTransaction = Yii::$app->db->beginTransaction(); try { $model->delete(); # 删除这个role 对应的所有关联的菜单 AdminRoleMenu::deleteAll(['role_id' => $role_id]); $innerTransaction->commit(); } catch (Exception $e) { $innerTransaction->rollBack(); } echo json_encode(["statusCode" => "200", "message" => 'Delete Success!']); exit; } else { echo json_encode(["statusCode" => "300", "message" => "role_id => {$role_id} , is not exist"]); exit; } } else { if ($ids = CRequest::param($this->_paramKey . 's')) { $id_arr = explode(",", $ids); $innerTransaction = Yii::$app->db->beginTransaction(); try { # 不允许删除admin if (CConfig::param("is_demo")) { if (in_array(4, $id_arr)) { echo json_encode(["statusCode" => "300", "message" => 'demo版本,不允许删除admin']); $innerTransaction->rollBack(); exit; } } AdminRole::deleteAll(['in', 'role_id', $id_arr]); # 删除这个role 对应的所有关联的菜单 AdminRoleMenu::deleteAll(['in', 'role_id', $id_arr]); $innerTransaction->commit(); } catch (Exception $e) { $innerTransaction->rollBack(); } echo json_encode(["statusCode" => "200", "message" => "{$ids} Delete Success!"]); exit; } } echo json_encode(["statusCode" => "300", "message" => "role_id or ids Param is not Exist!"]); exit; }
public static function getConfigChildHtml($configKey) { $config = []; # get config from module param if ($module = Yii::$app->controller->module) { $module_config = CModule::param("block"); if (isset($module_config[$configKey])) { $config = $module_config[$configKey]; } } # if module config param is empty or not exist, # get config from application if (empty($config)) { $app_config = CConfig::param("block"); if (isset($app_config[$configKey])) { $config = $app_config[$configKey]; } } if (!isset($config['view']) || empty($config['view'])) { throw new InvalidConfigException('view and class must exist in array config!'); } else { return self::getChildHtml($config); } }