Commit 92887093 authored by Francois Gannaz's avatar Francois Gannaz
Browse files

user identification/creation in LnB: save result

parent c477e196
......@@ -150,8 +150,12 @@ class mod_labnbook_session
protected function fetchUserId($force = false) {
global $DB, $SESSION, $USER;
if ($force || !isset($SESSION->labnbook_userid)) {
if (empty($USER) || empty($USER->id)) {
throw new Exception("Please log into Moodle");
}
$userId = $DB->get_field("labnbook_user", "labnbook_userid", ['userid' => $USER->id]);
if (!$userId && $this->identifyByStudentNumber && $USER->idnumber) {
$knownUser = $userId > 0;
if (!$userId && $this->identifyByStudentNumber && !empty($USER->idnumber)) {
$userId = $this->fetch('GET', "/user/identify", null, ['idnumber' => $USER->idnumber]);
}
if (!$userId && $this->identifyByCasAuth && $USER->auth === 'cas') {
......@@ -172,6 +176,12 @@ class mod_labnbook_session
$user['teacher'] = false;
$userId = $this->fetch('PUT', "/user/create", null, $user);
}
if (!$knownUser && $userId > 0) {
$DB->insert_record(
"labnbook_user",
(object) ['userid' => $USER->id, 'labnbook_userid' => $userId, 'timemodified' => time()]
);
}
$SESSION->labnbook_userid = (int) $userId;
}
return $SESSION->labnbook_userid;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment