1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace enigmatix\confirmation; |
4
|
|
|
|
5
|
|
|
use yii\web\Controller; |
6
|
|
|
use Yii; |
7
|
|
|
use enigmatix\confirmation\ConfirmationRequest; |
8
|
|
|
use yii\base\ErrorException; |
9
|
|
|
use yii\web\NotFoundHttpException; |
10
|
|
|
use yii\filters\VerbFilter; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* ConfirmationRequestsController implements the CRUD actions for ConfirmationRequest model. |
14
|
|
|
*/ |
15
|
|
|
class ConfirmationRequestsController extends Controller |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
var $defaultAction = 'release'; |
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @inheritdoc |
21
|
|
|
*/ |
22
|
|
|
public function behaviors() |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
'verbs' => [ |
26
|
|
|
'class' => VerbFilter::className(), |
27
|
|
|
'actions' => [ |
28
|
|
|
'delete' => ['POST'], |
29
|
|
|
], |
30
|
|
|
], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Releases a single change as stored in the ConfirmationRequest model. |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function actionRelease($release_token) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
try { |
43
|
|
|
$model = $this->findModel($release_token); |
44
|
|
|
} catch (NotFoundHttpException $e) { |
45
|
|
|
Yii::$app->session->setFlash('danger', "We were not able to find your change. Perhaps it has already been processed?"); |
|
|
|
|
46
|
|
|
return $this->goHome(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
try { |
50
|
|
|
$model->release(); |
51
|
|
|
} catch (ErrorException $e) { |
52
|
|
|
return $this->redirect(['confirmation-requests/expired']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$viewLink = $model->constructObject()->getViewLink(); |
56
|
|
|
$model->delete(); |
57
|
|
|
|
58
|
|
|
if (!Yii::$app->user->isGuest) { |
59
|
|
|
return $this->redirect($viewLink); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->render('@vendor/enigmatix/yii2-confirmation/views/confirm', []); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function actionExpired() { |
66
|
|
|
return $this->render('@vendor/enigmatix/yii2-confirmation/views/expired', []); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Finds the ConfirmationRequest model based on its primary key value. |
72
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
73
|
|
|
* @return ConfirmationRequest the loaded model |
74
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
75
|
|
|
*/ |
76
|
|
|
protected function findModel($release_token) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
if (($model = ConfirmationRequest::findOne(['release_token' => $release_token])) !== null) { |
79
|
|
|
return $model; |
80
|
|
|
} else { |
81
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.