Completed
Push — master ( 4923e3...d627d1 )
by Joel
01:58
created
mail/_confirmationEmail.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@
 block discarded – undo
3 3
 /* @var $model /yii/base/Model */
4 4
 use yii\helpers\Html;
5 5
 
6
-$link =  $model->getViewLink();
6
+$link = $model->getViewLink();
7 7
 ?>
8 8
 
9 9
 <p>Your details have been changed in <?=Yii::$app->name ?>. specifically:</p>
10 10
 
11
-  <?=  Html::ul(unserialize($model->values), ['item' => function($item, $index){return Html::tag('li', $index .' : ' . $item);}]) ?>
11
+  <?=  Html::ul(unserialize($model->values), ['item' => function($item, $index) {return Html::tag('li', $index . ' : ' . $item); }]) ?>
12 12
 
13 13
 <p>If these details are correct, please follow this link to 
14 14
     finalise your changes: <?= Html::a('Finalise link', $model->getViewLink()) ?></p>
Please login to merge, or discard this patch.
ConfirmationBehavior.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param $event Event;
91 91
      */
92 92
 
93
-    public function beforeSave($event){
93
+    public function beforeSave($event) {
94 94
         $this->protectAttributes();
95 95
     }
96 96
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute)
110 110
                 continue;
111 111
 
112
-            if(!$this->isAuthorised($user, $attribute, $value)){
112
+            if (!$this->isAuthorised($user, $attribute, $value)) {
113 113
                 $this->createConfirmationRequest();
114 114
                 $this->resetAttribute($attribute);
115 115
             }
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
      *
125 125
      * @return bool
126 126
      */
127
-    protected function isAuthorised($user, $attribute, $value){
127
+    protected function isAuthorised($user, $attribute, $value) {
128 128
 
129 129
         //Check for pre-defined administration roles
130 130
         if ($this->userIsAuthorised($user))
131 131
             return true;
132 132
 
133 133
         //Check for valid release token , eg that the token exists and is for the same record as this
134
-        if($this->releaseToken != null){
135
-            $confirmation =  ConfirmationRequest::findOne(['release_token' => $this->releaseToken]);
134
+        if ($this->releaseToken != null) {
135
+            $confirmation = ConfirmationRequest::findOne(['release_token' => $this->releaseToken]);
136 136
 
137
-            if($confirmation == null)
137
+            if ($confirmation == null)
138 138
                 return false;
139 139
 
140 140
             $model = $confirmation->constructObject();
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
         //Check to see if any protected attributes have been altered
147 147
         foreach ($this->protectedAttributes as $attribute)
148
-            if($this->hasChanged($attribute))
148
+            if ($this->hasChanged($attribute))
149 149
                 return false;
150 150
 
151 151
         return true;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
      *
158 158
      * @return bool
159 159
      */
160
-    protected function userIsAuthorised($user){
160
+    protected function userIsAuthorised($user) {
161 161
         foreach ($this->allow as $role)
162
-            if($user->can($role))
162
+            if ($user->can($role))
163 163
                 return true;
164 164
 
165 165
         return false;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     /**
169 169
      * Business logic handling the creation of the Confirmation Request, and sending the second factor message.
170 170
      */
171
-    protected function createConfirmationRequest(){
171
+    protected function createConfirmationRequest() {
172 172
 
173 173
         $model          = $this->owner;
174 174
         $changedValues  = $this->getChangedValues();
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      *
194 194
      * @return bool
195 195
      */
196
-    protected function hasChanged($attribute){
196
+    protected function hasChanged($attribute) {
197 197
         return $this->owner->oldAttributes[$attribute] != $this->owner->{$attribute};
198 198
     }
199 199
 
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
      * Fetches all values which have changed, expect for the timestamp attribute.
202 202
      * @return array
203 203
      */
204
-    public function getChangedValues(){
204
+    public function getChangedValues() {
205 205
         $changedAttributes = [];
206 206
 
207 207
         foreach ($this->owner->attributes() as $attribute)
208
-            if($this->hasChanged($attribute))
208
+            if ($this->hasChanged($attribute))
209 209
                 $changedAttributes[$attribute] = $this->owner->$attribute;
210 210
 
211 211
         unset($changedAttributes[$this->timestampAttribute]);
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      * Sets an attribute back to it's original value when it was fetched.
218 218
      * @param string $attribute
219 219
      */
220
-    protected function resetAttribute($attribute){
220
+    protected function resetAttribute($attribute) {
221 221
         $this->owner->$attribute = $this->owner->oldAttributes[$attribute];
222 222
     }
223 223
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      * Adds a flash message to the interface stating the change has been held over pending confirmation.
226 226
      * @param $model
227 227
      */
228
-    public function createFeedbackMessage($model){
228
+    public function createFeedbackMessage($model) {
229 229
         $this->displayMessage($model);
230 230
     }
231 231
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      * Business logic around displaying an appropriate feedback message to the user regbarding the change.
234 234
      * @param $model
235 235
      */
236
-    protected function displayMessage($model){
236
+    protected function displayMessage($model) {
237 237
         Yii::$app->session->setFlash('warning', 'Your update is pending confirmation.  Please check your email for a confirmation link.');
238 238
     }
239 239
 
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
      * Business logic around transmitting the second factor message.
242 242
      * @param ConfirmationRequest $model
243 243
      */
244
-    public function sendSecondFactorMessage($model){
245
-        switch ($this->secondFactor){
244
+    public function sendSecondFactorMessage($model) {
245
+        switch ($this->secondFactor) {
246 246
             case 'email':
247 247
                 Yii::$app->mailer
248 248
                     ->compose($this->confirmationViewPath, ['model' => $model])
@@ -265,25 +265,25 @@  discard block
 block discarded – undo
265 265
      * @return string
266 266
      * @throws InvalidCallException
267 267
      */
268
-    protected function getEmail($model){
268
+    protected function getEmail($model) {
269 269
 
270 270
         $values = unserialize($model->values);
271
-        $email  = ArrayHelper::getValue($values,'email');
271
+        $email  = ArrayHelper::getValue($values, 'email');
272 272
         $object = $model->constructObject();
273 273
 
274
-        if($email == null)
275
-            $email = ArrayHelper::getValue($values,'email_address');
274
+        if ($email == null)
275
+            $email = ArrayHelper::getValue($values, 'email_address');
276 276
 
277
-        if($email == null)
278
-            $email = ArrayHelper::getValue($object,'email');
277
+        if ($email == null)
278
+            $email = ArrayHelper::getValue($object, 'email');
279 279
 
280
-        if($email == null)
281
-            $email = ArrayHelper::getValue($object,'email_address');
280
+        if ($email == null)
281
+            $email = ArrayHelper::getValue($object, 'email_address');
282 282
 
283
-        if($email == null)
284
-            $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email');
283
+        if ($email == null)
284
+            $email = ArrayHelper::getValue($object, $this->createdByAttribute . '.email');
285 285
 
286
-        if($email == null)
286
+        if ($email == null)
287 287
             throw new InvalidCallException("Unable to locate email address via record, changed values, or user account");
288 288
 
289 289
         return $email;
Please login to merge, or discard this patch.
ConfirmationRequestsController.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,30 +40,30 @@
 block discarded – undo
40 40
     public function actionRelease($release_token)
41 41
     {
42 42
 
43
-        try{
44
-            $model =  $this->findModel($release_token);
45
-        } catch (NotFoundHttpException $e){
46
-            Yii::$app->session->setFlash('danger' , "We were not able to find your change.  Perhaps it has already been processed?");
43
+        try {
44
+            $model = $this->findModel($release_token);
45
+        } catch (NotFoundHttpException $e) {
46
+            Yii::$app->session->setFlash('danger', "We were not able to find your change.  Perhaps it has already been processed?");
47 47
             return $this->goHome();
48 48
         }
49 49
 
50
-        try{
50
+        try {
51 51
             $model->release();
52
-        } catch (ErrorException $e){
52
+        } catch (ErrorException $e) {
53 53
             return $this->redirect(['confirmation-requests/expired']);
54 54
         }
55 55
 
56 56
         $viewLink = $model->constructObject()->getViewLink();
57 57
         $model->delete();
58 58
 
59
-        if(!Yii::$app->user->isGuest){
59
+        if (!Yii::$app->user->isGuest) {
60 60
             return $this->redirect($viewLink);
61 61
         }
62 62
 
63 63
         return $this->render('@vendor/enigmatix/yii2-confirmation/views/confirm', []);
64 64
     }
65 65
 
66
-    public function actionExpired(){
66
+    public function actionExpired() {
67 67
         return $this->render('@vendor/enigmatix/yii2-confirmation/views/expired', []);
68 68
 
69 69
     }
Please login to merge, or discard this patch.
ConfirmationRequest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             [['object_id'], 'integer'],
39 39
             [['object', 'values'], 'string'],
40 40
             [['model', 'release_token'], 'string', 'max' => 255],
41
-            [['release_token'], 'default',  'value' => function ($model, $attribute){ return $this->generateReleaseToken();}],
41
+            [['release_token'], 'default', 'value' => function($model, $attribute) { return $this->generateReleaseToken(); }],
42 42
             [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['created_by' => 'id']],
43 43
             [['updated_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['updated_by' => 'id']],
44 44
         ];
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
             ]);
85 85
     }
86 86
 
87
-    public function getViewLink(){
88
-        return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token],true);
87
+    public function getViewLink() {
88
+        return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token], true);
89 89
     }
90 90
 
91 91
     /**
@@ -113,20 +113,20 @@  discard block
 block discarded – undo
113 113
         return $this->hasOne($this->getUserClassName(), ['id' => 'updated_by']);
114 114
     }
115 115
 
116
-    protected function getUserClassName(){
116
+    protected function getUserClassName() {
117 117
         return Yii::$app->user->identityClass;
118 118
     }
119 119
 
120
-    public function release(){
120
+    public function release() {
121 121
 
122 122
         $model          = $this->constructObject();
123 123
         $changedValues  = $model->getChangedValues();
124 124
         $current        = clone $model;
125 125
         $current->refresh();
126 126
 
127
-        foreach ($changedValues as $field => $value){
127
+        foreach ($changedValues as $field => $value) {
128 128
             $oldValue = $model->oldAttributes[$field];
129
-            if($current->$field !== $oldValue && $current->$field !== $value)
129
+            if ($current->$field !== $oldValue && $current->$field !== $value)
130 130
                 throw new ErrorException("Unable to release change, protected field $field has been updated since this request."
131 131
                 . " Expected to find $value or $oldValue, found " . $current->$field);
132 132
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     /**
142 142
      * @return \enigmatix\core\Model
143 143
      */
144
-    public function constructObject(){
144
+    public function constructObject() {
145 145
         return unserialize($this->object);
146 146
     }
147 147
 
Please login to merge, or discard this patch.