@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function findByPasswordResetToken($token) |
| 145 | 145 | { |
| 146 | - if(!$this->isTokenCurrent($token)) { |
|
| 146 | + if (!$this->isTokenCurrent($token)) { |
|
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | 149 | |
@@ -161,15 +161,15 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function findByVerifyEmailToken($token) |
| 163 | 163 | { |
| 164 | - if($this->isTokenConfirmed($token)) return null; |
|
| 164 | + if ($this->isTokenConfirmed($token)) return null; |
|
| 165 | 165 | |
| 166 | 166 | $user = $this->findOne([ |
| 167 | 167 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
| 168 | 168 | 'status' => self::STATUS_ACTIVE, |
| 169 | 169 | ]); |
| 170 | 170 | |
| 171 | - if($user) { |
|
| 172 | - if(!$this->isTokenConfirmed($token) && |
|
| 171 | + if ($user) { |
|
| 172 | + if (!$this->isTokenConfirmed($token) && |
|
| 173 | 173 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
| 174 | 174 | return null; |
| 175 | 175 | } |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | 'status' => self::STATUS_ACTIVE, |
| 192 | 192 | ]); |
| 193 | 193 | |
| 194 | - if($user) { |
|
| 195 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 194 | + if ($user) { |
|
| 195 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 196 | 196 | return null; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
| 211 | 211 | $expire = \Yii::$app->params[$paramPath]; |
| 212 | 212 | $parts = explode('_', $token); |
| 213 | - $timestamp = (int) end($parts); |
|
| 213 | + $timestamp = (int)end($parts); |
|
| 214 | 214 | if ($timestamp + $expire < time()) { |
| 215 | 215 | // token expired |
| 216 | 216 | return false; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param string $match the needle to search for |
| 226 | 226 | */ |
| 227 | 227 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 228 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 228 | + if (is_null($token)) $token = $this->verify_email_token; |
|
| 229 | 229 | return substr($token, -strlen($match)) === $match; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function isVerified() { |
| 253 | - if(is_null($this->verify_email_token)) { |
|
| 253 | + if (is_null($this->verify_email_token)) { |
|
| 254 | 254 | // for old users who verified their accounts before the addition of |
| 255 | 255 | // '_confirmed' to the token |
| 256 | 256 | return true; |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | public function sendEmailReport($date) { |
| 359 | - if(!$this->isPartnerEnabled()) return false; // no partner emails set |
|
| 359 | + if (!$this->isPartnerEnabled()) return false; // no partner emails set |
|
| 360 | 360 | |
| 361 | 361 | list($start, $end) = $this->time->getUTCBookends($date); |
| 362 | 362 | |
@@ -366,12 +366,12 @@ discard block |
||
| 366 | 366 | ->create($scores_of_month); |
| 367 | 367 | |
| 368 | 368 | $score = $this->user_behavior->calculateScoreByUTCRange($start, $end); |
| 369 | - $user_behaviors = $this->getUserBehaviors($date); |
|
| 369 | + $user_behaviors = $this->getUserBehaviors($date); |
|
| 370 | 370 | $user_questions = $this->getUserQuestions($date); |
| 371 | 371 | |
| 372 | 372 | $messages = []; |
| 373 | - foreach($this->getPartnerEmails() as $email) { |
|
| 374 | - if($email) { |
|
| 373 | + foreach ($this->getPartnerEmails() as $email) { |
|
| 374 | + if ($email) { |
|
| 375 | 375 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
| 376 | 376 | 'user' => $this, |
| 377 | 377 | 'email' => $email, |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
| 385 | 385 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 386 | 386 | ->setReplyTo($this->email) |
| 387 | - ->setSubject($this->email." has scored high in The Faster Scale App") |
|
| 387 | + ->setSubject($this->email . " has scored high in The Faster Scale App") |
|
| 388 | 388 | ->setTo($email); |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | return \Yii::$app->mailer->compose('signupNotification') |
| 458 | 458 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 459 | 459 | ->setTo(\Yii::$app->params['adminEmail']) |
| 460 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
| 460 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
| 461 | 461 | ->send(); |
| 462 | 462 | } |
| 463 | 463 | |
@@ -465,22 +465,22 @@ discard block |
||
| 465 | 465 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
| 466 | 466 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 467 | 467 | ->setTo($this->email) |
| 468 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
| 468 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
| 469 | 469 | ->send(); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | public function sendDeleteNotificationEmail() { |
| 473 | - if($this->isPartnerEnabled()) return false; // no partner emails set |
|
| 473 | + if ($this->isPartnerEnabled()) return false; // no partner emails set |
|
| 474 | 474 | |
| 475 | 475 | $messages = []; |
| 476 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 477 | - if($email) { |
|
| 476 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 477 | + if ($email) { |
|
| 478 | 478 | $messages[] = Yii::$app->mailer->compose('partnerDeleteNotification', [ |
| 479 | 479 | 'user' => $this, |
| 480 | 480 | 'email' => $email |
| 481 | 481 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 482 | 482 | ->setReplyTo($this->email) |
| 483 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
| 483 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
| 484 | 484 | ->setTo($email); |
| 485 | 485 | } |
| 486 | 486 | } |
@@ -489,13 +489,13 @@ discard block |
||
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | public function getUserQuestions($local_date = null) { |
| 492 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 492 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 493 | 493 | $questions = $this->getQuestionData($local_date); |
| 494 | 494 | return $this->parseQuestionData($questions); |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | public function getUserBehaviors($local_date = null) { |
| 498 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 498 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 499 | 499 | |
| 500 | 500 | $behaviors = $this->getBehaviorData($local_date); |
| 501 | 501 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -503,10 +503,10 @@ discard block |
||
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | public function parseQuestionData($questions) { |
| 506 | - if(!$questions) return []; |
|
| 506 | + if (!$questions) return []; |
|
| 507 | 507 | |
| 508 | 508 | $question_answers = []; |
| 509 | - foreach($questions as $question) { |
|
| 509 | + foreach ($questions as $question) { |
|
| 510 | 510 | $behavior = $question['behavior']; |
| 511 | 511 | |
| 512 | 512 | $question_answers[$behavior['id']]['question'] = [ |
@@ -524,10 +524,10 @@ discard block |
||
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | public function parseBehaviorData($behaviors) { |
| 527 | - if(!$behaviors) return []; |
|
| 527 | + if (!$behaviors) return []; |
|
| 528 | 528 | |
| 529 | 529 | $opts_by_cat = []; |
| 530 | - foreach($behaviors as $behavior) { |
|
| 530 | + foreach ($behaviors as $behavior) { |
|
| 531 | 531 | $indx = $behavior['behavior']['category_id']; |
| 532 | 532 | |
| 533 | 533 | $opts_by_cat[$indx]['category_name'] = $behavior['behavior']['category']['name']; |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | public function isPartnerEnabled() { |
| 579 | - if((is_integer($this->email_threshold) |
|
| 579 | + if ((is_integer($this->email_threshold) |
|
| 580 | 580 | && $this->email_threshold >= 0) |
| 581 | 581 | && ($this->partner_email1 |
| 582 | 582 | || $this->partner_email2 |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | public function isOverThreshold($score) { |
| 590 | - if(!$this->isPartnerEnabled()) return false; |
|
| 590 | + if (!$this->isPartnerEnabled()) return false; |
|
| 591 | 591 | |
| 592 | 592 | $threshold = $this->email_threshold; |
| 593 | 593 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | return rtrim( |
| 641 | 641 | strtr( |
| 642 | 642 | base64_encode( |
| 643 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
| 643 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
| 644 | 644 | ), |
| 645 | 645 | '+/', '-_'), |
| 646 | 646 | '='); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | 'allow' => true, |
| 28 | 28 | 'roles' => ['@'], |
| 29 | 29 | ], [ |
| 30 | - 'actions' => [ 'change-email', ], |
|
| 30 | + 'actions' => ['change-email', ], |
|
| 31 | 31 | 'allow' => true, |
| 32 | 32 | ], |
| 33 | 33 | ], |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | if ($editProfileForm->load(Yii::$app->request->post())) { |
| 74 | 74 | $saved_user = $editProfileForm->saveProfile(); |
| 75 | - if($saved_user) { |
|
| 75 | + if ($saved_user) { |
|
| 76 | 76 | Yii::$app->getSession()->setFlash('success', 'New profile data saved!'); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $model = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
| 91 | 91 | |
| 92 | 92 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
| 93 | - if($model->deleteAccount()) { |
|
| 93 | + if ($model->deleteAccount()) { |
|
| 94 | 94 | $this->redirect(['site/index']); |
| 95 | 95 | } else { |
| 96 | 96 | Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $model = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
| 105 | 105 | |
| 106 | 106 | if ($model->load(Yii::$app->request->post())) { |
| 107 | - if($model->validate() && $model->changePassword()) { |
|
| 107 | + if ($model->validate() && $model->changePassword()) { |
|
| 108 | 108 | Yii::$app->getSession()->setFlash('success', 'Password successfully changed'); |
| 109 | 109 | } else { |
| 110 | 110 | Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | $model = Yii::$container->get(\site\models\ChangeEmailForm::class, [Yii::$app->user->identity]); |
| 119 | 119 | |
| 120 | 120 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
| 121 | - if($model->changeEmail()) { |
|
| 121 | + if ($model->changeEmail()) { |
|
| 122 | 122 | Yii::$app->getSession()->setFlash('success', "We've sent an email to your requested email address to confirm. Please click on the verification link to continue."); |
| 123 | 123 | } else { |
| 124 | 124 | Yii::$app->getSession()->setFlash('error', 'Something went wrong!'); |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | public function actionChangeEmail(string $token) { |
| 132 | 132 | $user = \common\models\User::findByChangeEmailToken($token); |
| 133 | - if($user) { |
|
| 133 | + if ($user) { |
|
| 134 | 134 | $validator = new \yii\validators\EmailValidator(); |
| 135 | - if($validator->validate($user->desired_email, $error)) { |
|
| 135 | + if ($validator->validate($user->desired_email, $error)) { |
|
| 136 | 136 | $user->removeChangeEmailToken(); |
| 137 | 137 | $user->email = $user->desired_email; |
| 138 | 138 | $user->desired_email = null; |
| 139 | 139 | $user->save(); |
| 140 | - if(!Yii::$app->user->isGuest) { |
|
| 140 | + if (!Yii::$app->user->isGuest) { |
|
| 141 | 141 | Yii::$app->user->logout(); |
| 142 | 142 | Yii::$app->session->setFlash('success', 'Your email address was successfully changed. For security, we\'ve logged you out.'); |
| 143 | 143 | } else { |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | public function actionExport() { |
| 159 | 159 | header("Content-Type: text/csv"); |
| 160 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
| 160 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
| 161 | 161 | |
| 162 | 162 | $reader = Yii::$app->user->identity->getExportData(); |
| 163 | 163 | $fp = fopen('php://output', 'w'); |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | fputcsv($fp, $header); |
| 175 | 175 | $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
| 176 | - while($row = $reader->read()) { |
|
| 176 | + while ($row = $reader->read()) { |
|
| 177 | 177 | $row = $user_behavior::decorateWithCategory([$row]); |
| 178 | 178 | $row = Yii::$app->user->identity->cleanExportData($row); |
| 179 | 179 | fputcsv($fp, $row[0]); |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | // check that the desired_email is not already the email of another user |
| 49 | 49 | $user = $this->user->findByEmail($this->desired_email); |
| 50 | 50 | // if it is, we do nothing and return true, don't leak the data |
| 51 | - if(!$user) { |
|
| 51 | + if (!$user) { |
|
| 52 | 52 | $this->user->desired_email = $this->desired_email; |
| 53 | 53 | $this->user->generateChangeEmailToken(); |
| 54 | 54 | $this->user->save(); |