1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Overwrite Member object |
5
|
|
|
* |
6
|
|
|
* @package Users |
7
|
|
|
* @author i-lateral <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class Ext_Users_Member extends DataExtension |
10
|
|
|
{ |
11
|
|
|
private static $db = array( |
12
|
|
|
"VerificationCode" => "Varchar(40)" |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Is the current member verified? |
17
|
|
|
* |
18
|
|
|
* @return boolean |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
public function isVerified() |
21
|
|
|
{ |
22
|
|
|
return Permission::checkMember($this->owner, "USERS_VERIFIED"); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register a new user account using the provided data |
27
|
|
|
* and then return the current member |
28
|
|
|
* |
29
|
|
|
* @param array $data Array of data to create member from |
30
|
|
|
* |
31
|
|
|
* @return Member |
32
|
|
|
*/ |
33
|
|
|
public function Register($data) |
34
|
|
|
{ |
35
|
|
|
// If we have passed a confirm password field, clean the |
36
|
|
|
// data |
37
|
|
|
if (isset($data["Password"]) && is_array($data["Password"]) && isset($data["Password"]["_Password"])) { |
38
|
|
|
$data["Password"] = $data["Password"]["_Password"]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->owner->update($data); |
42
|
|
|
|
43
|
|
|
// Set verification code for this user |
44
|
|
|
$this->owner->VerificationCode = sha1(mt_rand() . mt_rand()); |
|
|
|
|
45
|
|
|
$this->owner->write(); |
46
|
|
|
|
47
|
|
|
// Add member to any groups that have been specified |
48
|
|
|
if (count(Users::config()->new_user_groups)) { |
49
|
|
|
$groups = Group::get()->filter( |
50
|
|
|
array( |
51
|
|
|
"Code" => Users::config()->new_user_groups |
52
|
|
|
) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
foreach ($groups as $group) { |
56
|
|
|
$group->Members()->add($this->owner); |
57
|
|
|
$group->write(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Send a verification email, if needed |
62
|
|
|
if (Users::config()->send_verification_email) { |
63
|
|
|
$this->owner->sendVerificationEmail(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Login (if enabled) |
67
|
|
|
if (Users::config()->login_after_register) { |
68
|
|
|
$this->owner->LogIn(isset($data['Remember'])); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->owner; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Send a verification email to this user account |
76
|
|
|
* |
77
|
|
|
* @return boolean |
78
|
|
|
*/ |
79
|
|
|
public function sendVerificationEmail() |
80
|
|
|
{ |
81
|
|
|
if ($this->owner->exists()) { |
82
|
|
|
$controller = Injector::inst()->get("Users_Register_Controller"); |
83
|
|
|
$subject = _t("Users.PleaseVerify", "Please verify your account"); |
84
|
|
|
|
85
|
|
|
if (Users::config()->send_email_from) { |
86
|
|
|
$from = Users::config()->send_email_from; |
87
|
|
|
} else { |
88
|
|
|
$from = Email::config()->admin_email; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$email = Email::create(); |
92
|
|
|
$email |
93
|
|
|
->setFrom($from) |
94
|
|
|
->setTo($this->owner->Email) |
|
|
|
|
95
|
|
|
->setSubject($subject) |
96
|
|
|
->setTemplate('UsersAccountVerification') |
97
|
|
|
->populateTemplate( |
98
|
|
|
ArrayData::create( |
99
|
|
|
array( |
100
|
|
|
"Link" => Controller::join_links( |
101
|
|
|
$controller->AbsoluteLink("verify"), |
102
|
|
|
$this->owner->ID, |
|
|
|
|
103
|
|
|
$this->owner->VerificationCode |
|
|
|
|
104
|
|
|
) |
105
|
|
|
) |
106
|
|
|
) |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$email->send(); |
110
|
|
|
|
111
|
|
|
return true; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return false; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.