@@ -223,7 +223,7 @@ |
||
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * Adds a flash message to the interface stating the change has been held over pending confirmation. |
| 226 | - * @param $model |
|
| 226 | + * @param ConfirmationRequest $model |
|
| 227 | 227 | */ |
| 228 | 228 | public function createFeedbackMessage($model){ |
| 229 | 229 | $this->displayMessage($model); |
@@ -90,7 +90,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,29 +265,29 @@ discard block |
||
| 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 | 277 | |
| 278 | - if($email == null){ |
|
| 279 | - $email = ArrayHelper::getValue($object,'email'); |
|
| 278 | + if ($email == null) { |
|
| 279 | + $email = ArrayHelper::getValue($object, 'email'); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if($email == null){ |
|
| 283 | - $email = ArrayHelper::getValue($object,'email_address'); |
|
| 282 | + if ($email == null) { |
|
| 283 | + $email = ArrayHelper::getValue($object, 'email_address'); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if($email == null){ |
|
| 287 | - $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email'); |
|
| 286 | + if ($email == null) { |
|
| 287 | + $email = ArrayHelper::getValue($object, $this->createdByAttribute . '.email'); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if($email == null){ |
|
| 290 | + if ($email == null) { |
|
| 291 | 291 | throw new InvalidCallException('Unable to locate email address via record, changed values, or user account'); |
| 292 | 292 | } |
| 293 | 293 | |
@@ -34,7 +34,6 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Releases a single change as stored in the ConfirmationRequest model. |
| 37 | - * @param integer $id |
|
| 38 | 37 | * @return mixed |
| 39 | 38 | */ |
| 40 | 39 | public function actionRelease($release_token) |
@@ -71,7 +70,6 @@ discard block |
||
| 71 | 70 | /** |
| 72 | 71 | * Finds the ConfirmationRequest model based on its primary key value. |
| 73 | 72 | * If the model is not found, a 404 HTTP exception will be thrown. |
| 74 | - * @param integer $id |
|
| 75 | 73 | * @return ConfirmationRequest the loaded model |
| 76 | 74 | * @throws NotFoundHttpException if the model cannot be found |
| 77 | 75 | */ |
@@ -40,30 +40,30 @@ |
||
| 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 | } |
@@ -3,12 +3,12 @@ |
||
| 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> |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | [['object_id'], 'integer'], |
| 52 | 52 | [['object', 'values'], 'string'], |
| 53 | 53 | [['model', 'release_token'], 'string', 'max' => 255], |
| 54 | - [['release_token'], 'default', 'value' => function ($model, $attribute){ return $this->generateReleaseToken();}], |
|
| 54 | + [['release_token'], 'default', 'value' => function($model, $attribute) { return $this->generateReleaseToken(); }], |
|
| 55 | 55 | [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['created_by' => 'id']], |
| 56 | 56 | [['updated_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['updated_by' => 'id']], |
| 57 | 57 | ]; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | ]); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function getViewLink(){ |
|
| 101 | - return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token],true); |
|
| 100 | + public function getViewLink() { |
|
| 101 | + return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token], true); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -129,20 +129,20 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * @return string ActiveRecord user class, as per application implementation |
| 131 | 131 | */ |
| 132 | - protected function getUserClassName(){ |
|
| 132 | + protected function getUserClassName() { |
|
| 133 | 133 | return Yii::$app->user->identityClass; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function release(){ |
|
| 136 | + public function release() { |
|
| 137 | 137 | |
| 138 | 138 | $model = $this->constructObject(); |
| 139 | 139 | $changedValues = $model->getChangedValues(); |
| 140 | 140 | $current = clone $model; |
| 141 | 141 | $current->refresh(); |
| 142 | 142 | |
| 143 | - foreach ($changedValues as $field => $value){ |
|
| 143 | + foreach ($changedValues as $field => $value) { |
|
| 144 | 144 | $oldValue = $model->oldAttributes[$field]; |
| 145 | - if($current->$field !== $oldValue && $current->$field !== $value){ |
|
| 145 | + if ($current->$field !== $oldValue && $current->$field !== $value) { |
|
| 146 | 146 | throw new ErrorException( |
| 147 | 147 | sprintf('Unable to release change, protected field %s has been updated since this request.' |
| 148 | 148 | . ' Expected to find %s or %s, found %s', $field, $value, $oldValue, $current->$field)); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | /** |
| 160 | 160 | * @return \enigmatix\core\Model |
| 161 | 161 | */ |
| 162 | - public function constructObject(){ |
|
| 162 | + public function constructObject() { |
|
| 163 | 163 | return unserialize($this->object); |
| 164 | 164 | } |
| 165 | 165 | |