MDL-28615 mod_forum: Fixed the users page that shows all of the users posts
[moodle.git] / user / managetoken.php
blob46cb3330173df5e8d5deeab864c6740746cfb22e
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Web service test client.
21 * @package webservice
22 * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
23 * @author Jerome Mouneyrac
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../config.php');
29 require_login();
30 require_sesskey();
32 $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
34 $PAGE->set_context($usercontext);
35 $PAGE->set_url('/user/managetoken.php');
36 $PAGE->set_title(get_string('securitykeys', 'webservice'));
37 $PAGE->set_heading(get_string('securitykeys', 'webservice'));
38 $PAGE->set_pagelayout('standard');
40 $rsstokenboxhtml = $webservicetokenboxhtml = '';
41 /// Manage user web service tokens
42 if ( !is_siteadmin($USER->id)
43 && !empty($CFG->enablewebservices)
44 && has_capability('moodle/webservice:createtoken', $usercontext )) {
45 require($CFG->dirroot.'/webservice/lib.php');
47 $action = optional_param('action', '', PARAM_ACTION);
48 $tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
49 $confirm = optional_param('confirm', 0, PARAM_BOOL);
51 $webservice = new webservice(); //load the webservice library
52 $wsrenderer = $PAGE->get_renderer('core', 'webservice');
54 if ($action == 'resetwstoken') {
55 $token = $webservice->get_created_by_user_ws_token($USER->id, $tokenid);
56 /// Display confirmation page to Reset the token
57 if (!$confirm) {
58 $resetconfirmation = $wsrenderer->user_reset_token_confirmation($token);
59 } else {
60 /// Delete the token that need to be regenerated
61 $webservice->delete_user_ws_token($tokenid);
65 //no point creating the table is we're just displaying a confirmation screen
66 if (empty($resetconfirmation)) {
67 $webservice->generate_user_ws_tokens($USER->id); //generate all token that need to be generated
68 $tokens = $webservice->get_user_ws_tokens($USER->id);
69 $webservicetokenboxhtml = $wsrenderer->user_webservice_tokens_box($tokens, $USER->id,
70 $CFG->enablewsdocumentation); //display the box for web service token
74 //RSS keys
75 if (!empty($CFG->enablerssfeeds)) {
76 require_once($CFG->dirroot.'/lib/rsslib.php');
78 $action = optional_param('action', '', PARAM_ACTION);
79 $confirm = optional_param('confirm', 0, PARAM_BOOL);
81 $rssrenderer = $PAGE->get_renderer('core', 'rss');
83 if ($action=='resetrsstoken') {
84 /// Display confirmation page to Reset the token
85 if (!$confirm) {
86 $resetconfirmation = $rssrenderer->user_reset_rss_token_confirmation();
87 } else {
88 rss_delete_token($USER->id);
91 if (empty($resetconfirmation)) {
92 $token = rss_get_token($USER->id);
93 $rsstokenboxhtml = $rssrenderer->user_rss_token_box($token); //display the box for the user's RSS token
97 // PAGE OUTPUT
98 echo $OUTPUT->header();
99 if (!empty($resetconfirmation)) {
100 echo $resetconfirmation;
101 } else {
102 echo $webservicetokenboxhtml;
103 echo $rsstokenboxhtml;
105 echo $OUTPUT->footer();