Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LabNbook
LabNbook-Moodle
Commits
9328ed06
Commit
9328ed06
authored
Nov 05, 2019
by
Francois Gannaz
Browse files
move requireLabnbookAuthentication() into local NS
parent
8e92e797
Changes
2
Hide whitespace changes
Inline
Side-by-side
classes/local/helper.php
0 → 100644
View file @
9328ed06
<?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
;
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"
);
}
}
}
mod_form.php
View file @
9328ed06
...
...
@@ -8,15 +8,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use
\
mod_labnbook\fetch
;
use
\
mod_labnbook\form\select_dynamic
;
use
mod_labnbook
\
fetch
;
use
mod_labnbook\form\select_dynamic
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
require_once
(
$CFG
->
dirroot
.
'/course/moodleform_mod.php'
);
// short-cut before loading the form, see `course/modedit.php`
requireLabnbookAuthentication
();
\
mod_labnbook\local\helper
::
requireLabnbookAuthentication
();
define
(
'TEAMCONFIG_METHOD_STUDENTS'
,
1
);
define
(
'TEAMCONFIG_METHOD_RANDOM'
,
3
);
...
...
@@ -187,32 +187,3 @@ EOJS
}
}
}
/**
* Stop loading the form if the current user has no LabnBook account.
*
* @global \Stdclass $COURSE
* @return null
* @throws \moodle_exception
*/
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"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment