|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class ShopAccountForm_Validator extends RequiredFields |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Ensures member unique id stays unique and other basic stuff... |
|
9
|
|
|
* |
|
10
|
|
|
* @param array $data = array Form Field Data |
|
11
|
|
|
* @param bool $allowExistingEmail - see comment below |
|
12
|
|
|
* |
|
13
|
|
|
* @return bool |
|
14
|
|
|
**/ |
|
15
|
|
|
public function php($data, $allowExistingEmail = false) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->form->saveDataToSession(); |
|
18
|
|
|
$valid = parent::php($data); |
|
19
|
|
|
$uniqueFieldName = Member::get_unique_identifier_field(); |
|
|
|
|
|
|
20
|
|
|
$loggedInMember = Member::currentUser(); |
|
21
|
|
|
$loggedInMemberID = 0; |
|
22
|
|
|
if (isset($data[$uniqueFieldName]) && $data[$uniqueFieldName]) { |
|
23
|
|
|
$isShopAdmin = false; |
|
24
|
|
|
if ($loggedInMember) { |
|
25
|
|
|
$loggedInMemberID = $loggedInMember->ID; |
|
26
|
|
|
if ($loggedInMember->IsShopAdmin()) { |
|
27
|
|
|
$isShopAdmin = true; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
if ($isShopAdmin || $allowExistingEmail) { |
|
|
|
|
|
|
31
|
|
|
//do nothing |
|
32
|
|
|
} else { |
|
33
|
|
|
$uniqueFieldValue = Convert::raw2sql($data[$uniqueFieldName]); |
|
34
|
|
|
//can't be taken |
|
35
|
|
|
$otherMembersWithSameEmail = Member::get() |
|
36
|
|
|
->filter(array($uniqueFieldName => $uniqueFieldValue)) |
|
37
|
|
|
->exclude(array('ID' => $loggedInMemberID)); |
|
38
|
|
|
if ($otherMembersWithSameEmail->count()) { |
|
39
|
|
|
//we allow existing email |
|
40
|
|
|
// if we are currently NOT logged in |
|
41
|
|
|
// in case we place an order! |
|
42
|
|
|
if ($allowExistingEmail) { |
|
|
|
|
|
|
43
|
|
|
//do nothing |
|
44
|
|
|
} else { |
|
45
|
|
|
$message = _t( |
|
46
|
|
|
'Account.ALREADYTAKEN', |
|
47
|
|
|
'{uniqueFieldValue} is already taken by another member. Please log in or use another {uniqueFieldName}.', |
|
48
|
|
|
array('uniqueFieldValue' => $uniqueFieldValue, 'uniqueFieldName' => $uniqueFieldName) |
|
|
|
|
|
|
49
|
|
|
); |
|
50
|
|
|
$this->validationError( |
|
51
|
|
|
$uniqueFieldName, |
|
52
|
|
|
$message, |
|
53
|
|
|
'required' |
|
54
|
|
|
); |
|
55
|
|
|
$valid = false; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
// check password fields are the same before saving |
|
61
|
|
|
if (isset($data['PasswordCheck1']) && isset($data['PasswordCheck2'])) { |
|
62
|
|
|
if ($data['PasswordCheck1'] != $data['PasswordCheck2']) { |
|
63
|
|
|
$this->validationError( |
|
64
|
|
|
'PasswordCheck1', |
|
65
|
|
|
_t('Account.PASSWORDSERROR', 'Passwords do not match.'), |
|
66
|
|
|
'required' |
|
67
|
|
|
); |
|
68
|
|
|
$valid = false; |
|
69
|
|
|
} |
|
70
|
|
|
//if you are not logged in, you have not provided a password and the settings require you to be logged in then |
|
71
|
|
|
//we have a problem |
|
72
|
|
|
if (!$loggedInMember && !$data['PasswordCheck1'] && EcommerceConfig::get('EcommerceRole', 'must_have_account_to_purchase')) { |
|
73
|
|
|
$this->validationError( |
|
74
|
|
|
'PasswordCheck1', |
|
75
|
|
|
_t('Account.SELECTPASSWORD', 'Please select a password.'), |
|
76
|
|
|
'required' |
|
77
|
|
|
); |
|
78
|
|
|
$valid = false; |
|
79
|
|
|
} |
|
80
|
|
|
$letterCount = strlen($data['PasswordCheck1']); |
|
81
|
|
|
$minLength = Config::inst()->get('ShopAccountForm_Validator', 'minimum_password_length'); |
|
82
|
|
|
if ($letterCount > 0 && $letterCount < $minLength) { |
|
83
|
|
|
$this->validationError( |
|
84
|
|
|
'PasswordCheck1', |
|
85
|
|
|
_t('Account.PASSWORDMINIMUMLENGTH', 'Password does not meet minimum standards.'), |
|
86
|
|
|
'required' |
|
87
|
|
|
); |
|
88
|
|
|
$valid = false; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
if (isset($data['FirstName'])) { |
|
92
|
|
|
if (strlen($data['FirstName']) < 2) { |
|
93
|
|
|
$this->validationError( |
|
94
|
|
|
'FirstName', |
|
95
|
|
|
_t('Account.NOFIRSTNAME', 'Please enter your first name.'), |
|
96
|
|
|
'required' |
|
97
|
|
|
); |
|
98
|
|
|
$valid = false; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
if (isset($data['Surname'])) { |
|
102
|
|
|
if (strlen($data['Surname']) < 2) { |
|
103
|
|
|
$this->validationError( |
|
104
|
|
|
'Surname', |
|
105
|
|
|
_t('Account.NOSURNAME', 'Please enter your surname.'), |
|
106
|
|
|
'required' |
|
107
|
|
|
); |
|
108
|
|
|
$valid = false; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
if (!$valid) { |
|
112
|
|
|
$this->form->sessionMessage(_t('Account.ERRORINFORM', 'We could not save your details, please check your errors below.'), 'bad'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return $valid; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.