Completed
Pull Request — master (#164)
by Corey
03:18
created
common/models/User.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     '=');
Please login to merge, or discard this patch.
site/models/ChangeEmailForm.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
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();
Please login to merge, or discard this patch.
site/views/profile/index.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@
 block discarded – undo
24 24
   ]); ?>
25 25
           <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?>
26 26
           <?= $form->field($profile, 'expose_graph')->checkbox() ?>
27
-          <?php if($profile->expose_graph): ?>
27
+          <?php if ($profile->expose_graph): ?>
28 28
           <div class='alert alert-success score-graph-info'>Your score graph can be found at:<br /> <a id="score-graph-link" target="_blank" href="<?=$graph_url?>"><?=$graph_url?></a></div>
29 29
           <?php endif; ?>
30 30
         <?= $form->field($profile, 'send_email')->checkbox() ?>
31
-        <div id='email_threshold_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>>
31
+        <div id='email_threshold_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>>
32 32
           <?= $form->field($profile, 'email_threshold')->textInput(['class'=>'form-control', 'style'=>'width: 50px;'])->input('number', ['min' => 0, 'max' => 1000]) ?>
33 33
           <?= $form->field($profile, 'partner_email1')->input('email'); ?>
34 34
           <?= $form->field($profile, 'partner_email2')->input('email'); ?>
Please login to merge, or discard this patch.
site/models/EditProfileForm.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
       $graph = Yii::$container
82 82
         ->get(\common\components\Graph::class, [$this->user]);
83 83
 
84
-      if($this->timezone)
84
+      if ($this->timezone)
85 85
         $user->timezone = $this->timezone;
86
-      if($this->expose_graph) {
86
+      if ($this->expose_graph) {
87 87
         $user->expose_graph = true;
88 88
 
89 89
         // generate scores graph image
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         // if they haven't done a check-in in the last month this
92 92
         // will explode because $scores_last_month is an empty
93 93
         // array
94
-        if($scores_last_month) {
94
+        if ($scores_last_month) {
95 95
           $graph->create($scores_last_month, true);
96 96
         }
97 97
       } else {
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         // remove scores graph image
100 100
         $graph->destroy();
101 101
       }
102
-      if($this->send_email) {
102
+      if ($this->send_email) {
103 103
         $user->email_threshold = $this->email_threshold;
104 104
         $user->partner_email1  = $this->partner_email1;
105 105
         $user->partner_email2  = $this->partner_email2;
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@
 block discarded – undo
81 81
       $graph = Yii::$container
82 82
         ->get(\common\components\Graph::class, [$this->user]);
83 83
 
84
-      if($this->timezone)
85
-        $user->timezone = $this->timezone;
84
+      if($this->timezone) {
85
+              $user->timezone = $this->timezone;
86
+      }
86 87
       if($this->expose_graph) {
87 88
         $user->expose_graph = true;
88 89
 
Please login to merge, or discard this patch.
site/controllers/ProfileController.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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!');
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 
128 128
   public function actionChangeEmail(string $token) {
129 129
     $user = \common\models\User::findByChangeEmailToken($token);
130
-    if($user) {
130
+    if ($user) {
131 131
       $validator = new \yii\validators\EmailValidator();
132
-      if($validator->validate($user->desired_email, $error)) {
132
+      if ($validator->validate($user->desired_email, $error)) {
133 133
         $user->removeChangeEmailToken();
134 134
         $user->email = $user->desired_email;
135 135
         $user->desired_email = null;
136 136
         $user->save();
137
-        if(!Yii::$app->user->isGuest) {
137
+        if (!Yii::$app->user->isGuest) {
138 138
           Yii::$app->user->logout();
139 139
           Yii::$app->session->setFlash('success', 'Your email address was successfully changed. For security, we\'ve logged you out.');
140 140
         } else {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
   public function actionExport() {
156 156
     header("Content-Type: text/csv");
157
-    header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv");
157
+    header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv");
158 158
 
159 159
     $reader = Yii::$app->user->identity->getExportData();
160 160
     $fp = fopen('php://output', 'w');
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
     fputcsv($fp, $header);
172 172
     $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class);
173
-    while($row = $reader->read()) {
173
+    while ($row = $reader->read()) {
174 174
       $row = $user_behavior::decorateWithCategory([$row]);
175 175
       $row = Yii::$app->user->identity->cleanExportData($row);
176 176
       fputcsv($fp, $row[0]);
Please login to merge, or discard this patch.