Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

helper.php 1.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

/**
 * @package     mod_labnbook
 * @copyright   2019 Université Grenoble Alpes
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace mod_labnbook\local;

11
12
use mod_labnbook\fetch;

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
class helper
{
    /**
     * Stop loading the current page if the current user has no LabnBook account.
     * Redirects on an account binding|creation if necessary.
     *
     * @global \Stdclass $COURSE
     * @return null
     * @throws \moodle_exception
     */
    public static function requireLabnbookAuthentication() {
        global $COURSE;
        if (fetch\user::isAuthenticated()) {
            return;
        }
        $institutionFetcher = new fetch\institution;
        switch ($institutionFetcher->loginUser()) {
            case fetch\institution::OK:
               return;
            case fetch\institution::ERROR_LOGIN_UNKNOWN:
                redirect(
                    "/mod/labnbook/user-binding.php?courseid={$COURSE->id}&return="
                    . base64_encode($_SERVER['REQUEST_URI'])
                );
                break;
            case fetch\institution::ERROR_TOKEN_NOTVALID:
               throw new \moodle_exception("Internal error with LabNbook");
            default:
               throw new \moodle_exception("Unknown error with LabNbook");
        }
    }
}