1
|
|
|
<?php |
2
|
|
|
namespace site\controllers; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use common\models\Question; |
7
|
|
|
use yii\web\Controller; |
8
|
|
|
use yii\filters\VerbFilter; |
9
|
|
|
use common\components\AccessControl; |
10
|
|
|
use League\Csv\Writer; |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Profile controller |
14
|
|
|
*/ |
15
|
|
|
class ProfileController extends Controller { |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function behaviors() { |
20
|
|
|
return [ |
21
|
|
|
'access' => [ |
22
|
|
|
'class' => AccessControl::class, |
23
|
|
|
'rules' => [ |
24
|
|
|
[ |
25
|
|
|
'actions' => ['index', 'error', 'delete-account', 'change-password', 'change-email', 'export'], |
26
|
|
|
'allow' => true, |
27
|
|
|
'roles' => ['@'], |
28
|
|
|
], |
29
|
|
|
], |
30
|
|
|
], |
31
|
|
|
'verbs' => [ |
32
|
|
|
'class' => VerbFilter::class, |
33
|
|
|
'actions' => [ |
34
|
|
|
'deleteAccount' => ['post'], |
35
|
|
|
'changePassword' => ['post'], |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function actions() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
'error' => [ |
48
|
|
|
'class' => 'yii\web\ErrorAction', |
49
|
|
|
], |
50
|
|
|
'captcha' => [ |
51
|
|
|
'class' => 'yii\captcha\CaptchaAction', |
52
|
|
|
], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function actionIndex() { |
57
|
|
|
$editProfileForm = Yii::$container->get(\site\models\EditProfileForm::class, [Yii::$app->user->identity]); |
58
|
|
|
$changePasswordForm = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
59
|
|
|
$changeEmailForm = Yii::$container->get(\site\models\ChangeEmailForm::class, [Yii::$app->user->identity]); |
60
|
|
|
$deleteAccountForm = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
61
|
|
|
$graph = Yii::$container->get(\common\components\Graph::class, [Yii::$app->user->identity]); |
62
|
|
|
|
63
|
|
|
if (Yii::$app->request->isAjax && $editProfileForm->load($_POST)) { |
64
|
|
|
Yii::$app->response->format = 'json'; |
65
|
|
|
return \yii\widgets\ActiveForm::validate($editProfileForm); |
66
|
|
|
} |
67
|
|
|
$editProfileForm->loadUser(); |
68
|
|
|
|
69
|
|
|
if ($editProfileForm->load(Yii::$app->request->post())) { |
70
|
|
|
$saved_user = $editProfileForm->saveProfile(); |
71
|
|
|
if($saved_user) { |
72
|
|
|
Yii::$app->getSession()->setFlash('success', 'New profile data saved!'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->render('index', [ |
77
|
|
|
'profile' => $editProfileForm, |
78
|
|
|
'change_password' => $changePasswordForm, |
79
|
|
|
'change_email' => $changeEmailForm, |
80
|
|
|
'delete' => $deleteAccountForm, |
81
|
|
|
'graph_url' => $graph->getUrl(Yii::$app->user->identity->getIdHash()), |
|
|
|
|
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function actionDeleteAccount() { |
86
|
|
|
$model = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
87
|
|
|
|
88
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
89
|
|
|
if($model->deleteAccount()) { |
90
|
|
|
$this->redirect(['site/index']); |
91
|
|
|
} else { |
92
|
|
|
Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->redirect(Yii::$app->request->getReferrer()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function actionChangePassword() { |
100
|
|
|
$model = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
101
|
|
|
|
102
|
|
|
if ($model->load(Yii::$app->request->post())) { |
103
|
|
|
if($model->validate() && $model->changePassword()) { |
104
|
|
|
Yii::$app->getSession()->setFlash('success', 'Password successfully changed'); |
105
|
|
|
} else { |
106
|
|
|
Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->redirect(['profile/index']); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function actionChangeEmail() { |
114
|
|
|
$model = Yii::$container->get(\site\models\ChangeEmailForm::class, [Yii::$app->user->identity]); |
115
|
|
|
|
116
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
117
|
|
|
if($model->changeEmail()) { |
118
|
|
|
Yii::$app->getSession()->setFlash('success', "We've sent an email to your requested email address to confirm. Please click on the verification link."); |
119
|
|
|
} else { |
120
|
|
|
Yii::$app->getSession()->setFlash('error', 'Something went wrong!'); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->redirect(['profile/index']); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function actionExport() { |
128
|
|
|
header("Content-Type: text/csv"); |
129
|
|
|
header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$reader = Yii::$app->user->identity->getExportData(); |
|
|
|
|
132
|
|
|
$fp = fopen('php://output', 'w'); |
133
|
|
|
|
134
|
|
|
$header = [ |
135
|
|
|
'Date', |
136
|
|
|
'Behavior', |
137
|
|
|
'Category', |
138
|
|
|
Question::$QUESTIONS[1], |
139
|
|
|
Question::$QUESTIONS[2], |
140
|
|
|
Question::$QUESTIONS[3], |
141
|
|
|
]; |
142
|
|
|
|
143
|
|
|
fputcsv($fp, $header); |
|
|
|
|
144
|
|
|
$user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
145
|
|
|
while($row = $reader->read()) { |
146
|
|
|
$row = $user_behavior::decorateWithCategory([$row]); |
147
|
|
|
$row = Yii::$app->user->identity->cleanExportData($row); |
|
|
|
|
148
|
|
|
fputcsv($fp, $row[0]); |
149
|
|
|
} |
150
|
|
|
fclose($fp); |
|
|
|
|
151
|
|
|
|
152
|
|
|
die; |
|
|
|
|
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths