-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegistrationPresenter.php
242 lines (205 loc) · 6.72 KB
/
RegistrationPresenter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
Copyright 2011-2017 Nick Korbel
This file is part of Booked Scheduler.
Booked Scheduler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Booked Scheduler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(ROOT_DIR . 'lib/Config/namespace.php');
require_once(ROOT_DIR . 'lib/Common/namespace.php');
require_once(ROOT_DIR . 'lib/Application/Attributes/namespace.php');
require_once(ROOT_DIR . 'Presenters/ActionPresenter.php');
class RegisterActions
{
const Register = 'register';
}
class RegistrationPresenter extends ActionPresenter
{
/**
* @var IRegistrationPage
*/
private $page;
/**
* @var IRegistration
*/
private $registration;
/**
* @var IAuthentication
*/
private $auth;
/**
* @var ICaptchaService
*/
private $captchaService;
/**
* @var IAttributeService
*/
private $attributeService;
/**
* @param IRegistrationPage $page
* @param IRegistration|null $registration
* @param IAuthentication|null $authentication
* @param ICaptchaService|null $captchaService
* @param IAttributeService|null $attributeService
*/
public function __construct(IRegistrationPage $page, $registration = null, $authentication = null, $captchaService = null, $attributeService = null)
{
parent::__construct($page);
$this->page = $page;
$this->SetRegistration($registration);
$this->SetAuthentication($authentication);
$this->SetCaptchaService($captchaService);
$this->SetAttributeService($attributeService);
$this->AddAction(RegisterActions::Register, 'Register');
}
private function SetRegistration($registration)
{
if (is_null($registration))
{
$this->registration = new Registration();
}
else
{
$this->registration = $registration;
}
}
private function SetAuthentication($authorization)
{
if (is_null($authorization))
{
$this->auth = PluginManager::Instance()->LoadAuthentication();
}
else
{
$this->auth = $authorization;
}
}
private function SetCaptchaService($captchaService)
{
if (is_null($captchaService))
{
$this->captchaService = CaptchaService::Create();
}
else
{
$this->captchaService = $captchaService;
}
}
private function SetAttributeService($attributeService)
{
if (is_null($attributeService))
{
$this->attributeService = new AttributeService(new AttributeRepository());
}
else
{
$this->attributeService = $attributeService;
}
}
public function PageLoad()
{
$this->BounceIfNotAllowingRegistration();
$attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::USER);
$this->page->SetAttributes($attributes->GetAttributes());
$this->page->SetCaptchaImageUrl($this->captchaService->GetImageUrl());
$this->PopulateTimezones();
$this->PopulateHomepages();
}
public function Register()
{
$additionalFields = array('phone' => $this->page->GetPhone(),
'organization' => $this->page->GetOrganization(),
'position' => $this->page->GetPosition());
$language = Resources::GetInstance()->CurrentLanguage;
$user = $this->registration->Register(
$this->page->GetLoginName(),
$this->page->GetEmail(),
$this->page->GetFirstName(),
$this->page->GetLastName(),
$this->page->GetPassword(),
$this->page->GetTimezone(),
$language,
intval($this->page->GetHomepage()),
$additionalFields,
$this->GetAttributeValues());
$context = new WebLoginContext(new LoginData(false, $language));
$plugin = PluginManager::Instance()->LoadPostRegistration();
$plugin->HandleSelfRegistration($user, $this->page, $context);
}
/**
* @return array|AttributeValue[]
*/
private function GetAttributeValues()
{
$attributes = array();
foreach ($this->page->GetAttributes() as $attribute)
{
$attributes[] = new AttributeValue($attribute->Id, $attribute->Value);
}
return $attributes;
}
private function BounceIfNotAllowingRegistration()
{
if (!Configuration::Instance()->GetKey(ConfigKeys::ALLOW_REGISTRATION, new BooleanConverter()))
{
$this->page->RedirectPage(Pages::LOGIN);
}
}
private function PopulateTimezones()
{
$timezoneValues = array();
$timezoneOutput = array();
foreach ($GLOBALS['APP_TIMEZONES'] as $timezone)
{
$timezoneValues[] = $timezone;
$timezoneOutput[] = $timezone;
}
$this->page->SetTimezones($timezoneValues, $timezoneOutput);
$timezone = Configuration::Instance()->GetDefaultTimezone();
if ($this->page->IsPostBack())
{
$timezone = $this->page->GetTimezone();
}
$this->page->SetTimezone($timezone);
}
private function PopulateHomepages()
{
$homepageValues = array();
$homepageOutput = array();
$pages = Pages::GetAvailablePages();
foreach ($pages as $pageid => $page)
{
$homepageValues[] = $pageid;
$homepageOutput[] = Resources::GetInstance()->GetString($page['name']);
}
$this->page->SetHomepages($homepageValues, $homepageOutput);
$homepageId = 1;
if ($this->page->IsPostBack())
{
$homepageId = $this->page->GetHomepage();
}
$this->page->SetHomepage($homepageId);
}
protected function LoadValidators($action)
{
$this->page->RegisterValidator('fname', new RequiredValidator($this->page->GetFirstName()));
$this->page->RegisterValidator('lname', new RequiredValidator($this->page->GetLastName()));
$this->page->RegisterValidator('username', new RequiredValidator($this->page->GetLoginName()));
$this->page->RegisterValidator('passwordmatch', new EqualValidator($this->page->GetPassword(), $this->page->GetPasswordConfirm()));
$this->page->RegisterValidator('passwordcomplexity', new PasswordComplexityValidator($this->page->GetPassword()));
$this->page->RegisterValidator('emailformat', new EmailValidator($this->page->GetEmail()));
$this->page->RegisterValidator('uniqueemail', new UniqueEmailValidator(new UserRepository(), $this->page->GetEmail()));
$this->page->RegisterValidator('uniqueusername', new UniqueUserNameValidator(new UserRepository(), $this->page->GetLoginName()));
$this->page->RegisterValidator('captcha', new CaptchaValidator($this->page->GetCaptcha(), $this->captchaService));
$this->page->RegisterValidator('additionalattributes', new AttributeValidator($this->attributeService, CustomAttributeCategory::USER, $this->GetAttributeValues()));
$this->page->RegisterValidator('requiredEmailDomain', new RequiredEmailDomainValidator($this->page->GetEmail()));
}
}