Example #1
0
 public function actionChangePassword()
 {
     $model = new \backend\models\Admin(['scenario' => 'admin-change-password']);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $user = Admin::findOne(Yii::$app->user->identity->id);
         $user->setPassword($model->password);
         $user->generateAuthKey();
         if ($user->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.'));
         }
         return $this->redirect(['change-password']);
     }
     return $this->render('changePassword', ['model' => $model]);
 }
Example #2
0
 public function actionIndex()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->redirect(['goods/index']);
     }
     //判断请求类型
     if (Yii::$app->request->isPost && Yii::$app->request->isAjax) {
         $name = Yii::$app->request->Post('username');
         $password = (string) Yii::$app->request->Post('password');
         //查询管理员是否存在
         $admin = Admin::findOne(['name' => $name]);
         if (null === $admin) {
             $this->ajaxReturn(false, [], '用户不存在,请先注册');
         }
         //获取密码
         $passwordServer = $admin->getAttribute('password');
         if ($password !== $passwordServer) {
             $this->ajaxReturn(false, [], '密码错误,请重新输入');
         }
         //获取管理员id
         $adminId = $admin->getPrimaryKey();
         //如果存在记入session
         $session = Yii::$app->getSession();
         $session->open();
         //组装SESSION
         $sessionBody = ['adminId' => $adminId, 'name' => $name];
         $sessionData = $session->set('username', $sessionBody);
         $this->ajaxReturn(true, [], '登录成功');
     }
     return $this->renderPartial('index');
 }
Example #3
0
 /**
  * Finds user by [[username]]
  *
  * @return Admin|null
  */
 protected function getAdmin()
 {
     if ($this->_admin === null) {
         $this->_admin = Admin::findByUsername($this->username);
     }
     return $this->_admin;
 }
Example #4
0
 public function loginAction()
 {
     //登录验证
     $this->view->disable();
     $code = trim(htmlspecialchars($this->request->getPost('code')));
     if (strtolower($code) != $this->session->get('verify_code')) {
         echo "<script>alert('验证码错误');history.back();</script>";
     }
     $username = trim(htmlspecialchars($this->request->getPost('username')));
     $password = md5(trim(htmlspecialchars($this->request->getPost('password'))));
     if (empty($code) || empty($username) || empty($password)) {
         echo "<script>alert('用户名或密码不能为空');history.back();</script>";
     }
     $where = array("name =  :name: and passwd = :passwd:", 'bind' => array('name' => $username, 'passwd' => $password));
     $user = Admin::findFirst($where);
     if ($user) {
         if ($user->getActive() == 0) {
             echo "<script>alert('该用户已经被冻结');history.back();</script>";
             exit;
         }
         $this->session->set('depart_id', $user->getDepart());
         $this->session->set('username', $username);
         $this->session->set('uid', $user->getId());
         //            header("location:/backend/system/user");
         $this->response->redirect('/backend/system/user');
     } else {
         echo "<script>alert('用户名或密码错误');history.back();</script>";
         exit;
     }
 }
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = Admin::findByUsername($this->username);
     }
     return $this->_user;
 }
 /**
  * Creates Admin account
  *
  * @return Admin|null the saved model or null if saving fails
  */
 public function createAdmin()
 {
     if ($this->validate()) {
         $admin = new Admin();
         $admin->nicename = $this->nicename;
         $admin->username = $this->username;
         $admin->email = $this->email;
         $admin->role = $this->role;
         $admin->status = $this->status;
         $admin->setPassword($this->password);
         $admin->generateAuthKey();
         if ($admin->save()) {
             return $admin;
         }
     }
     return null;
 }
 /**
  * Creates a form model given a token.
  *
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($id, $config = [])
 {
     $this->_user = Admin::findIdentity($id);
     if (!$this->_user) {
         throw new InvalidParamException('Unable to find admin!');
     }
     $this->id = $this->_user->id;
     parent::__construct($config);
 }
Example #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Admin::find();
     $dataProvider = new ActiveDataProvider(['query' => $query->where(['status' => [Admin::STATUS_ACTIVE, Admin::STATUS_INACTIVE]])]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'auth_role' => $this->auth_role, 'status' => $this->status, 'birthdate' => $this->birthdate]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
 /**
  * 用户登录
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     $model->userClass = Admin::className();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goHome();
     } else {
         return $this->renderPartial('login', ['model' => $model]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Admin::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'status' => $this->status, 'role' => $this->role, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'nicename', $this->nicename])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]);
     return $dataProvider;
 }
Example #11
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $user = Admin::find()->where(['username' => $_POST['LoginForm']['username']])->one();
         //设置session
         $session = Yii::$app->session;
         $session['userid'] = $user->id;
         $session['username'] = $user->username;
         $session['head_image'] = $user->head_image;
         return $this->redirect(['/admin/index']);
     } else {
         return $this->renderPartial('login', ['model' => $model, 'assets_url' => \Yii::$app->params['backend_assets']]);
     }
 }
 public function actionAdd()
 {
     $model = new Leaveword();
     if ($model->load(\Yii::$app->request->post())) {
         $model->leave_time = time();
         $model->leave_uid = \Yii::$app->session['userid'];
         if ($model->validate() && $model->save()) {
             \Yii::$app->getSession()->setFlash('success', '留言成功!^_^');
             $this->redirect(['leaveword-admin/index']);
         }
     }
     $admins = Admin::findBySql('SELECT id,username FROM tbl_admin')->asArray()->all();
     $admin_map[0] = '所有人';
     foreach ($admins as $admin) {
         $admin_map[$admin['id']] = $admin['username'];
     }
     unset($admin_map[\Yii::$app->session['userid']]);
     // var_dump($admin_map);exit();
     return $this->render('add', ['model' => $model, 'admin_map' => $admin_map]);
 }
Example #13
0
                <?php 
if (Yii::$app->controller->action->id != 'update') {
    ?>
                    <?php 
    echo $form->field($model, 'password')->passwordInput(['maxlength' => 255]);
    ?>

                    <?php 
    echo $form->field($model, 'repassword')->passwordInput(['maxlength' => 255]);
    ?>
                <?php 
}
?>

                <?php 
echo $form->field($model, 'auth_role')->dropDownList(Admin::getArrayAuthRole());
?>

                <div class="form-group pull-right">
                    <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
                </div>

                <?php 
ActiveForm::end();
?>
            </div>
        </div>
    </div>
</div>
Example #14
0
 /**
  * 修改管理员
  *
  * @param array $_POST[] 管理员修改数据
  */
 public function actionUpdate()
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $mAdmin = new Admin();
     if ($params = Yii::$app->request->post()) {
         //验证
         if (empty($params['user_name'])) {
             Yii::$app->util->msg('参数错误');
         }
         if (empty($params['password']) && empty($params['repassword'])) {
             $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'auth' => isset($params['auth']) ? json_encode($params['auth']) : ''];
         } else {
             if ($params['password'] != $params['repassword']) {
                 Yii::$app->util->msg('两次密码不一致');
             } else {
                 $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
                 $salt = substr(str_shuffle($str), 0, 8);
                 $options = ['id' => $params['id'], 'user_name' => $params['user_name'], 'salt' => $salt, 'password' => Yii::$app->util->passwordEncode($params['password'], $salt), 'auth' => isset($params['auth']) ? json_encode($params['auth']) : ''];
             }
         }
         if ($mAdmin->store($options)) {
             return $this->redirect('admin-list');
         } else {
             Yii::$app->util->msg('入库错误');
         }
     } else {
         $id = Yii::$app->request->get('id', 0);
         $one = $mAdmin->getAdminById($id);
         if (!$one) {
             return $this->redirect('admin-list');
         } else {
             $mMenu = new Menu();
             $data = $mMenu->menu();
             $auth = json_decode($one['auth']);
             if (!empty($auth)) {
                 foreach ($data as $k => $v) {
                     if (in_array($v['id'], $auth)) {
                         $data[$k]['checked'] = 'checked';
                     } else {
                         $data[$k]['checked'] = '';
                     }
                 }
             }
             return $this->render('update', ['data' => $data, 'one' => $one]);
         }
     }
 }
Example #15
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Admin::findOne(['id' => $id, 'status' => [Admin::STATUS_ACTIVE, Admin::STATUS_INACTIVE]])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the Admin model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Admin the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Admin::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #17
0
    <!--<h1><?php 
echo Html::encode($this->title);
?>
</h1>-->
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>&nbsp;</p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', 'email:email', 'nicename', ['attribute' => 'role', 'label' => 'Role', 'filter' => Admin::getAdminRoleConst(), 'value' => function ($model, $index, $dataColumn) {
    return $model->adminRole;
    //$roleDropdown = Admin::getAdminRoleConst();
    //return $roleDropdown[$model->role];
}], ['attribute' => 'status', 'label' => 'Status', 'filter' => Admin::getAdminStatusConst(), 'value' => function ($model, $index, $dataColumn) {
    return $model->adminStatus;
    //$roleDropdown = Admin::getAdminStatusConst();
    //return $roleDropdown[$model->status];
}], 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'buttons' => ['update' => function ($url, $model) {
    //return (Yii::$app->user->identity->role > $model->role || Yii::$app->user->id === $model->id || Yii::$app->user->identity->role === Admin::ROLE_ROOT) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Update']) : '';
    //return (Admin::isOwnAdminAccount($model->id) || Admin::canEditAdminAccount($model->role)) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Update']) : '';
    //return (AdminRoles::canUpdateAdminAccount($model->id, Yii::$app->user->id, $model->role, Yii::$app->user->identity->role)) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Update']) : '';
    return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Update']);
    //return (AdminRoles::canUpdateAdminAccountByRole($model->role, $model->id)) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, ['title' => 'Update']) : '';
}, 'delete' => function ($url, $model) {
    //return (Yii::$app->user->identity->role > $model->role || Yii::$app->user->id === $model->id || Yii::$app->user->identity->role === Admin::ROLE_ROOT) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => 'Delete']) : '';
    //return (!Admin::isOwnAdminAccount($model->id) && Admin::canEditAdminAccount($model->role)) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => 'Delete']) : '';
    //return (AdminRoles::canDeleteAdminAccount($model->id, Yii::$app->user->id, $model->role, Yii::$app->user->identity->role)) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => 'Delete', 'data-confirm' => 'Are you sure to delete this admin?', 'data-method' => 'post']) : '';
    return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => 'Delete', 'data-confirm' => 'Are you sure to delete this admin?', 'data-method' => 'post']);
    //return (AdminRoles::canDeleteAdminAccountByRole($model->role, $model->id)) ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => 'Delete']) : '';
Example #18
0
use yii\grid\GridView;
use backend\models\Admin;
use yii\helpers\ArrayHelper;
use dosamigos\datepicker\DatePicker;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Admins';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">
    <div class="box-body">
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'table table-bordered table-hover'], 'summary' => '', 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'username', 'name', 'email:email', ['attribute' => 'auth_role', 'value' => function ($model) {
    return $model->authRoleLabel;
}, 'filter' => Html::activeDropDownList($searchModel, 'auth_role', Admin::getArrayAuthRole(), ['class' => 'form-control', 'prompt' => 'Please Filter'])], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    if ($model->status === $model::STATUS_ACTIVE) {
        $class = 'label-success';
    } elseif ($model->status === $model::STATUS_INACTIVE) {
        $class = 'label-warning';
    } else {
        $class = 'label-danger';
    }
    return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status', $arrayStatus, ['class' => 'form-control', 'prompt' => 'Please Filter'])], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete} {inactive}', 'buttons' => ['inactive' => function ($url, $model) {
    if ($model->status != $model::STATUS_INACTIVE) {
        return Html::a('<span class="glyphicon glyphicon-eye-close"></span>', ['inactive', 'id' => $model->id], ['title' => 'Inactive', 'data' => ['confirm' => 'Are you sure you want to inactive this user?', 'method' => 'post']]);
    } else {
        if ($model->status == $model::STATUS_INACTIVE) {
            return Html::a('<span class="glyphicon glyphicon-exclamation-sign"></span>', ['active', 'id' => $model->id], ['title' => 'Inactive', 'data' => ['confirm' => 'Are you sure you want to actived this user?', 'method' => 'post']]);
        } else {
Example #19
0
 public function getHandler()
 {
     return $this->hasOne(Admin::className(), ['id' => 'handle_uid']);
 }
Example #20
0
 /**
  * Find helpDesk by email
  * @param string, $email
  * @return Array, HelpDesk info
  */
 public static function getByEmail($email)
 {
     return Admin::findOne(['email' => $email]);
 }
Example #21
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCreatedBy0()
 {
     return $this->hasOne(Admin::className(), ['id' => 'createdBy']);
 }
Example #22
0
 public function chpassAction()
 {
     //密码修改
     if ($this->request->isPost()) {
         $this->view->disable();
         $oldpass = trim($this->request->getPost('oldpass'));
         $newpass = trim($this->request->getPost('newpass'));
         if (empty($oldpass) || empty($newpass)) {
             echo "<script>alert('密码不能为空'),history.back();</script>";
             exit;
         }
         $user = Admin::findFirst($this->uid);
         if (md5($oldpass) != $user->getPasswd()) {
             echo "<script>alert('原密码错误'),history.back();</script>";
             exit;
         }
         $user->setPasswd(md5($newpass));
         $user->update();
         echo "<script>alert('密码修改成功'),history.back();</script>";
         exit;
     } else {
         $this->response->setStatusCode(404, "Not Found");
     }
 }
Example #23
0
 public function sayAction()
 {
     $this->view->disable();
     $user = Admin::find();
     var_dump($user->toArray());
 }
Example #24
0
 public function getAdmin()
 {
     return $this->hasOne(Admin::className(), ['id' => 'admin_id']);
 }
Example #25
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdmins()
 {
     return $this->hasMany(Admin::className(), ['roleId' => 'RoleId']);
 }