-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPUPI_SRS_RegistrationFilter.php
58 lines (45 loc) · 1.7 KB
/
PUPI_SRS_RegistrationFilter.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
<?php
class PUPI_SRS_RegistrationFilter
{
/** @var string */
private $directory;
public function load_module($directory, $urlToRoot)
{
$this->directory = $directory;
}
public function filter_email(&$email, $olduser)
{
if (isset($olduser)) {
return null;
}
if (!empty($errors)) {
return null;
}
$message = $this->getMessageFromEmailValidators($email);
if (isset($message)) {
return $message;
}
return $this->getMessageFromOnlineUserValidators($email, qa_remote_ip_address());
}
private function getMessageFromEmailValidators(string $email)
{
require_once $this->directory . 'Services/PUPI_SRS_EmailValidatorManager.php';
$verificationResult = (new PUPI_SRS_EmailValidatorManager($this->directory))->getVerificationResult($email);
switch ($verificationResult['status']) {
case 'q2a-duplicate':
return qa_lang('users/email_exists');
case 'service-duplicate':
return qa_lang_sub('pupi_srs/email_already_registered', $verificationResult['registeredEmail']);
case 'invalid':
return qa_lang('users/email_invalid');
default: // 'valid'
return null;
}
}
private function getMessageFromOnlineUserValidators(string $email, string $ipAddress)
{
require_once $this->directory . 'Services/PUPI_SRS_OnlineUserValidatorManager.php';
$isSpamUser = (new PUPI_SRS_OnlineUserValidatorManager($this->directory))->isSpammer($email, $ipAddress);
return $isSpamUser ? qa_lang_html('users/email_invalid') : null;
}
}