6
6
use Firesphere \PartialUserforms \Models \PartialFormSubmission ;
7
7
use SilverStripe \CMS \Controllers \ContentController ;
8
8
use SilverStripe \Control \HTTPRequest ;
9
- use SilverStripe \Control \Middleware \HTTPCacheControlMiddleware ;
10
9
use SilverStripe \ORM \DataObject ;
11
10
use SilverStripe \ORM \ValidationException ;
12
11
use SilverStripe \UserForms \Control \UserDefinedFormController ;
13
12
use SilverStripe \UserForms \Model \EditableFormField ;
14
13
use SilverStripe \View \Requirements ;
15
14
16
15
/**
17
- * Class \Firesphere\PartialUserforms\Controllers\ PartialUserFormController
18
- *
16
+ * Class PartialUserFormController
17
+ * @package Firesphere\PartialUserforms\Controllers
19
18
*/
20
19
class PartialUserFormController extends ContentController
21
20
{
@@ -28,7 +27,7 @@ class PartialUserFormController extends ContentController
28
27
* @var array
29
28
*/
30
29
private static $ url_handlers = [
31
- '' => 'savePartialSubmission ' ,
30
+ 'save ' => 'savePartialSubmission ' ,
32
31
'$Key/$Token ' => 'partial ' ,
33
32
];
34
33
@@ -42,11 +41,16 @@ class PartialUserFormController extends ContentController
42
41
43
42
/**
44
43
* @param HTTPRequest $request
45
- * @return int
44
+ * @return int|mixed|void
46
45
* @throws ValidationException
46
+ * @throws \SilverStripe\Control\HTTPResponse_Exception
47
47
*/
48
48
public function savePartialSubmission (HTTPRequest $ request )
49
49
{
50
+ if (!$ request ->isPOST ()) {
51
+ return $ this ->httpError (404 );
52
+ }
53
+
50
54
$ postVars = $ request ->postVars ();
51
55
$ editableField = null ;
52
56
@@ -128,18 +132,19 @@ protected function createOrUpdateSubmission($formData)
128
132
*/
129
133
public function partial (HTTPRequest $ request )
130
134
{
131
- // Ensure this URL doesn't get picked up by HTTP caches
132
- HTTPCacheControlMiddleware::singleton ()->disableCache ();
133
-
134
135
$ key = $ request ->param ('Key ' );
135
136
$ token = $ request ->param ('Token ' );
136
137
137
138
$ partial = PartialFormSubmission::get ()->find ('Token ' , $ token );
138
- if (!$ partial || !$ partial ->UserDefinedFormID ) {
139
+ if (!$ token || ! $ partial || !$ partial ->UserDefinedFormID ) {
139
140
return $ this ->httpError (404 );
140
141
}
141
142
142
143
if ($ partial ->generateKey ($ token ) === $ key ) {
144
+ // Set the session if the last session has expired
145
+ if (!$ request ->getSession ()->get (self ::SESSION_KEY )) {
146
+ $ request ->getSession ()->set (self ::SESSION_KEY , $ partial ->ID );
147
+ }
143
148
144
149
// TODO: Recognize visitor with the password
145
150
// TODO: Populate form values
@@ -156,7 +161,7 @@ public function partial(HTTPRequest $request)
156
161
'Content ' => $ this ->obj ('Content ' ),
157
162
'Form ' => $ controller ->Form (),
158
163
'Link ' => $ partial ->getPartialLink ()
159
- ])->renderWith (['PartialUserform ' , 'Page ' ]);
164
+ ])->renderWith (['PartialUserForm ' , 'Page ' ]);
160
165
} else {
161
166
return $ this ->httpError (404 );
162
167
}
0 commit comments