-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
131 lines (117 loc) · 4.95 KB
/
signup.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?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/>.
/**
* Twili OTP authentication plugin signup.
*
* @package auth_twiliootp
* @author Erudisiya <[email protected]>
* @copyright 2024 Erudisiya Team(https://erudisiya.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
global $CFG;
require_once($CFG->dirroot . '/user/editlib.php');
require_once($CFG->libdir . '/authlib.php');
require_once($CFG->dirroot . '/login/lib.php');
require_once($CFG->dirroot . '/auth/twiliootp/auth.php');
require_once('lib.php');
if (!$authplugin = signup_is_enabled_twiliootp()) {
throw new \moodle_exception('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$PAGE->set_url('/auth/twiliootp/signup.php');
$PAGE->set_context(context_system::instance());
// If wantsurl is empty or /login/signup.php, override wanted URL.
// We do not want to end up here again if user clicks "Login".
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = $CFG->wwwroot . '/';
} else {
$wantsurl = new moodle_url($SESSION->wantsurl);
if ($PAGE->url->compare($wantsurl, URL_MATCH_BASE)) {
$SESSION->wantsurl = $CFG->wwwroot . '/';
}
}
if (isloggedin() and !isguestuser()) {
// Prevent signing up when already logged in.
echo $OUTPUT->header();
echo $OUTPUT->box_start();
$logout = new single_button(new moodle_url('/login/logout.php',
array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
$continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
// If verification of age and location (digital minor check) is enabled.
if (\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) {
$cache = cache::make('core', 'presignup');
$isminor = $cache->get('isminor');
if ($isminor === false) {
// The verification of age and location (minor) has not been done.
redirect(new moodle_url('/login/verify_age_location.php'));
} else if ($isminor === 'yes') {
// The user that attempts to sign up is a digital minor.
redirect(new moodle_url('/login/digital_minor.php'));
}
}
// Plugins can create pre sign up requests.
// Can be used to force additional actions before sign up such as acceptance of policies, validations, etc.
core_login_pre_signup_requests();
$mform_signup = signup_form();
if ($mform_signup->is_cancelled()) {
redirect(get_login_url());
} else if ($user = $mform_signup->get_data()) {
// Add missing required fields.
$user = signup_setup_new_user($user);
// Plugins can perform post sign up actions once data has been validated.
core_login_post_signup_requests($user);
$user->auth = 'twiliootp';
$auth = get_auth_plugin($user->auth);
$auth->user_signup($user, true);// prints notice and link to login/index.php
$auth->user_confirm($user->username, $user->secret);
//$loggedinuser = authenticate_user_login($user->username, $user->password);
//complete_user_login($loggedinuser);
$redirect_url = new moodle_url('/my/');
redirect($redirect_url, 'Account created successfully! Please login', 20);
exit; //never reached
}
$newaccount = get_string('newaccount');
$login = get_string('login');
$PAGE->navbar->add($login);
$PAGE->navbar->add($newaccount);
$PAGE->set_pagelayout('login');
$PAGE->set_title($newaccount);
$PAGE->set_heading($SITE->fullname);
$cssurl = new moodle_url('/auth/twiliootp/style/style.css');
$PAGE->requires->css($cssurl);
echo $OUTPUT->header();
$plugin = get_auth_plugin('twiliootp');
$minrequestperiod = $plugin->config->minrequestperiod;
$PAGE->requires->js_call_amd('auth_twiliootp/sendbutton','auth_twiliootp',array('twiliootp',$minrequestperiod));
if ($mform_signup instanceof renderable) {
// Try and use the renderer from the auth plugin if it exists.
try {
$renderer = $PAGE->get_renderer('auth_twiliootp');
} catch (coding_exception $ce) {
// Fall back on the general renderer.
$renderer = $OUTPUT;
}
echo $renderer->render($mform_signup);
} else {
// Fall back for auth plugins not using renderables.
$mform_signup->display();
}
echo $OUTPUT->footer();