File tree Expand file tree Collapse file tree 3 files changed +15
-24
lines changed Expand file tree Collapse file tree 3 files changed +15
-24
lines changed Original file line number Diff line number Diff line change @@ -118,17 +118,15 @@ public function actionContact()
118118 */
119119 public function actionAccount ()
120120 {
121- $ userModel = Yii::$ app ->user ->identity ;
122- $ resetPasswordForm = new ResetPasswordForm ($ userModel );
121+ $ resetPasswordForm = new ResetPasswordForm (Yii::$ app ->user ->identity );
123122
124123 if ($ resetPasswordForm ->load (Yii::$ app ->request ->post ()) && $ resetPasswordForm ->resetPassword ()) {
125124 Yii::$ app ->session ->setFlash ('success ' , Yii::t ('user ' , 'Password has been updated. ' ));
126125 return $ this ->refresh ();
127126 }
128127
129128 return $ this ->render ('account ' , [
130- 'resetPasswordForm ' => $ resetPasswordForm ,
131- 'userModel ' => $ userModel
129+ 'resetPasswordForm ' => $ resetPasswordForm
132130 ]);
133131 }
134132}
Original file line number Diff line number Diff line change 44
55use app \models \UserModel ;
66use Yii ;
7- use yii \base \InvalidConfigException ;
87use yii \base \Model ;
98
109/**
1413class ResetPasswordForm extends Model
1514{
1615 /**
17- * @var string Password
16+ * @var string password
1817 */
1918 public $ password ;
2019
@@ -29,19 +28,15 @@ class ResetPasswordForm extends Model
2928 private $ _user ;
3029
3130 /**
32- * Construct
31+ * ResetPasswordForm constructor.
3332 *
3433 * @param UserModel $user
35- * @param array $config name-value pairs that will be used to initialize the object properties
36- *
37- * @throws InvalidConfigException
34+ * @param array $config
3835 */
39- public function __construct ($ user , $ config = [])
36+ public function __construct (UserModel $ user , $ config = [])
4037 {
4138 $ this ->_user = $ user ;
42- if (!$ this ->_user ) {
43- throw new InvalidConfigException ('UserModel must be set. ' );
44- }
39+
4540 parent ::__construct ($ config );
4641 }
4742
@@ -77,12 +72,11 @@ public function attributeLabels()
7772 */
7873 public function resetPassword ()
7974 {
80- $ user = $ this ->_user ;
8175 if ($ this ->validate ()) {
82- $ user ->setPassword ($ this ->password );
83- return $ user ->save (true , ['passwordHash ' ]);
84- } else {
85- return false ;
76+ $ this ->_user ->setPassword ($ this ->password );
77+ return $ this ->_user ->save (true , ['passwordHash ' ]);
8678 }
79+
80+ return false ;
8781 }
8882}
Original file line number Diff line number Diff line change 55use yii \widgets \DetailView ;
66
77/* @var $resetPasswordForm \app\models\forms\ResetPasswordForm */
8- /* @var $userModel \app\models\UserModel */
98
109$ this ->title = Yii::t ('user ' , 'My Account ' );
1110?>
3635 </div>
3736 <div class="table-responsive">
3837 <?php echo DetailView::widget ([
39- 'model ' => $ userModel ,
38+ 'model ' => Yii:: $ app -> user -> identity ,
4039 'attributes ' => [
41- " username " ,
42- " email " ,
40+ ' username ' ,
41+ ' email ' ,
4342 'lastLogin:date '
4443 ],
4544 ]); ?>
4645 </div>
4746 </div>
4847 </div>
4948 </div>
50- </div>
49+ </div>
You can’t perform that action at this time.
0 commit comments