@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | public function actionIndex() |
| 72 | 72 | { |
| 73 | 73 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 74 | - $key = "index_blog_".$time->getLocalDate('UTC'); |
|
| 74 | + $key = "index_blog_" . $time->getLocalDate('UTC'); |
|
| 75 | 75 | $posts = Yii::$app->cache->get($key); |
| 76 | - if($posts === false) { |
|
| 76 | + if ($posts === false) { |
|
| 77 | 77 | $posts = \Yii::$app->getModule('blog') |
| 78 | 78 | ->fetch() |
| 79 | 79 | ->parse() |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | { |
| 107 | 107 | $model = new ContactForm(); |
| 108 | 108 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
| 109 | - if($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
| 109 | + if ($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
| 110 | 110 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.'); |
| 111 | 111 | } else { |
| 112 | 112 | Yii::$app->session->setFlash('error', 'There was an error sending email.'); |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | public function actionSignup() |
| 139 | 139 | { |
| 140 | 140 | $model = Yii::$container->get(\site\models\SignupForm::class); |
| 141 | - if($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
| 141 | + if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
| 142 | 142 | $model->signup(); |
| 143 | 143 | Yii::$app->getSession()->setFlash('success', 'We have sent a verification email to the email address you provided. Please check your inbox and follow the instructions to verify your account.'); |
| 144 | - return $this->redirect('/',302); |
|
| 144 | + return $this->redirect('/', 302); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $this->render('signup', [ |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | public function actionRequestPasswordReset() |
| 153 | 153 | { |
| 154 | 154 | $model = Yii::$container->get(\site\models\PasswordResetRequestForm::class); |
| 155 | - if($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
| 156 | - if(!$model->sendEmail()) { |
|
| 155 | + if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
| 156 | + if (!$model->sendEmail()) { |
|
| 157 | 157 | $ip = Yii::$app->getRequest()->getUserIP() ?: "UNKNOWN"; |
| 158 | - Yii::warning("$ip has tried to reset the password for ".$model->email); |
|
| 158 | + Yii::warning("$ip has tried to reset the password for " . $model->email); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | Yii::$app->getSession()->setFlash('success', 'If there is an account with the submitted email address you will receive further instructions in your email inbox.'); |
@@ -198,14 +198,14 @@ discard block |
||
| 198 | 198 | throw new BadRequestHttpException("Wrong or expired email verification token. If you aren't sure why this error occurs perhaps you've already verified your account. Please try logging in."); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if($user->isTokenConfirmed($user->verify_email_token)) { |
|
| 201 | + if ($user->isTokenConfirmed($user->verify_email_token)) { |
|
| 202 | 202 | Yii::$app->getSession()->setFlash('success', 'Your account has already been verified. Please log in.'); |
| 203 | - return $this->redirect('/login',302); |
|
| 203 | + return $this->redirect('/login', 302); |
|
| 204 | 204 | } else if (Yii::$app->getUser()->login($user)) { |
| 205 | 205 | $user->confirmVerifyEmailToken(); |
| 206 | 206 | $user->save(); |
| 207 | 207 | Yii::$app->getSession()->setFlash('success', 'Your account has been verified. Please continue with your check-in.'); |
| 208 | - return $this->redirect('/welcome',302); |
|
| 208 | + return $this->redirect('/welcome', 302); |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | $user = Yii::$container->get(\common\interfaces\UserInterface::class)->findByChangeEmailToken($token); |
| 219 | - var_dump( $user); |
|
| 219 | + var_dump($user); |
|
| 220 | 220 | exit(); |
| 221 | 221 | if (!$user) { |
| 222 | 222 | throw new BadRequestHttpException("Wrong or expired email change token. If you aren't sure why this error occurs perhaps you've already confirmed your change of email. Please try logging in."); |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // log out the user (if they're logged in) |
| 228 | 228 | |
| 229 | 229 | Yii::$app->getSession()->setFlash('success', 'Your email address has been successfully changed. Please log in.'); |
| 230 | - return $this->redirect('/login',302); |
|
| 230 | + return $this->redirect('/login', 302); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | public function actionPrivacy() |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | public function actionExport() |
| 244 | 244 | { |
| 245 | 245 | header("Content-Type: text/csv"); |
| 246 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
| 246 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
| 247 | 247 | |
| 248 | 248 | $reader = Yii::$app->user->identity->getExportData(); |
| 249 | 249 | $fp = fopen('php://output', 'w'); |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | fputcsv($fp, $header); |
| 261 | 261 | $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
| 262 | - while($row = $reader->read()) { |
|
| 262 | + while ($row = $reader->read()) { |
|
| 263 | 263 | $row = $user_behavior::decorateWithCategory([$row]); |
| 264 | 264 | $row = Yii::$app->user->identity->cleanExportData($row); |
| 265 | 265 | fputcsv($fp, $row[0]); |
@@ -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]); |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | public function changeEmail() { |
| 48 | 48 | $user = $this->user->findByEmail($this->desired_email); |
| 49 | - if(!$user) { |
|
| 49 | + if (!$user) { |
|
| 50 | 50 | $this->user->desired_email = $this->desired_email; |
| 51 | 51 | $this->user->generateChangeEmailToken(); |
| 52 | 52 | $this->user->save(); |