Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 97
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ucp_resend
0.00% covered (danger)
0.00%
0 / 95
0.00% covered (danger)
0.00%
0 / 2
600
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 87
0.00% covered (danger)
0.00%
0 / 1
552
 update_activation_expiration
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22/**
23* ucp_resend
24* Resending activation emails
25*/
26class ucp_resend
27{
28    var $u_action;
29
30    function main($id, $mode)
31    {
32        global $config, $phpbb_root_path, $phpEx;
33        global $db, $user, $auth, $template, $request, $phpbb_container;
34
35        /** @var \phpbb\controller\helper $controller_helper */
36        $controller_helper = $phpbb_container->get('controller.helper');
37
38        $username    = $request->variable('username', '', true);
39        $email        = strtolower($request->variable('email', ''));
40        $submit        = (isset($_POST['submit'])) ? true : false;
41
42        add_form_key('ucp_resend');
43
44        if ($submit)
45        {
46            if (!check_form_key('ucp_resend'))
47            {
48                trigger_error('FORM_INVALID');
49            }
50
51            $sql = 'SELECT user_id, group_id, username, user_email, user_type, user_lang, user_actkey, user_actkey_expiration, user_inactive_reason
52                FROM ' . USERS_TABLE . "
53                WHERE user_email = '" . $db->sql_escape($email) . "'
54                    AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
55            $result = $db->sql_query($sql);
56            $user_row = $db->sql_fetchrow($result);
57            $db->sql_freeresult($result);
58
59            if (!$user_row)
60            {
61                trigger_error('NO_EMAIL_USER');
62            }
63
64            if ($user_row['user_type'] == USER_IGNORE)
65            {
66                trigger_error('NO_USER');
67            }
68
69            if (!$user_row['user_actkey'] && $user_row['user_type'] != USER_INACTIVE)
70            {
71                trigger_error('ACCOUNT_ALREADY_ACTIVATED');
72            }
73
74            if (!$user_row['user_actkey'] || ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_MANUAL))
75            {
76                trigger_error('ACCOUNT_DEACTIVATED');
77            }
78
79            // Do not resend activation email if valid one still exists
80            if (!empty($user_row['user_actkey']) && (int) $user_row['user_actkey_expiration'] >= time())
81            {
82                trigger_error('ACTIVATION_ALREADY_SENT');
83            }
84
85            // Determine coppa status on group (REGISTERED(_COPPA))
86            $sql = 'SELECT group_name, group_type
87                FROM ' . GROUPS_TABLE . '
88                WHERE group_id = ' . $user_row['group_id'];
89            $result = $db->sql_query($sql);
90            $row = $db->sql_fetchrow($result);
91            $db->sql_freeresult($result);
92
93            if (!$row)
94            {
95                trigger_error('NO_GROUP');
96            }
97
98            $board_url = generate_board_url();
99            $coppa = ($row['group_name'] == 'REGISTERED_COPPA' && $row['group_type'] == GROUP_SPECIAL) ? true : false;
100
101            $email_method = $phpbb_container->get('messenger.method.email');
102            $email_method->set_use_queue(false);
103
104            if ($config['require_activation'] == USER_ACTIVATION_SELF || $coppa)
105            {
106                $email_method->template(($coppa) ? 'coppa_resend_inactive' : 'user_resend_inactive', $user_row['user_lang']);
107                $email_method->set_addresses($user_row);
108
109                $email_method->anti_abuse_headers($config, $user);
110
111                $email_method->assign_vars([
112                    'WELCOME_MSG'    => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
113                    'USERNAME'        => html_entity_decode($user_row['username'], ENT_COMPAT),
114                    'U_ACTIVATE'    => $board_url . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
115                ]);
116
117                if ($coppa)
118                {
119                    $email_method->assign_vars([
120                        'FAX_INFO'        => $config['coppa_fax'],
121                        'MAIL_INFO'        => $config['coppa_mail'],
122                        'EMAIL_ADDRESS'    => $user_row['user_email'],
123                    ]);
124                }
125
126                $email_method->send();
127            }
128
129            if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
130            {
131                // Grab an array of user_id's with a_user permissions ... these users can activate a user
132                $admin_ary = $auth->acl_get_list(false, 'a_user', false);
133
134                $sql = 'SELECT user_id, username, user_email, user_lang
135                    FROM ' . USERS_TABLE . '
136                    WHERE ' . $db->sql_in_set('user_id', $admin_ary[0]['a_user']);
137                $result = $db->sql_query($sql);
138
139                /** @var \phpbb\di\service_collection $messenger_collection */
140                $messenger_collection = $phpbb_container->get('messenger.method_collection');
141                /** @var \phpbb\messenger\method\messenger_interface $messenger_method */
142                $messenger_method = $messenger_collection->offsetGet('messenger.method.email');
143
144                while ($row = $db->sql_fetchrow($result))
145                {
146                    $messenger_method->set_use_queue(false);
147                    $messenger_method->template('admin_activate', $row['user_lang']);
148                    $messenger_method->set_addresses($row);
149                    $messenger_method->anti_abuse_headers($config, $user);
150                    $messenger_method->assign_vars([
151                        'USERNAME'            => html_entity_decode($user_row['username'], ENT_COMPAT),
152                        'U_USER_DETAILS'    => $board_url . "/memberlist.$phpEx?mode=viewprofile&u={$user_row['user_id']}",
153                        'U_ACTIVATE'        => $board_url . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
154                    ]);
155
156                    $messenger_method->send();
157                }
158                $db->sql_freeresult($result);
159            }
160
161            $this->update_activation_expiration();
162
163            meta_refresh(3, $controller_helper->route('phpbb_index_controller'));
164
165            $message = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? $user->lang['ACTIVATION_EMAIL_SENT_ADMIN'] : $user->lang['ACTIVATION_EMAIL_SENT'];
166            $message .= '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $controller_helper->route('phpbb_index_controller') . '">', '</a>');
167            trigger_error($message);
168        }
169
170        $template->assign_vars(array(
171            'USERNAME'            => $username,
172            'EMAIL'                => $email,
173            'S_PROFILE_ACTION'    => append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=resend_act'))
174        );
175
176        $this->tpl_name = 'ucp_resend';
177        $this->page_title = 'UCP_RESEND';
178    }
179
180    /**
181     * Update activation expiration to 1 day from now
182     *
183     * @return void
184     */
185    protected function update_activation_expiration(): void
186    {
187        global $db, $user;
188
189        $sql_ary = [
190            'user_actkey_expiration'    => $user::get_token_expiration(),
191        ];
192
193        $sql = 'UPDATE ' . USERS_TABLE . '
194            SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
195            WHERE user_id = ' . (int) $user->id();
196        $db->sql_query($sql);
197    }
198}