Ext_Users_Member   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 10
dl 0
loc 108
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isVerified() 0 4 1
B Register() 0 40 8
A sendVerificationEmail() 0 37 3
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
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|null?

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The property VerificationCode does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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)
0 ignored issues
show
Bug introduced by
The property Email does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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,
0 ignored issues
show
Bug introduced by
The property ID does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
103
                            $this->owner->VerificationCode
0 ignored issues
show
Bug introduced by
The property VerificationCode does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
104
                        )
105
                        )
106
                    )
107
                );
108
109
            $email->send();
110
111
            return true;
112
        }
113
114
        return false;
115
    }
116
}
117