Пример #1
0
 /**
  * 登录方法
  */
 public function actionDoLogin()
 {
     $this->layout = false;
     $util = new Util();
     $session = Yii::$app->session;
     $request = Yii::$app->getRequest();
     if (empty($_POST)) {
         return $this->redirect(['login/login']);
     }
     $post = Yii::$app->request->post();
     $username = $post['username'];
     $password = $post['password'];
     // 判断管理员是否存在
     $admin = new AdminBaseInfo();
     $id = $admin->login($username, $password);
     // id不存在
     if (is_array($id)) {
         return $this->render('login', ['error' => $id['error']]);
     }
     // 存放session
     $session[AdminBaseInfo::SESSION_KEY_ADMIN] = [AdminBaseInfo::ADMIN_BASE => 'admin', 'id' => $id, 'mobile' => $username];
     // 存放cookie
     $cookies = Yii::$app->response->cookies;
     $times = time() + 60 * 60 * 24;
     $admin = ['name' => AdminBaseInfo::ADMIN_BASE, 'value' => 'admin'];
     $id = ['name' => AdminBaseInfo::COOKIE_KEY_ID, 'value' => $id];
     $username = ['name' => AdminBaseInfo::COOKIE_KEY_NAME, 'value' => $username];
     $cookie = ['admin' => $admin, 'id' => $id, 'adminName' => $username];
     $util->cookie($cookie, $times);
     // $util->formatResData(0,'success');
     $this->layout = 'index';
     return $this->redirect(['login/index']);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $num)
 {
     $query = ApplicationBaseInfo::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => $num]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'user_id' => $this->user_id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'app_name', $this->app_name])->andFilterWhere(['like', 'app_id', $this->app_id])->andFilterWhere(['like', 'app_key', $this->app_key])->andFilterWhere(['like', 'app_desc', $this->app_desc])->andFilterWhere(['like', 'provider', $this->provider])->andFilterWhere(['like', 'app_logo', $this->app_logo])->andFilterWhere(['like', 'app_url', $this->app_url]);
     $session = Yii::$app->getSession();
     $id = $session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'];
     $authManager = Yii::$app->authManager->getRolesByUser($id);
     if (AdminBaseInfo::getAdminById($id)['role_id'] != 0) {
         $query->andFilterWhere(['like', 'app_key', array_keys($authManager)[0]]);
     }
     return $dataProvider;
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $num)
 {
     $query = AdminBaseInfo::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => $num]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'gender' => $this->gender, 'last_login_time' => $this->last_login_time, 'create_id' => $this->create_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'status' => $this->status]);
     $session = Yii::$app->getSession();
     if (self::getAdminById($session[self::SESSION_KEY_ADMIN]['id'])['role_id'] == 0) {
         $query->andFilterWhere(['role_id' => $this->role_id]);
     } else {
         $query->andFilterWhere(['role_id' => self::getAdminById($session[self::SESSION_KEY_ADMIN]['id'])['role_id']]);
     }
     $query->andFilterWhere(['like', 'adminname', $this->adminname])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'password_salt', $this->password_salt])->andFilterWhere(['like', 'avatar', $this->avatar])->andFilterWhere(['like', 'department', $this->department])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'last_login_ip', $this->last_login_ip])->andFilterWhere(['like', 'create_ip', $this->create_ip]);
     return $dataProvider;
 }
Пример #4
0
 public function beforeAction($action)
 {
     // 判断是否登录
     $isLogin = AdminBaseInfo::isLogin();
     if (!$isLogin) {
         return $this->redirect(['login/login']);
     }
     $session = Yii::$app->getSession();
     $Jurisdiction = Yii::$app->controller->id . '/' . Yii::$app->controller->action->id;
     $dbManager = new DbManager();
     $id = $session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'];
     if (Yii::$app->authManager->getRolesByUser($id)['admin']->name == 'admin') {
         parent::beforeAction($action);
         return true;
     }
     if ($dbManager->checkAccess($id, $Jurisdiction)) {
         parent::beforeAction($action);
         return true;
     } else {
         return $this->redirect(['login/no-authority']);
     }
     parent::beforeAction($action);
     return true;
 }
Пример #5
0
        return Html::img('/' . 'introduce/images/common-head-pic.png', ['height' => '60', 'width' => '60']);
    }
    return Html::img('/' . $model->avatar, ['width' => '60']);
}], 'adminname', ['attribute' => 'gender', 'value' => function ($model, $row) {
    $gender = $model->gender;
    if ($gender == 1) {
        return '男';
    } else {
        if ($gender == 2) {
            return '女';
        } else {
            return '未设置';
        }
    }
}, 'filter' => AdminBaseInfo::getType('gender', ['1' => '男', '2' => '女', '0' => '未设置'])], ['attribute' => 'role_id', 'value' => function ($model) {
    $admin = new AdminBaseInfo();
    return conditionSelect($model->role_id, $admin->getRole());
}, 'filter' => AdminBaseInfo::getType('role_id', conditionSelect($role, $arr))], 'department', 'mobile', 'email:email', 'create_id', ['attribute' => 'last_login_time', 'value' => function ($model, $row) {
    return date('Y-m-d H:i:s', $model->last_login_time);
}, 'filter' => false], ['attribute' => 'last_login_ip', 'filter' => false], ['attribute' => 'create_ip', 'filter' => false], ['attribute' => 'create_time', 'value' => function ($model, $row) {
    return date('Y-m-d H:i:s', $model->create_time);
}, 'filter' => false], ['attribute' => 'update_time', 'value' => function ($model, $row) {
    return date('Y-m-d H:i:s', $model->update_time);
}, 'filter' => false], ['attribute' => 'status', 'value' => function ($model, $row) {
    $status = $model->status;
    if ($status == 1) {
        return '正常';
    } else {
        if ($status == 2) {
            return '临时禁用';
        } else {
Пример #6
0
?>

    <?php 
echo $form->field($model, 'avatar')->fileInput();
?>

    <?php 
$session = Yii::$app->getSession();
if (AdminBaseInfo::getAdminById($session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'])['role_id'] == 0) {
    if (empty($model->role_id)) {
        $model->role_id = 0;
    }
    echo $form->field($model, 'role_id')->radioList($role_id);
} else {
    $arr = [AdminBaseInfo::getAdminById($session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'])['role_id'] => $role_id[AdminBaseInfo::getAdminById($session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'])['role_id']]];
    $model->role_id = AdminBaseInfo::getAdminById($session[AdminBaseInfo::SESSION_KEY_ADMIN]['id'])['role_id'];
    echo $form->field($model, 'role_id')->radioList($arr);
}
?>

    <?php 
echo $form->field($model, 'department')->textInput(['maxlength' => 30]);
?>

    <?php 
echo $form->field($model, 'mobile')->textInput(['maxlength' => 11]);
?>

    <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>
Пример #7
0
use yii\helpers\Html;
use common\helpers\Util;
use yii\helpers\Url;
use common\models\user\UserBaseInfo;
use backend\models\AdminBaseInfo;
use yii\widgets\Breadcrumbs;
use backend\assets\AppAsset;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\rbac\DbManager;
use backend\assets\layouts\LayoutsAsset;
LayoutsAsset::register($this);
$session = Yii::$app->session;
$info = $session[AdminBaseInfo::SESSION_KEY_ADMIN];
$info = AdminBaseInfo::getAdminById($info['id']);
$this->beginPage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<?php 
echo Html::csrfMetaTags();
?>
<title><?php 
echo Html::encode($this->title);
?>
</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/introduce/css/fonts/icomoon/style.css">