-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfirm.php
executable file
·78 lines (73 loc) · 3.14 KB
/
confirm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Subscription confirmation script for newsletter module
*
* @package mod_newsletter
* @copyright 2013 Ivan Šakić <[email protected]>
* @copyright 2015 onwards David Bogner <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__, 3) .'/config.php');
require_once($CFG->dirroot . '/mod/newsletter/lib.php');
$data = required_param(NEWSLETTER_PARAM_DATA, PARAM_ALPHANUMEXT); // Formatted as: secret-userid.
$dataelements = explode('-', $data, 4);
$secret = clean_param($dataelements[0], PARAM_ALPHANUM);
$userid = clean_param($dataelements[1], PARAM_INT);
$newsletterid = clean_param($dataelements[2], PARAM_INT);
if (count($dataelements) == 4) {
if ($dataelements[3] == "guest") {
$guestuser = 1;
}
}
$cm = get_coursemodule_from_instance('newsletter', $newsletterid);
$context = context_module::instance($cm->id);
$PAGE->set_context($context);
if ($secret && $userid) {
if (!$user = get_complete_user_data('id', $userid)) {
throw new \moodle_exception("Cannot find user!");
}
if ($user->confirmed) {
redirect(new moodle_url('/mod/newsletter/view.php', array('id' => $cm->id)),
"You are already registered and subscribed!", 5);
// TODO: user/editadvanced.php?id=2.
} else {
if ($secret === $user->secret) {
global $DB;
$DB->set_field('user', 'confirmed', 1, array('id' => $user->id));
complete_user_login($user);
if (!isset($guestuser)) {
if (!$welcomemessage = $DB->get_field('newsletter', 'welcomemessage',
array('id' => $newsletterid))) {
$welcomemessage = get_string('welcometonewsletter', 'mod_newsletter');
}
} else {
if (!$welcomemessage = $DB->get_field('newsletter', 'welcomemessageguestuser',
array('id' => $newsletterid))) {
$welcomemessage = get_string('welcometonewsletter_guestsubscription',
'mod_newsletter');
}
}
redirect(new moodle_url('/mod/newsletter/view.php', array('id' => $cm->id)),
$welcomemessage, 15);
// TODO: user/editadvanced.php?id=2.
} else {
throw new \moodle_exception('The link you followed is invalid.');
}
}
} else {
throw new \moodle_exception('The link you followed is invalid.');
}