/** * 是否是当前登录用户的cron * @param integer $id * @return boolean */ public function isLoginCron($id) { $loginUser = UserModel::instance()->getLoginUser(); $loginId = $loginUser['id']; $userid = $this->getFieldByField('userid', 'id', $id); return $loginId == $userid; }
/** * 循环每日任务 */ public function actionIndex() { //获取当前登录的用户Id $userId = UserModel::instance()->getLoginUser()['id']; $crons = CronModel::instance()->getAllByField('userid', $userId); $this->setTitle('每日运行任务'); $this->render('index', array('crons' => $crons)); }
/** * 一次运行任务列表 */ public function actionIndex() { //获取当前登录用户的Id $userId = UserModel::instance()->getLoginUser()['id']; //获取当前用户一次任务的列表 $ats = AtModel::instance()->getAllByField('userid', $userId, 'id,title,hasrun,runTime,create_time,update_time'); $this->setTitle('一次运行列表'); $this->render('index', array('ats' => $ats)); }
/** * 判断某个id的一次任务是不是当前登录用户的一次任务 * @param integer $id * @return boolean 是返回true,否则返回false */ public function isLoginAt($id) { $userid = $this->getFieldByField('userid', 'id', $id); if (!empty($userid)) { $loginUserId = UserModel::instance()->getLoginUser()['id']; return $userid == $loginUserId; } return false; }
/** * (non-PHPdoc) * @see CController::beforeAction() */ protected function beforeAction($action) { if (!UserModel::instance()->islogin()) { $controllerName = $action->getController()->getId(); $actionName = $action->getId(); $noControllers = array_keys(Yii::app()->params['no_login']); if (in_array($controllerName, $noControllers)) { $noActions = Yii::app()->params['no_login'][$controllerName]; if (in_array($actionName, $noActions)) { return parent::beforeAction($action); } } $this->redirect(array('/user/login')); return !parent::beforeAction($action); } return parent::beforeAction($action); }
if ($this->getId() == 'cron') { ?> class="active"<?php } ?> > <a href="<?php echo Yii::app()->createUrl('/cron'); ?> "> <i class="icon-refresh"></i> <span class="menu-text"> 每日循环 </span> </a> </li> <?php if (UserModel::instance()->isLoginSuper()) { ?> <li <?php if ($this->getId() == 'user') { ?> class="active"<?php } ?> > <a href="<?php echo Yii::app()->createUrl('/user'); ?> "> <i class="icon-user"></i> <span class="menu-text"> 用户管理 </span> </a>
/** * 重置密码 */ public function actionResetpwd() { if (Yii::app()->request->getIsAjaxRequest()) { $id = Yii::app()->request->getQuery('id'); $user = UserModel::instance()->getById($id); $password = Yii::app()->getSecurityManager()->computeHMAC('123456789', $user['salt']); UserModel::instance()->update($id, array('password' => $password)); echo 'reset password'; } }
/** * 用户登录 * @return boolean */ public function login() { return UserModel::instance()->login($this->username, $this->password); }