user-binding.php 1006 Bytes
Newer Older
Francois Gannaz's avatar
Francois Gannaz committed
1
2
3
4
<?php

/**
 * Inner HTL page.
Francois Gannaz's avatar
Francois Gannaz committed
5
 * Bind a Moodle user to a LabNbook account.
Francois Gannaz's avatar
Francois Gannaz committed
6
7
8
9
 *
 * @copyright   2019 Université Grenoble Alpes
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
Francois Gannaz's avatar
Francois Gannaz committed
10
use mod_labnbook\fetch;
Francois Gannaz's avatar
Francois Gannaz committed
11

Francois Gannaz's avatar
Francois Gannaz committed
12
require_once \dirname(__DIR__, 2) . '/config.php';
13

14
$returnUrl = \base64_decode(required_param('return', PARAM_RAW));
15
16
17
18
19
20
21
$courseid = required_param('courseid', PARAM_INT);

$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);

$fetchInstitution = new fetch\institution();
$context = context_course::instance($courseid);
22
23
$isTeacher = has_capability('mod/labnbook:addinstance', $context);
$role = ($isTeacher ? 'teacher' : 'learner');
24
global $USER;
25
$url = $fetchInstitution->getRedirectUrl();
David Beniamine's avatar
David Beniamine committed
26
27
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$returnUrl";
$token=$fetchInstitution->getBindingTokenForRedirect($actual_link, $role, $USER);
28
redirect($url."?token=".$token);