public function actionLogin() { $model = new Admin('login'); if (XUtils::method() == 'POST') { $model->attributes = $_POST['Admin']; if ($model->validate()) { $data = $model->find('username=:username', array('username' => $model->username)); if ($data === null) { $model->addError('username', '用户不存在'); parent::_backendLogger(array('catalog' => 'login', 'intro' => '登录失败,用户不存在:' . CHtml::encode($model->username), 'user_id' => 0)); } elseif (!$model->validatePassword($data->password)) { $model->addError('password', '密码不正确'); parent::_backendLogger(array('catalog' => 'login', 'intro' => '登录失败,密码不正确:' . CHtml::encode($model->username) . ',使用密码:' . CHtml::encode($model->password), 'user_id' => 0)); } elseif ($data->group_id == 2) { $model->addError('username', '用户已经锁定,请联系管理'); } else { $this->_sessionSet('_backendGroupId', $data->group_id); if (isset($data->group_id) && $data->group_id == 1) { $this->_sessionSet('_backendPermission', 'backendstrator'); } $data->last_login_ip = XUtils::getClientIP(); $data->last_login_time = time(); $data->login_count = $data->login_count + 1; $data->save(); parent::_sessionSet('uid', $data->id); parent::_sessionSet('uname', $data->username); parent::_backendLogger(array('catalog' => 'login', 'intro' => '用户登录成功:' . $data->username)); $this->redirect(array('default/index')); XUtils::message('success', '登录成功', $this->createUrl('default/index'), 2); } } } $this->render('login', array('model' => $model)); }
public function init() { //初始化 parent::init(); //更新session if (isset($_POST['sessionId'])) { $session = Yii::app()->getSession(); $session->close(); $session->sessionID = $_POST['sessionId']; $session->open(); } //从初始化的内容里面取的userid,若存在则证明有登录 $this->_backendUserId = parent::_sessionGet('uid'); $this->_backendUserName = parent::_sessionGet('uname'); $this->_backendGroupId = parent::_sessionGet('_backendGroupId'); /* 检测判断是否登陆,否则跳到login页面 */ empty($this->_backendUserId) && $this->redirect(array('public/login')); empty($this->_backendGroupId) && $this->redirect(array('public/login')); $this->_backendGroupName = parent::_sessionGet('_backendGroupName'); $this->_backendPermission = parent::_sessionGet('_backendPermission'); $this->_backendAcl = parent::_sessionGet('_backendAcl'); if (empty($this->_backendAcl) || empty($this->_backendGroupName)) { $groupArr = AdminGroup::model()->findByPk($this->_backendGroupId); //当前组权限 $this->_backendAcl = $groupArr->acl; parent::_sessionSet('_backendAcl', $this->_backendAcl); //当前组id $this->_backendGroupId = $groupArr->id; parent::_sessionSet('_backendGroupId', $this->_backendGroupId); //当前组名 $this->_backendGroupName = $groupArr->group_name; parent::_sessionSet('_backendGroupName', $this->_backendGroupName); unset($groupArr); } //栏目,后端在此获得全分类数组,前端在system里面获得 $this->_catalog = XXcache::get('_catalog'); $this->_catalogAll = XXcache::get('_catalogAll'); //系统配置 $this->_conf = XXcache::get('_config'); $this->_theme = empty($this->_conf['theme']) ? 'default' : $this->_conf['theme']; // $this->_conf = self::_config(); //站点前台主题静态目录url !defined('STATIC_THEME_URL') && define('STATIC_THEME_URL', SITE_URL . 'static/themes/' . $this->_theme . '/'); }