Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 96
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 / 94
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 / 86
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        $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
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 $messenger_collection */
137                $messenger_collection = $phpbb_container->get('messenger.method_collection');
138                /** @var \phpbb\messenger\method\messenger_interface $messenger_method */
139                $messenger_method = $messenger_collection->offsetGet('messenger.method.email');
140
141                while ($row = $db->sql_fetchrow($result))
142                {
143                    $messenger_method->set_use_queue(false);
144                    $messenger_method->template('admin_activate', $row['user_lang']);
145                    $messenger_method->set_addresses($row);
146                    $messenger_method->anti_abuse_headers($config, $user);
147                    $messenger_method->assign_vars([
148                        'USERNAME'            => html_entity_decode($user_row['username'], ENT_COMPAT),
149                        'U_USER_DETAILS'    => $board_url . "/memberlist.$phpEx?mode=viewprofile&u={$user_row['user_id']}",
150                        'U_ACTIVATE'        => $board_url . "/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k={$user_row['user_actkey']}",
151                    ]);
152
153                    $messenger_method->send();
154                }
155                $db->sql_freeresult($result);
156            }
157
158            $this->update_activation_expiration();
159
160            meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
161
162            $message = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? $user->lang['ACTIVATION_EMAIL_SENT_ADMIN'] : $user->lang['ACTIVATION_EMAIL_SENT'];
163            $message .= '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
164            trigger_error($message);
165        }
166
167        $template->assign_vars(array(
168            'USERNAME'            => $username,
169            'EMAIL'                => $email,
170            'S_PROFILE_ACTION'    => append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=resend_act'))
171        );
172
173        $this->tpl_name = 'ucp_resend';
174        $this->page_title = 'UCP_RESEND';
175    }
176
177    /**
178     * Update activation expiration to 1 day from now
179     *
180     * @return void
181     */
182    protected function update_activation_expiration(): void
183    {
184        global $db, $user;
185
186        $sql_ary = [
187            'user_actkey_expiration'    => $user::get_token_expiration(),
188        ];
189
190        $sql = 'UPDATE ' . USERS_TABLE . '
191            SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
192            WHERE user_id = ' . (int) $user->id();
193        $db->sql_query($sql);
194    }
195}