These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | class Ext_Users_Member extends DataExtension |
||
4 | { |
||
5 | private static $db = array( |
||
6 | "VerificationCode" => "Varchar(40)" |
||
7 | ); |
||
8 | |||
9 | private static $has_many = array(); |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | public function isVerified() |
||
12 | { |
||
13 | return Permission::checkMember($this->owner, "USERS_VERIFIED"); |
||
14 | } |
||
15 | |||
16 | /** |
||
17 | * Register a new user account using the provided data |
||
18 | * and then return the current member |
||
19 | * |
||
20 | * @param array $data |
||
21 | * @return Member |
||
22 | */ |
||
23 | public function Register($data) |
||
24 | { |
||
25 | // If we have passed a confirm password field, clean the |
||
26 | // data |
||
27 | if (isset($data["Password"]) && is_array($data["Password"]) && isset($data["Password"]["_Password"])) { |
||
28 | $data["Password"] = $data["Password"]["_Password"]; |
||
29 | } |
||
30 | |||
31 | $this->owner->update($data); |
||
32 | |||
33 | // Set verification code for this user |
||
34 | $this->owner->VerificationCode = sha1(mt_rand() . mt_rand()); |
||
35 | $this->owner->write(); |
||
36 | |||
37 | // Add member to any groups that have been specified |
||
38 | if (count(Users::config()->new_user_groups)) { |
||
39 | $groups = Group::get()->filter(array( |
||
40 | "Code" => Users::config()->new_user_groups |
||
41 | )); |
||
42 | |||
43 | foreach ($groups as $group) { |
||
44 | $group->Members()->add($this->owner); |
||
45 | $group->write(); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | // Send a verification email, if needed |
||
50 | if (Users::config()->send_verification_email) { |
||
51 | $this->owner->sendVerificationEmail(); |
||
52 | } |
||
53 | |||
54 | // Login (if enabled) |
||
55 | if (Users::config()->login_after_register) { |
||
56 | $this->owner->LogIn(isset($data['Remember'])); |
||
57 | } |
||
58 | |||
59 | return $this->owner; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Send a verification email to this user account |
||
64 | * |
||
65 | * @return boolean |
||
66 | */ |
||
67 | public function sendVerificationEmail() |
||
68 | { |
||
69 | if ($this->owner->exists()) { |
||
70 | $controller = Injector::inst()->get("Users_Register_Controller"); |
||
71 | $subject = _t("Users.PleaseVerify", "Please verify your account"); |
||
72 | |||
73 | if (Users::config()->send_email_from) { |
||
74 | $from = Users::config()->send_email_from; |
||
75 | } else { |
||
76 | $from = Email::config()->admin_email; |
||
77 | } |
||
78 | |||
79 | $email = Email::create(); |
||
80 | |||
81 | ->setFrom($from) |
||
82 | ->setTo($this->owner->Email) |
||
83 | ->setSubject($subject) |
||
84 | ->setTemplate('UsersAccountVerification') |
||
85 | ->populateTemplate(ArrayData::create(array( |
||
86 | "Link" => Controller::join_links( |
||
87 | $controller->AbsoluteLink("verify"), |
||
88 | $this->owner->ID, |
||
89 | $this->owner->VerificationCode |
||
90 | ) |
||
91 | ))); |
||
92 | |||
93 | $email->send(); |
||
94 | |||
95 | return true; |
||
96 | } |
||
97 | |||
98 | return false; |
||
99 | } |
||
100 | } |
||
101 |
This check marks private properties in classes that are never used. Those properties can be removed.