1
|
|
|
<?php |
2
|
|
|
namespace UserManagement\Forms; |
3
|
|
|
|
4
|
|
|
use SilverStripe\Forms\FieldList; |
5
|
|
|
use SilverStripe\Forms\Form; |
6
|
|
|
use SilverStripe\Forms\EmailField; |
7
|
|
|
use SilverStripe\Forms\DateField; |
8
|
|
|
use SilverStripe\Forms\FormAction; |
9
|
|
|
use SilverStripe\Forms\TextField; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
12
|
|
|
use SilverStripe\Control\Controller; |
13
|
|
|
use SilverStripe\Forms\OptionsetField; |
14
|
|
|
use SilverStripe\Forms\ConfirmedPasswordField; |
15
|
|
|
use SilverStripe\Security\Security; |
16
|
|
|
use SilverStripe\Security\RequestAuthenticationHandler; |
17
|
|
|
use SilverStripe\Core\Injector\Injector; |
18
|
|
|
use SilverStripe\Security\IdentityStore; |
19
|
|
|
use Psr\Log\LoggerInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class SignUpForm |
23
|
|
|
* |
24
|
|
|
* @package user-management |
25
|
|
|
*/ |
26
|
|
|
class SignUpForm extends Form |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
protected $siteConfig; |
30
|
|
|
/** |
31
|
|
|
* Constructor |
32
|
|
|
*/ |
33
|
|
|
public function __construct($controller, $name) |
34
|
|
|
{ |
35
|
|
|
$this->setsiteConfig(); |
36
|
|
|
$this->setAttribute('id', 'SignUpForm'); |
37
|
|
|
parent::__construct($controller, $name, $this->getFormFields($controller), $this->getFormActions()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Form action, Register user and redirect to the call back url with auto login. |
42
|
|
|
*/ |
43
|
|
|
public function doSubmit($data, Form $form) |
44
|
|
|
{ |
45
|
|
|
|
46
|
|
|
try { |
47
|
|
|
$signUpPersonal = Member::create(); |
48
|
|
|
$form->saveInto($signUpPersonal); |
49
|
|
|
if (isset($data['DOB']) && $data['DOB']) { |
50
|
|
|
$signUpPersonal->DOB = date('Y-m-d', strtotime($data['DOB'])); |
51
|
|
|
} |
52
|
|
|
$signUpPersonal->write(); |
53
|
|
|
$Member = Member::get()->byId($signUpPersonal->ID); |
54
|
|
|
$assignGroup = $signUpPersonal->Groups(); |
55
|
|
|
$assignGroup->add($this->siteConfig->CustomerGroup()); |
56
|
|
|
Injector::inst()->get(IdentityStore::class)->logIn($Member); |
57
|
|
|
//TO DO |
58
|
|
|
//$this->sessionMessage('Profile Created!', 'good'); |
59
|
|
|
return $this->controller->redirect($this->siteConfig->LoginCallBackUrl()->URLSegment); #TODO |
60
|
|
|
} catch (Exception $e) { |
|
|
|
|
61
|
|
|
$this->logger->log('Error occured in signup'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Controller $controller the controller instance that is being passed to the form |
68
|
|
|
* @return FieldList Fields for this form. |
69
|
|
|
*/ |
70
|
|
|
protected function getFormFields($controller = null) |
71
|
|
|
{ |
72
|
|
|
$fields = FieldList::create( |
73
|
|
|
TextField::create("FirstName", "FirstName"), |
74
|
|
|
TextField::create("Surname", "Surname"), |
75
|
|
|
TextField::create("NickName", "NickName"), |
76
|
|
|
DateField::create("DOB", "DOB"), |
77
|
|
|
ConfirmedPasswordField::create("Password", "Password"), |
78
|
|
|
EmailField::create("Email", "Email"), |
79
|
|
|
TextField::create("Mobile", "Mobile"), |
80
|
|
|
TextField::create("SecurityQuestion", "SecurityQuestion"), |
81
|
|
|
TextField::create("SecurityAnswer", "SecurityAnswer") |
82
|
|
|
); |
83
|
|
|
// Update the fields using updateSignUpForm |
84
|
|
|
$this->extend('updateSignUpForm', $fields); |
85
|
|
|
return $fields; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return FieldList Actions for this form. |
91
|
|
|
*/ |
92
|
|
|
protected function getFormActions() |
93
|
|
|
{ |
94
|
|
|
return FieldList::create( |
95
|
|
|
FormAction::create("doSubmit", "Submit") |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
protected function setsiteConfig() |
101
|
|
|
{ |
102
|
|
|
$this->siteConfig = SiteConfig::current_site_config(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|