update config permission

This commit is contained in:
dongpd 2020-05-25 11:42:14 +07:00
parent e77c1416f5
commit 7bdb458b78
8 changed files with 196 additions and 153 deletions

View File

@ -152,9 +152,15 @@ class ConfigController extends Controller {
'method' => "POST" 'method' => "POST"
] ]
]; ];
$apiConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true); $ip = "192.168.0.42";
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true);
if ($tempConfig['status']) {
$t = json_decode($tempConfig['data'], true);
$temp = explode(":", $t['servermqtt']);
$ip = $temp[0];
}
return $this->render('index', [ return $this->render('index', [
"apiConfig" => $apiConfig "ip" => $ip
]); ]);
} }

View File

@ -22,6 +22,9 @@ class UserController extends Controller {
if (Yii::$app->user->isGuest) { if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']); return $this->redirect(['/site/login']);
} }
if (!Yii::$app->user->can("administrator")) {
return $this->redirect(["/dashboard"]);
}
} }
/** /**
@ -43,11 +46,16 @@ class UserController extends Controller {
* @return mixed * @return mixed
*/ */
public function actionIndex() { public function actionIndex() {
$this->view->title = "Người dùng";
$this->view->params['breadcrumbs'][] = "Hệ thống";
$this->view->params['breadcrumbs'][] = $this->view->title;
$searchModel = new UserSearch(); $searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->renderAjax("index", [
return $this->render('index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider 'dataProvider' => $dataProvider,
]); ]);
} }
@ -84,6 +92,14 @@ class UserController extends Controller {
* @return mixed * @return mixed
*/ */
public function actionCreate() { public function actionCreate() {
if (!Yii::$app->user->can("administrator")) {
Yii::$app->response->format = "json";
return [
"title" => "403",
"form" => Yii::t("app", "Bạn không có quyền truy cập!")
];
}
$model = new User(); $model = new User();
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$post = Yii::$app->request->post(); $post = Yii::$app->request->post();
@ -111,8 +127,7 @@ class UserController extends Controller {
} }
} }
return [ return [
'stt' => true, 'stt' => true
'url' => Url::to(['/user'])
]; ];
} else { } else {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
@ -135,6 +150,14 @@ class UserController extends Controller {
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */
public function actionUpdate($id) { public function actionUpdate($id) {
if (!Yii::$app->user->can("administrator")) {
Yii::$app->response->format = "json";
return [
"title" => "403",
"form" => Yii::t("app", "Bạn không có quyền truy cập!")
];
}
$model = $this->findModel($id); $model = $this->findModel($id);
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$post = Yii::$app->request->post(); $post = Yii::$app->request->post();
@ -150,6 +173,7 @@ class UserController extends Controller {
$model->username = $post['Username']; $model->username = $post['Username'];
$model->phone_number = $post['PhoneNumber']; $model->phone_number = $post['PhoneNumber'];
$model->email = $post['Email']; $model->email = $post['Email'];
$model->quota = $post['Quota'];
$model->save(); $model->save();
AuthAssignment::deleteAll(['user_id' => $id]); AuthAssignment::deleteAll(['user_id' => $id]);
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;
@ -159,11 +183,7 @@ class UserController extends Controller {
$auth->assign($role, $id); $auth->assign($role, $id);
} }
} }
Yii::$app->response->format = "json"; return true;
return [
'stt' => true,
'url' => Url::to(['/user'])
];
} else { } else {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
return [ return [
@ -185,12 +205,13 @@ class UserController extends Controller {
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */
public function actionDelete($id) { public function actionDelete($id) {
if (Yii::$app->request->isAjax) { if (!Yii::$app->user->can("administrator")) {
throw new \yii\web\ForbiddenHttpException(Yii::t("app", "Bạn không có quyền truy cập!"));
}
$this->findModel($id)->delete(); $this->findModel($id)->delete();
AuthAssignment::deleteAll(['user_id' => $id]); AuthAssignment::deleteAll(['user_id' => $id]);
Yii::$app->response->format = "json"; return $this->redirect(['index']);
return ["url" => Url::to(['/user'])];
}
} }
/** /**
@ -209,27 +230,27 @@ class UserController extends Controller {
} }
public function actionProfiles() { public function actionProfiles() {
if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']);
}
$model = $this->findModel(Yii::$app->user->id); $model = $this->findModel(Yii::$app->user->id);
$this->view->title = Yii::t("app", "Thông tin cá nhân");
$this->view->params['breadcrumbs'][] = $this->view->title;
return $this->render('profiles', [
"model" => $model
]);
}
public function actionInfo($id) {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$model = $this->findModel($id);
$post = Yii::$app->request->post(); $post = Yii::$app->request->post();
$model->first_name = $post['Name']; $model->first_name = $post['Name'];
$model->phone_number = $post['PhoneNumber']; $model->phone_number = $post['PhoneNumber'];
$model->email = $post['Email']; $model->email = $post['Email'];
return $model->save(); return $model->save();
} else {
Yii::$app->response->format = "json";
if (Yii::$app->user->isGuest) {
return [
"title" => "Lỗi",
"form" => "Bạn chưa đăng nhập hệ thống"
];
}
return [
"title" => "Thông tin cá nhân",
"form" => $this->renderPartial('profiles', [
"model" => $model
])
];
} }
} }
@ -241,19 +262,15 @@ class UserController extends Controller {
$model->save(); $model->save();
return true; return true;
} else { } else {
Yii::$app->response->format = "json";
if (Yii::$app->user->isGuest) { if (Yii::$app->user->isGuest) {
return [ return $this->redirect(['/site/login']);
"title" => "Lỗi",
"form" => "Bạn chưa đăng nhập hệ thống"
];
} }
return [ $this->view->title = Yii::t("app", "Đổi mật khẩu");
"title" => "Đổi mật khẩu", $this->view->params['breadcrumbs'][] = $this->view->title;
"form" => $this->renderPartial('password', [
return $this->render('password', [
"model" => $model "model" => $model
]) ]);
];
} }
} }

BIN
db/app.db

Binary file not shown.

View File

@ -166,8 +166,9 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
{$username=Yii::$app->user->identity->username}
<ul class="tree"> <ul class="tree">
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c1" /> <input type="checkbox" checked="checked" id="c1" />
<label class="tree_label" for="c1">camera</label> <label class="tree_label" for="c1">camera</label>
<ul> <ul>
@ -360,7 +361,7 @@
</li> </li>
</ul> </ul>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c2" /> <input type="checkbox" checked="checked" id="c2" />
<label class="tree_label" for="c2">face_verify</label> <label class="tree_label" for="c2">face_verify</label>
<ul> <ul>
@ -449,7 +450,7 @@
</li> </li>
</ul> </ul>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c3" /> <input type="checkbox" checked="checked" id="c3" />
<label class="tree_label" for="c3">haarcascade</label> <label class="tree_label" for="c3">haarcascade</label>
<ul> <ul>
@ -489,7 +490,7 @@
<input type="checkbox" checked="checked" id="c4" /> <input type="checkbox" checked="checked" id="c4" />
<label class="tree_label" for="c4">engine</label> <label class="tree_label" for="c4">engine</label>
<ul> <ul>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c41" /> <input type="checkbox" checked="checked" id="c41" />
<label class="tree_label" for="c41">max_fps</label>: <label class="tree_label" for="c41">max_fps</label>:
<div contenteditable="" id="text-c41" class="editform">{$config_json.engine.max_fps}</div> <div contenteditable="" id="text-c41" class="editform">{$config_json.engine.max_fps}</div>
@ -510,12 +511,12 @@
<input type="checkbox" checked="checked" id="c5" /> <input type="checkbox" checked="checked" id="c5" />
<label class="tree_label" for="c5">recognition</label> <label class="tree_label" for="c5">recognition</label>
<ul> <ul>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c51" /> <input type="checkbox" checked="checked" id="c51" />
<label class="tree_label" for="c51">enable</label>: <label class="tree_label" for="c51">enable</label>:
<div contenteditable="" id="text-c51" class="editform">{$config_json.recognition.enable}</div> <div contenteditable="" id="text-c51" class="editform">{$config_json.recognition.enable}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c52" /> <input type="checkbox" checked="checked" id="c52" />
<label class="tree_label" for="c52">accuracy</label>: <label class="tree_label" for="c52">accuracy</label>:
<div contenteditable="" id="text-c52" class="editform">{$config_json.recognition.accuracy}</div> <div contenteditable="" id="text-c52" class="editform">{$config_json.recognition.accuracy}</div>
@ -525,29 +526,29 @@
<label class="tree_label" for="c53">server_recog</label>: <label class="tree_label" for="c53">server_recog</label>:
<div contenteditable="" id="text-c53" class="editform">{$config_json.recognition.server_recog}</div> <div contenteditable="" id="text-c53" class="editform">{$config_json.recognition.server_recog}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c54" /> <input type="checkbox" checked="checked" id="c54" />
<label class="tree_label" for="c54">request_timeout</label>: <label class="tree_label" for="c54">request_timeout</label>:
<div contenteditable="" id="text-c54" class="editform">{$config_json.recognition.request_timeout}</div> <div contenteditable="" id="text-c54" class="editform">{$config_json.recognition.request_timeout}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c55" /> <input type="checkbox" checked="checked" id="c55" />
<label class="tree_label" for="c55">num_face_recog</label>: <label class="tree_label" for="c55">num_face_recog</label>:
<div contenteditable="" id="text-c55" class="editform">{$config_json.recognition.num_face_recog}</div> <div contenteditable="" id="text-c55" class="editform">{$config_json.recognition.num_face_recog}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c56" /> <input type="checkbox" checked="checked" id="c56" />
<label class="tree_label" for="c56">first_time_recog</label>: <label class="tree_label" for="c56">first_time_recog</label>:
<div contenteditable="" id="text-c56" class="editform">{$config_json.recognition.first_time_recog}</div> <div contenteditable="" id="text-c56" class="editform">{$config_json.recognition.first_time_recog}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c57" /> <input type="checkbox" checked="checked" id="c57" />
<label class="tree_label" for="c57">next_time_recog</label>: <label class="tree_label" for="c57">next_time_recog</label>:
<div contenteditable="" id="text-c57" class="editform">{$config_json.recognition.next_time_recog}</div> <div contenteditable="" id="text-c57" class="editform">{$config_json.recognition.next_time_recog}</div>
</li> </li>
</ul> </ul>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c6" /> <input type="checkbox" checked="checked" id="c6" />
<label class="tree_label" for="c6">screen</label> <label class="tree_label" for="c6">screen</label>
<ul> <ul>
@ -573,12 +574,12 @@
</li> </li>
</ul> </ul>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c7" /> <input type="checkbox" checked="checked" id="c7" />
<label class="tree_label" for="c7">id_city</label> <label class="tree_label" for="c7">id_city</label>
<div contenteditable="" id="text-c7" class="editform">{$config_json.id_city}</div> <div contenteditable="" id="text-c7" class="editform">{$config_json.id_city}</div>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c8" /> <input type="checkbox" checked="checked" id="c8" />
<label class="tree_label" for="c8">open_door</label> <label class="tree_label" for="c8">open_door</label>
<ul> <ul>
@ -594,7 +595,7 @@
</li> </li>
</ul> </ul>
</li> </li>
<li> <li {if $username!='admin'}class='hidden'{/if}>
<input type="checkbox" checked="checked" id="c9" /> <input type="checkbox" checked="checked" id="c9" />
<label class="tree_label" for="c9">log</label> <label class="tree_label" for="c9">log</label>
<ul> <ul>

View File

@ -43,8 +43,7 @@
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">server IP</div> <div class="input-group-addon">server IP</div>
{$temp=explode(":",$apiConfig.servermqtt)} <input type="input" class="form-control" name="servermqtt" value="{$ip}">
<input type="input" class="form-control" name="servermqtt" value="{$temp.0}">
</div> </div>
</div> </div>
<div class="text-center"> <div class="text-center">

View File

@ -1,30 +1,23 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"} {use class="yii\helpers\Url"}
{use class="yii\grid\GridView"} {use class="yii\grid\GridView"}
{use class="yii\widgets\Pjax" type="block"} {use class="app\assets\UserAsset"}
<style> {UserAsset::register($this)|void}
.table-user thead tr:first-child{ {block name='content'}
background: #eaeaea; {if \Yii::$app->user->can("administrator")}
}
.table-user thead tr .form-control{
height: 25px;
font-size: 12px;
}
</style>
<div class="text-left"> <div class="text-left">
<button class="btn btn-primary btn-xs" onclick="user.form(this);" data-href="{Url::to(['/user/create'])}"> <button class="btn btn-primary" onclick="user.form(this);" data-href="{Url::to(['/user/create'])}">
<i class="fa fa-plus"></i> Thêm mới <i class="fa fa-plus"></i> Thêm mới
</button> </button>
</div> </div>
{/if}
<br> <br>
<div style="font-size: 12px;">
{Pjax id="user-list-modal" enablePushState=false timeout=false enableReplaceState=false}
{GridView::widget([ {GridView::widget([
'id' => 'user-list-gridview',
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'layout'=> \app\helpers\UserGrid::getLayout(), 'layout'=> \app\helpers\UserGrid::getLayout(),
'tableOptions' => [ 'tableOptions' => [
'class' => 'table table-striped table-bordered table-user', 'class' => 'table table-striped table-bordered',
'style' => 'background:#fff;min-width:700px;' 'style' => 'background:#fff;min-width:700px;'
], ],
'columns' => [ 'columns' => [
@ -51,5 +44,4 @@
] ]
] ]
])} ])}
{/Pjax} {/block}
</div>

View File

@ -1,4 +1,14 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
{use class="app\assets\UserAsset"}
{UserAsset::register($this)|void}
{block name='content'}
<br>
<div class="row">
<div class="col-md-4 col-md-push-4">
<input type="hidden" value="{$model->password}" name="password"> <input type="hidden" value="{$model->password}" name="password">
<div class="well" style="background: #fff;">
<div class="form-group" id="old-password"> <div class="form-group" id="old-password">
<label class="control-label">Mật khẩu cũ</label> <label class="control-label">Mật khẩu cũ</label>
<input type="password" class="form-control" name="OldPassword"> <input type="password" class="form-control" name="OldPassword">
@ -18,7 +28,11 @@
<i class="fa fa-check"></i> Đổi mật khẩu thành công! <i class="fa fa-check"></i> Đổi mật khẩu thành công!
</div> </div>
<div class="text-center"> <div class="text-center">
<button class="btn btn-primary" onclick="user.changePassword(this);" data-href="{yii\helpers\Url::to(['/user/change-password','id'=>$model->id])}"> <button class="btn btn-primary" onclick="user.password(this);" data-href="{Url::to(['/user/change-password','id'=>$model->id])}">
<i class="fa fa-lock"></i> Đổi mật khẩu <i class="fa fa-lock"></i> Đổi mật khẩu
</button> </button>
</div> </div>
</div>
</div>
</div>
{/block}

View File

@ -1,3 +1,13 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
{use class="app\assets\UserAsset"}
{UserAsset::register($this)|void}
{block name='content'}
<br>
<div class="row">
<div class="col-md-4 col-md-push-4">
<div class="well" style="background: #fff;">
<div class="text-center"> <div class="text-center">
{$directoryAsset=Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist')} {$directoryAsset=Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist')}
{if !Yii::$app->user->isGuest} {if !Yii::$app->user->isGuest}
@ -11,7 +21,7 @@
<img src="{$img}" id="avatar" class="img-thumbnail img-circle" style="width: 100px;height: 100px;cursor: pointer;" onclick="$('#image').trigger('click');"> <img src="{$img}" id="avatar" class="img-thumbnail img-circle" style="width: 100px;height: 100px;cursor: pointer;" onclick="$('#image').trigger('click');">
<div class="hidden"> <div class="hidden">
<input type="file" name="image" id="image"> <input type="file" name="image" id="image">
<input type="hidden" name="url_upload_avatar" value="{yii\helpers\Url::to(['/user/avatar'])}"> <input type="hidden" name="url_upload_avatar" value="{Url::to(['/user/avatar'])}">
</div> </div>
</div> </div>
<br> <br>
@ -45,7 +55,11 @@
<i class="fa fa-check"></i> Thông tin đã được lưu lại! <i class="fa fa-check"></i> Thông tin đã được lưu lại!
</div> </div>
<div class="text-center"> <div class="text-center">
<button class="btn btn-primary" onclick="user.saveInfo(this);" data-href="{yii\helpers\Url::to(['/user/profiles','id'=>$model->id])}"> <button class="btn btn-primary" onclick="user.saveInfo(this);" data-href="{Url::to(['/user/info','id'=>$model->id])}">
<i class="fa fa-floppy-o"></i> Lưu lại <i class="fa fa-floppy-o"></i> Lưu lại
</button> </button>
</div> </div>
</div>
</div>
</div>
{/block}