mirror of
https://github.com/moodle/moodle.git
synced 2025-07-26 00:31:35 +02:00
MDL-59008 repository_onedrive: add method to serve login on a popup
This commit is contained in:
@@ -127,6 +127,33 @@ class repository_onedrive extends repository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print the login in a popup.
|
||||||
|
*
|
||||||
|
* @param array|null $attr Custom attributes to be applied to popup div.
|
||||||
|
*/
|
||||||
|
public function print_login_popup($attr = null) {
|
||||||
|
global $OUTPUT, $PAGE;
|
||||||
|
|
||||||
|
$client = $this->get_user_oauth_client(false);
|
||||||
|
$url = new moodle_url($client->get_login_url());
|
||||||
|
$state = $url->get_param('state') . '&reloadparent=true';
|
||||||
|
$url->param('state', $state);
|
||||||
|
|
||||||
|
$PAGE->set_pagelayout('embedded');
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
$repositoryname = get_string('pluginname', 'repository_onedrive');
|
||||||
|
|
||||||
|
$button = new single_button($url, get_string('logintoaccount', 'repository', $repositoryname), 'post', true);
|
||||||
|
$button->add_action(new popup_action('click', $url, 'Login'));
|
||||||
|
$button->class = 'mdl-align';
|
||||||
|
$button = $OUTPUT->render($button);
|
||||||
|
echo html_writer::div($button, '', $attr);
|
||||||
|
|
||||||
|
echo $OUTPUT->footer();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the breadcrumb from a path.
|
* Build the breadcrumb from a path.
|
||||||
*
|
*
|
||||||
@@ -564,8 +591,16 @@ class repository_onedrive extends repository {
|
|||||||
$storedfile->get_filename(),
|
$storedfile->get_filename(),
|
||||||
$forcedownload);
|
$forcedownload);
|
||||||
$url->param('sesskey', sesskey());
|
$url->param('sesskey', sesskey());
|
||||||
$userauth = $this->get_user_oauth_client($url);
|
$param = ($options['embed'] == true) ? false : $url;
|
||||||
|
$userauth = $this->get_user_oauth_client($param);
|
||||||
|
|
||||||
if (!$userauth->is_logged_in()) {
|
if (!$userauth->is_logged_in()) {
|
||||||
|
if ($options['embed'] == true) {
|
||||||
|
// Due to Same-origin policy, we cannot redirect to onedrive login page.
|
||||||
|
// If the requested file is embed and the user is not logged in, add option to log in using a popup.
|
||||||
|
$this->print_login_popup(['style' => 'margin-top: 250px']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
redirect($userauth->get_login_url());
|
redirect($userauth->get_login_url());
|
||||||
}
|
}
|
||||||
if ($userauth === false) {
|
if ($userauth === false) {
|
||||||
@@ -703,8 +738,10 @@ class repository_onedrive extends repository {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function set_file_sharing_anyone_with_link_can_read(\repository_onedrive\rest $client, $fileid) {
|
protected function set_file_sharing_anyone_with_link_can_read(\repository_onedrive\rest $client, $fileid) {
|
||||||
|
|
||||||
|
$type = (isset($this->options['embed']) && $this->options['embed'] == true) ? 'embed' : 'view';
|
||||||
$updateread = [
|
$updateread = [
|
||||||
'type' => 'view',
|
'type' => $type,
|
||||||
'scope' => 'anonymous'
|
'scope' => 'anonymous'
|
||||||
];
|
];
|
||||||
$params = ['fileid' => $fileid];
|
$params = ['fileid' => $fileid];
|
||||||
|
Reference in New Issue
Block a user