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
58b0ad55
Commit
58b0ad55
authored
Nov 05, 2019
by
Francois Gannaz
Browse files
LnB API changed: /redirect instead of /user/link
parent
73534e1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
classes/fetch/institution.php
View file @
58b0ad55
...
...
@@ -62,12 +62,30 @@ class institution extends moodlefetcher
return
self
::
OK
;
}
public
function
getBindingToken
(
$returnUrl
)
:
string
{
return
$this
->
fetcher
->
encodeJwtToken
(
'/v1/user/link'
,
[
'url'
=>
$returnUrl
]);
/**
* Return a JWT token for the redirection page of LnB, so that the user ends on the user-binding page.
*
* @param string $returnUrl Full URL, including protocol.
* @param string $role "learner" | "teacher"
* @return string JWT
* @throws \moodle_exception
*/
public
function
getBindingTokenForRedirect
(
string
$returnUrl
,
string
$role
)
:
string
{
if
(
$role
!==
'learner'
&&
$role
!==
'teacher'
)
{
throw
new
\
moodle_exception
(
"Invalid role value in fetch.institution.getBindingToken()"
);
}
$payload
=
[
'path'
=>
"/user/bind"
,
'forward'
=>
[
'role_ext'
=>
$role
,
'return_to'
=>
$returnUrl
,
],
];
return
$this
->
fetcher
->
encodeJwtToken
(
'/v1/redirect'
,
$payload
);
}
public
function
get
Login
Url
()
:
string
{
public
function
get
Redirect
Url
()
:
string
{
global
$CFG
;
return
rtrim
(
$CFG
->
labnbook_api_url
,
'/'
)
.
'/v1/
user/link
'
;
return
rtrim
(
$CFG
->
labnbook_api_url
,
'/'
)
.
'/v1/
redirect
'
;
}
}
user-binding.php
View file @
58b0ad55
...
...
@@ -22,13 +22,14 @@ require_login($course);
$fetchInstitution
=
new
fetch\institution
();
$context
=
context_course
::
instance
(
$courseid
);
$isTeacher
=
has_capability
(
'mod/labnbook:addinstance'
,
$context
);
if
(
$create
&&
!
fetch\user
::
isAuthenticated
())
{
global
$USER
;
$isTeacher
=
has_capability
(
'mod/labnbook:addinstance'
,
$context
);
if
(
createUser
(
$USER
,
$isTeacher
))
{
redirect
(
$returnUrl
);
}
}
$role
=
(
$isTeacher
?
'teacher'
:
'learner'
);
/* @var $PAGE moodle_page */
global
$PAGE
;
...
...
@@ -49,8 +50,8 @@ echo $OUTPUT->header();
<div
class=
"container-fluid"
>
<div
class=
"row"
>
<div
class=
"col"
style=
"text-align: center"
>
<form
action=
"
<?=
$fetchInstitution
->
get
Login
Url
()
?>
"
method=
"GET"
>
<input
type=
"hidden"
name=
"token"
value=
"
<?=
$fetchInstitution
->
getBindingToken
(
$CFG
->
wwwroot
.
$returnUrl
)
?>
"
/>
<form
action=
"
<?=
$fetchInstitution
->
get
Redirect
Url
()
?>
"
method=
"GET"
>
<input
type=
"hidden"
name=
"token"
value=
"
<?=
$fetchInstitution
->
getBindingToken
ForRedirect
(
$CFG
->
wwwroot
.
$returnUrl
,
$role
)
?>
"
/>
<button
type=
"submit"
class=
"btn btn-primary"
>
Se connecter à LabNbook
</button>
</form>
<div>
Si vous possédez déjà un compte dans LabNbook, ce lien permettra de vous authentifier dans LabNbook et de mettre à jour votre compte Moodle.
</div>
...
...
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