1 | <?php |
||
26 | class ConfirmationBehavior extends Behavior |
||
27 | { |
||
28 | /** |
||
29 | * @var bool whether to skip typecasting of `null` values. |
||
30 | * If enabled attribute value which equals to `null` will not be type-casted (e.g. `null` remains `null`), |
||
31 | * otherwise it will be converted according to the type configured at [[attributeTypes]]. |
||
32 | */ |
||
33 | public $skipOnNull = true; |
||
34 | |||
35 | /** |
||
36 | * @var array a list of the attributes to be protected, provided when constructing the behavior and attaching, |
||
37 | * or in the model's behaviors method. |
||
38 | */ |
||
39 | public $protectedAttributes = []; |
||
40 | |||
41 | /** |
||
42 | * @var string If a release token has been supplied, provided the corresponding release object is valid, the change |
||
43 | * will be executed. |
||
44 | */ |
||
45 | public $releaseToken; |
||
46 | |||
47 | /** |
||
48 | * @var array A list of roles that can bypass the protection and make the change without triggering a confirmation |
||
49 | * request. |
||
50 | */ |
||
51 | public $allow = []; |
||
52 | |||
53 | /** |
||
54 | * @var string namespace of the object that stores and executes the ConfirmationRequest |
||
55 | */ |
||
56 | public $confirmationRequestClass = 'enigmatix\\confirmation\\ConfirmationRequest'; |
||
57 | |||
58 | /** |
||
59 | * @var string delivery method for the Confirmation Request. Currently only email is supported. |
||
60 | */ |
||
61 | public $secondFactor = 'email'; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * @var string the name of the variable to use to traverse to the user table from the secured model. |
||
66 | */ |
||
67 | public $createdByAttribute = 'createdBy'; |
||
68 | |||
69 | /** |
||
70 | * @var string |
||
71 | */ |
||
72 | public $confirmationViewPath = '@vendor/enigmatix/yii2-confirmation/mail/_confirmationEmail'; |
||
73 | |||
74 | /** |
||
75 | * @var string The name of the table attribute that tracks when a record is updated. This value is ignored when |
||
76 | * determining of a record has changed values in it. |
||
77 | */ |
||
78 | public $timestampAttribute = 'updated_at'; |
||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | public function events() |
||
88 | |||
89 | /** |
||
90 | * @param $event Event; |
||
91 | */ |
||
92 | |||
93 | public function beforeSave($event) { |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Business logic around triggering the confirmation request. |
||
100 | */ |
||
101 | protected function protectAttributes() |
||
119 | |||
120 | /** |
||
121 | * Checks whether a user is allowed to make the change without triggering a confirmation request. |
||
122 | * @param \yii\web\User $user |
||
123 | * @param string $attribute |
||
124 | * @param string $value |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | protected function isAuthorised($user, $attribute, $value) { |
||
154 | |||
155 | /** |
||
156 | * Iterates over roles to determine if the user is authorised to complete the action. |
||
157 | * @param \yii\web\User $user |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | protected function userIsAuthorised($user) { |
||
168 | |||
169 | /** |
||
170 | * Business logic handling the creation of the Confirmation Request, and sending the second factor message. |
||
171 | */ |
||
172 | protected function createConfirmationRequest() { |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Determines whether an attribute has been changed in the object. |
||
193 | * @param string $attribute |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | protected function hasChanged($attribute) { |
||
200 | |||
201 | /** |
||
202 | * Fetches all values which have changed, expect for the timestamp attribute. |
||
203 | * @return array |
||
204 | */ |
||
205 | public function getChangedValues() { |
||
216 | |||
217 | /** |
||
218 | * Sets an attribute back to it's original value when it was fetched. |
||
219 | * @param string $attribute |
||
220 | */ |
||
221 | protected function resetAttribute($attribute) { |
||
224 | |||
225 | /** |
||
226 | * Adds a flash message to the interface stating the change has been held over pending confirmation. |
||
227 | * @param ConfirmationRequest $model |
||
228 | */ |
||
229 | public function createFeedbackMessage($model) { |
||
232 | |||
233 | /** |
||
234 | * Business logic around displaying an appropriate feedback message to the user regbarding the change. |
||
235 | * @param $model |
||
236 | */ |
||
237 | protected function displayMessage($model) { |
||
240 | |||
241 | /** |
||
242 | * Business logic around transmitting the second factor message. |
||
243 | * @param ConfirmationRequest $model |
||
244 | */ |
||
245 | public function sendSecondFactorMessage($model) { |
||
258 | |||
259 | /** |
||
260 | * Attempts to retrieve an address from several places within the request. Firstly, attempts to find an email in the |
||
261 | * changed values, and then looks within the current object for an email, and lastly attempts to traverse to the User |
||
262 | * who created the object if an identifier has been recorded. |
||
263 | * |
||
264 | * @param ConfirmationRequest $model |
||
265 | * |
||
266 | * @return string |
||
267 | * @throws InvalidCallException |
||
268 | */ |
||
269 | protected function getEmail($model) { |
||
297 | |||
298 | } |
||
299 |