Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 100
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 / 98
0.00% covered (danger)
0.00%
0 / 2
812
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 90
0.00% covered (danger)
0.00%
0 / 1
756
 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        $username    = $request->variable('username', '', true);
36        $email        = strtolower($request->variable('email', ''));
37        $submit        = (isset($_POST['submit'])) ? true : false;
38
39        add_form_key('ucp_resend');
40
41        if ($submit)
42        {
43            if (!check_form_key('ucp_resend'))
44            {
45                trigger_error('FORM_INVALID');
46            }
47
48            $sql = 'SELECT user_id, group_id, username, user_email, user_type, user_lang, user_actkey, user_actkey_expiration, user_inactive_reason
49                FROM ' . USERS_TABLE . "
50                WHERE user_email = '" . $db->sql_escape($email) . "'
51                    AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
52            $result = $db->sql_query($sql);
53            $user_row = $db->sql_fetchrow($result);
54            $db->sql_freeresult($result);
55
56            if (!$user_row)
57            {
58                trigger_error('NO_EMAIL_USER');
59            }
60
61            if ($user_row['user_type'] == USER_IGNORE)
62            {
63                trigger_error('NO_USER');
64            }
65
66            if (!$user_row['user_actkey'] && $user_row['user_type'] != USER_INACTIVE)
67            {
68                trigger_error('ACCOUNT_ALREADY_ACTIVATED');
69            }
70
71            if (!$user_row['user_actkey'] || ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_MANUAL))
72            {
73                trigger_error('ACCOUNT_DEACTIVATED');
74            }
75
76            // Do not resend activation email if valid one still exists
77            if (!empty($user_row['user_actkey']) && (int) $user_row['user_actkey_expiration'] >= time())
78            {
79                trigger_error('ACTIVATION_ALREADY_SENT');
80            }
81
82            // Determine coppa status on group (REGISTERED(_COPPA))
83            $sql = 'SELECT group_name, group_type
84                FROM ' . GROUPS_TABLE . '
85                WHERE group_id = ' . $user_row['group_id'];
86            $result = $db->sql_query($sql);
87            $row = $db->sql_fetchrow($result);
88            $db->sql_freeresult($result);
89
90            if (!$row)
91            {
92                trigger_error('NO_GROUP');
93            }
94
95            $board_url = generate_board_url();
96            $coppa = ($row['group_name'] == 'REGISTERED_COPPA' && $row['group_type'] == GROUP_SPECIAL) ? true : false;
97
98            $email_method = $phpbb_container->get('messenger.method.email');
99            $email_method->set_use_queue(false);
100
101            if ($config['require_activation'] == USER_ACTIVATION_SELF || $coppa)
102            {
103                $email_method->template(($coppa) ? 'coppa_resend_inactive' : 'user_resend_inactive', $user_row['user_lang']);
104                $email_method->set_addresses($user_row);
105
106                $email_method->anti_abuse_headers($config, $user);
107
108                $email_method->assign_vars([
109                    'WELCOME_MSG'    => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
110                    'USERNAME'        => html_entity_decode($user_row['username'], ENT_COMPAT),
111                    'U_ACTIVATE'    => $board_url . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
112                ]);
113
114                if ($coppa)
115                {
116                    $email_method->assign_vars([
117                        'FAX_INFO'        => $config['coppa_fax'],
118                        'MAIL_INFO'        => $config['coppa_mail'],
119                        'EMAIL_ADDRESS'    => $user_row['user_email'],
120                    ]);
121                }
122
123                $email_method->send();
124            }
125
126            if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
127            {
128                // Grab an array of user_id's with a_user permissions ... these users can activate a user
129                $admin_ary = $auth->acl_get_list(false, 'a_user', false);
130
131                $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
132                    FROM ' . USERS_TABLE . '
133                    WHERE ' . $db->sql_in_set('user_id', $admin_ary[0]['a_user']);
134                $result = $db->sql_query($sql);
135
136                /** @var \phpbb\di\service_collection */
137                $messenger = $phpbb_container->get('messenger.method_collection');
138                $messenger_collection_iterator = $messenger->getIterator();
139                while ($row = $db->sql_fetchrow($result))
140                {
141                    foreach ($messenger_collection_iterator as $messenger_method)
142                    {
143                        $messenger_method->set_use_queue(false);
144                        if ($messenger_method->get_id() == $row['user_notify_type'] || $row['user_notify_type'] == $messenger_method::NOTIFY_BOTH)
145                        {
146                            $messenger_method->template('admin_activate', $row['user_lang']);
147                            $messenger_method->set_addresses($row);
148                            $messenger_method->anti_abuse_headers($config, $user);
149                            $messenger_method->assign_vars([
150                                'USERNAME'            => html_entity_decode($user_row['username'], ENT_COMPAT),
151                                'U_USER_DETAILS'    => $board_url . "/memberlist.$phpEx?mode=viewprofile&u={$user_row['user_id']}",
152                                'U_ACTIVATE'        => $board_url . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
153                            ]);
154
155                            $messenger_method->send();
156                        }
157                    }
158                }
159                $db->sql_freeresult($result);
160
161                // Save the queue in the messenger method class (has to be called or these messages could be lost)
162                foreach ($messenger_collection_iterator as $messenger_method)
163                {
164                    $messenger_method->save_queue();
165                }
166            }
167
168            $this->update_activation_expiration();
169
170            meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
171
172            $message = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? $user->lang['ACTIVATION_EMAIL_SENT_ADMIN'] : $user->lang['ACTIVATION_EMAIL_SENT'];
173            $message .= '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
174            trigger_error($message);
175        }
176
177        $template->assign_vars(array(
178            'USERNAME'            => $username,
179            'EMAIL'                => $email,
180            'S_PROFILE_ACTION'    => append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=resend_act'))
181        );
182
183        $this->tpl_name = 'ucp_resend';
184        $this->page_title = 'UCP_RESEND';
185    }
186
187    /**
188     * Update activation expiration to 1 day from now
189     *
190     * @return void
191     */
192    protected function update_activation_expiration(): void
193    {
194        global $db, $user;
195
196        $sql_ary = [
197            'user_actkey_expiration'    => $user::get_token_expiration(),
198        ];
199
200        $sql = 'UPDATE ' . USERS_TABLE . '
201            SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
202            WHERE user_id = ' . (int) $user->id();
203        $db->sql_query($sql);
204    }
205}