|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Security\Confirmation; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
6
|
|
|
use SilverStripe\Control\Controller; |
|
7
|
|
|
use SilverStripe\Control\Director; |
|
8
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
9
|
|
|
use SilverStripe\Control\RequestHandler; |
|
10
|
|
|
use SilverStripe\Forms\Form as BaseForm; |
|
11
|
|
|
use SilverStripe\Forms\FieldList; |
|
12
|
|
|
use SilverStripe\Forms\TextField; |
|
13
|
|
|
use SilverStripe\Forms\FormAction; |
|
14
|
|
|
use SilverStripe\Forms\RequiredFields; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Confirmation form handler implementation |
|
18
|
|
|
* |
|
19
|
|
|
* Handles StorageID identifier in the URL |
|
20
|
|
|
*/ |
|
21
|
|
|
class Handler extends RequestHandler |
|
22
|
|
|
{ |
|
23
|
|
|
private static $url_handlers = [ |
|
|
|
|
|
|
24
|
|
|
'$StorageID!/$Action//$ID/$OtherID' => '$Action', |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
private static $allowed_actions = [ |
|
|
|
|
|
|
28
|
|
|
'index', |
|
29
|
|
|
'Form' |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
public function Link($action = null) |
|
33
|
|
|
{ |
|
34
|
|
|
$request = Injector::inst()->get(HTTPRequest::class); |
|
35
|
|
|
$link = Controller::join_links(Director::baseURL(), $request->getUrl(), $action); |
|
36
|
|
|
|
|
37
|
|
|
$this->extend('updateLink', $link, $action); |
|
38
|
|
|
|
|
39
|
|
|
return $link; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* URL handler for the log-in screen |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function index() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'Title' => _t(__CLASS__.'.FORM_TITLE', 'Confirm potentially dangerous action'), |
|
51
|
|
|
'Form' => $this->Form() |
|
52
|
|
|
]; |
|
53
|
|
|
return $this; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* This method is being used by Form to check whether it needs to use SecurityToken |
|
58
|
|
|
* |
|
59
|
|
|
* We always return false here as the confirmation form should decide this on its own |
|
60
|
|
|
* depending on the Storage data. If we had the original request to |
|
61
|
|
|
* be POST with its own SecurityID, we don't want to interfre with it. If it's been |
|
62
|
|
|
* GET request, then it will generate a new SecurityToken |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function securityTokenEnabled() |
|
67
|
|
|
{ |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns an instance of Confirmation\Form initialized |
|
73
|
|
|
* with the proper storage id taken from URL |
|
74
|
|
|
* |
|
75
|
|
|
* @return Form |
|
76
|
|
|
*/ |
|
77
|
|
|
public function Form() |
|
78
|
|
|
{ |
|
79
|
|
|
$storageId = $this->request->param('StorageID'); |
|
80
|
|
|
|
|
81
|
|
|
if (!strlen(trim($storageId))) { |
|
82
|
|
|
$this->httpError(404, "Undefined StorageID"); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return Form::create($storageId, $this, __FUNCTION__); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|