Skip to content

Commit

Permalink
rss MDL-22204 added ability for user to reset their rss token
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed May 13, 2010
1 parent bfebaf6 commit 842cd18
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6970,6 +6970,7 @@ function get_core_subsystems() {
'rating' => 'rating',
'register' => 'admin/registration',
'repository' => 'repository',
'rss' => 'rss',
'role' => $CFG->admin.'/role',
'simpletest' => NULL,
'search' => 'search',
Expand Down
85 changes: 85 additions & 0 deletions rss/renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////

/**
* Web service documentation renderer.
* @package rss
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

class core_rss_renderer extends plugin_renderer_base {
/**
* Returns the html for the token reset confirmation box
* @param object $token to reset
* @return string html
*/
public function user_reset_rss_token_confirmation() {
global $OUTPUT, $CFG;
$managetokenurl = $CFG->wwwroot."/user/managetoken.php?sesskey=" . sesskey();
$optionsyes = array('action'=>'resetrsstoken', 'confirm'=>1, 'sesskey'=>sesskey());
$optionsno = array('section'=>'webservicetokens', 'sesskey'=>sesskey());
$formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes), get_string('reset'));
$formcancel = new single_button(new moodle_url($managetokenurl, $optionsno), get_string('cancel'), 'get');
$html = $OUTPUT->confirm(get_string('resettokenconfirmsimple', 'webservice'), $formcontinue, $formcancel);
return $html;
}

/**
* Display user tokens with buttons to reset them
* @param object $tokens
* @param int $userid
* @return string html code
*/
public function user_rss_token_box($token) {
global $OUTPUT, $CFG;

// display strings
$stroperation = get_string('operation', 'webservice');
$strtoken = get_string('key', 'webservice');

$return = $OUTPUT->heading(get_string('rss'), 3, 'main', true);
$return .= $OUTPUT->box_start('generalbox webservicestokenui');

//$return .= get_string('keyshelp', 'webservice');

$table = new html_table();
$table->head = array($strtoken, $stroperation);
$table->align = array('left', 'center');
$table->width = '100%';
$table->data = array();

if (!empty($token)) {
$reset = "<a href=\"".$CFG->wwwroot."/user/managetoken.php?sesskey=".sesskey().
"&amp;action=resetrsstoken\">".get_string('reset')."</a>";

$table->data[] = array($token, $reset);

$return .= html_writer::table($table);
} else {
$return .= get_string('notoken', 'webservice');
}

$return .= $OUTPUT->box_end();
return $return;
}
}
52 changes: 35 additions & 17 deletions user/managetoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/

require('../config.php');
require($CFG->dirroot.'/webservice/lib.php');

$PAGE->set_url('/user/managetoken.php');
$PAGE->set_title(get_string('securitykeys', 'webservice'));
Expand All @@ -34,10 +33,12 @@
require_login();
require_sesskey();

$webservicetokenboxhtml = '';
$rsstokenboxhtml = $webservicetokenboxhtml = '';
/// Manage user web service tokens
if ( !is_siteadmin($USER->id) && !empty($CFG->enablewebservices) &&
has_capability('moodle/webservice:createtoken', get_system_context())) {
if ( !is_siteadmin($USER->id)
&& !empty($CFG->enablewebservices)
&& has_capability('moodle/webservice:createtoken', get_system_context() )) {
require($CFG->dirroot.'/webservice/lib.php');

$action = optional_param('action', '', PARAM_ACTION);
$tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
Expand All @@ -52,33 +53,50 @@
if (!$confirm) {
$resetconfirmation = $wsrenderer->user_reset_token_confirmation($token);
} else {
/// Delete the token that need to be regenerated
/// Delete the token that need to be regenerated
$webservice->delete_user_ws_token($tokenid);
}
}

$webservice->generate_user_ws_tokens($USER->id); //generate all token that need to be generated
$tokens = $webservice->get_user_ws_tokens($USER->id);
$webservicetokenboxhtml = $wsrenderer->user_webservice_tokens_box($tokens, $USER->id); //display the box for web service token
//no point creating the table is we're just displaying a confirmation screen
if (empty($resetconfirmation)) {
$webservice->generate_user_ws_tokens($USER->id); //generate all token that need to be generated
$tokens = $webservice->get_user_ws_tokens($USER->id);
$webservicetokenboxhtml = $wsrenderer->user_webservice_tokens_box($tokens, $USER->id); //display the box for web service token
}
}

//TODO Manage RSS keys
//1- the reset confirmation page content should go into $resetconfirmation
//2- create a table/box for the RSS key
//PS: in 2 if you prefer to add a special row to the ws table in this case move
//the renderer somewhere else, add a new column to make difference between web service and RSS, change the name of the
//renderer function.
//RSS keys
if (!empty($CFG->enablerssfeeds)) {
require_once($CFG->dirroot.'/lib/rsslib.php');

$action = optional_param('action', '', PARAM_ACTION);
$confirm = optional_param('confirm', 0, PARAM_BOOL);

$rssrenderer = $PAGE->get_renderer('core', 'rss');

if ($action=='resetrsstoken') {
/// Display confirmation page to Reset the token
if (!$confirm) {
$resetconfirmation = $rssrenderer->user_reset_rss_token_confirmation();
} else {
rss_delete_token($USER->id);
}
}
if (empty($resetconfirmation)) {
$token = rss_get_token($USER->id);
$rsstokenboxhtml = $rssrenderer->user_rss_token_box($token); //display the box for the user's RSS token
}
}


// PAGE OUTPUT
echo $OUTPUT->header();
if (!empty($resetconfirmation)) {
echo $resetconfirmation; //TODO the RSS regenerate confirmation content code should
//be containt into $resetconfirmation too
echo $resetconfirmation;
} else {
echo $webservicetokenboxhtml;
//TODO: echo RSS table html here
echo $rsstokenboxhtml;
}
echo $OUTPUT->footer();

Expand Down

0 comments on commit 842cd18

Please sign in to comment.