DX_Auth_Event   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 116
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A user_activated() 0 7 1
A user_logged_in() 0 3 1
A user_logging_out() 0 3 1
A user_changed_password() 0 3 1
A user_canceling_account() 0 7 1
A checked_uri_permissions() 0 3 1
A got_permission_value() 0 3 1
A got_permissions_value() 0 3 1
A sending_account_email() 0 7 1
A sending_activation_email() 0 4 1
A sending_forgot_password_email() 0 16 2
1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
// Event for DX_Auth
8
// You can use DX_Auth_Event to extend DX_Auth to fullfil your needs
9
// For example: you can use event below to PM user when he already activated the account, etc.
10
11
class DX_Auth_Event
12
{
13
14
    var $ci;
15
16
    public function __construct() {
17
        $this->ci = & get_instance();
18
    }
19
20
    // If DX_email_activation in config is TRUE,
21
    // this event occurs after user succesfully activated using specified key in their email.
22
    // If DX_email_activation in config is FALSE,
23
    // this event occurs right after user succesfully registered.
24
25
    public function user_activated($user_id) {
26
        // Load models
27
        $this->ci->load->model('dx_auth/user_profile', 'user_profile');
28
29
        // Create user profile
30
        $this->ci->user_profile->create_profile($user_id);
31
    }
32
33
    // This event occurs right after user login
34
35
    public function user_logged_in($user_id) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
37
    }
38
39
    // This event occurs right before user logout
40
41
    public function user_logging_out($user_id) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
43
    }
44
45
    // This event occurs right after user change password
46
47
    public function user_changed_password($user_id, $new_password) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $new_password is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
49
    }
50
51
    // This event occurs right before user account is canceled
52
53
    public function user_canceling_account($user_id) {
54
        // Load models
55
        $this->ci->load->model('dx_auth/user_profile', 'user_profile');
56
57
        // Delete user profile
58
        $this->ci->user_profile->delete_profile($user_id);
59
    }
60
61
    // This event occurs when check_uri_permissions() function in DX_Auth is called
62
    // after checking if user role is allowed or not to access URI, this event will be triggered
63
    // $allowed is result of the check before, it's possible to alter the value since it's passed by reference
64
65
    public function checked_uri_permissions($user_id, &$allowed) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $allowed is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
67
    }
68
69
    // This event occurs when get_permission_value() function in DX_Auth is called
70
71
    public function got_permission_value($user_id, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
73
    }
74
75
    // This event occurs when get_permissions_value() function in DX_Auth is called
76
77
    public function got_permissions_value($user_id, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $user_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
79
    }
80
81
    // This event occurs right before dx auth send email with account details
82
    // $data is an array, containing username, password, email and last ip
83
    // $content is email content, passed by reference
84
    // You can customize email content here
85
86
    public function sending_account_email($data, &$content) {
87
        // Load helper
88
        $this->ci->load->helper('url');
89
90
        // Create content
91
        $content = sprintf($this->ci->lang->line('auth_account_content'), $this->ci->config->item('DX_website_name'), $data['username'], $data['email'], $data['password'], site_url($this->ci->config->item('DX_login_uri')), $this->ci->config->item('DX_website_name'));
92
    }
93
94
    // This event occurs right before dx auth send activation email
95
    // $data is an array, containing username, password, email, last ip, activation_key, activate_url
96
    // $content is email content, passed by reference
97
    // You can customize email content here
98
99
    public function sending_activation_email($data, &$content) {
100
        // Create content
101
        $content = sprintf($this->ci->lang->line('auth_activate_content'), $this->ci->config->item('DX_website_name'), $data['activate_url'], $this->ci->config->item('DX_email_activation_expire') / 60 / 60, $data['username'], $data['email'], $data['password'], $this->ci->config->item('DX_website_name'));
102
    }
103
104
    // This event occurs right before dx auth send forgot password request email
105
    // $data is an array, containing password, key, and reset_password_uri
106
    // $content is email content, passed by reference
107
    // You can customize email content here
108
109
    public function sending_forgot_password_email($data, &$content) {
110
        if (class_exists(ShopCore)) {
111
            $replaceData = [
112
                            '%webSiteName%'      => $this->ci->config->item('DX_website_name'),
113
                            '%resetPasswordUri%' => $data['reset_password_uri'],
114
                            '%password%'         => $data['password'],
115
                            '%key%'              => $data['key'],
116
                            '%webMasterEmail%'   => $this->ci->config->item('DX_webmaster_email'),
117
                           ];
118
119
            $content = str_replace(array_keys($replaceData), $replaceData, ShopCore::app()->SSettings->getForgotPasswordMessageText());
120
        } else {
121
            // Create content
122
            $content = sprintf($this->ci->lang->line('auth_forgot_password_content'), $this->ci->config->item('DX_website_name'), $data['reset_password_uri'], $data['password'], $data['key'], $this->ci->config->item('DX_webmaster_email'), $this->ci->config->item('DX_website_name'));
123
        }
124
    }
125
126
}