AuthorController.php
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: stes
* Date: 11.06.18
* Time: 16:43
*/
namespace frontend\controllers;
use common\models\Book;
use frontend\helpers\Url;
use frontend\models\ChangePassword;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\Response;
use yii\web\UploadedFile;
class AuthorController extends Controller
{
public function actionIndex()
{
if (\Yii::$app->user->isGuest) {
return $this->redirect([ Url::home() ]);
}
/* @var \common\models\Author $user */
$user = \Yii::$app->user->identity;
$dataProvider = new ActiveDataProvider(
[
'query' => Book::find()
->where([ 'author_id' => $user->id ]),
'pagination' => [
'pageSize' => 10,
],
]
);
if ($user->load(\Yii::$app->request->post()) and $user->save()) {
$user->saveImage(UploadedFile::getInstanceByName('avatar'));
}
return $this->render(
'index',
[
'user' => $user,
'dataProvider' => $dataProvider,
]
);
}
public function actionChangePassword(){
\Yii::$app->response->format = Response::FORMAT_JSON;
$model = new ChangePassword();
if ($model->load(\Yii::$app->request->post(), '')){
return $model->changePassword();
}
}
}