Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/managetoken.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require('../config.php');
00028 
00029 require_login();
00030 require_sesskey();
00031 
00032 $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
00033 
00034 $PAGE->set_context($usercontext);
00035 $PAGE->set_url('/user/managetoken.php');
00036 $PAGE->set_title(get_string('securitykeys', 'webservice'));
00037 $PAGE->set_heading(get_string('securitykeys', 'webservice'));
00038 $PAGE->set_pagelayout('standard');
00039 
00040 $rsstokenboxhtml = $webservicetokenboxhtml = '';
00042 if ( !is_siteadmin($USER->id)
00043     && !empty($CFG->enablewebservices)
00044     && has_capability('moodle/webservice:createtoken', $usercontext )) {
00045     require($CFG->dirroot.'/webservice/lib.php');
00046 
00047     $action  = optional_param('action', '', PARAM_ACTION);
00048     $tokenid = optional_param('tokenid', '', PARAM_SAFEDIR);
00049     $confirm = optional_param('confirm', 0, PARAM_BOOL);
00050 
00051     $webservice = new webservice(); //load the webservice library
00052     $wsrenderer = $PAGE->get_renderer('core', 'webservice');
00053 
00054     if ($action == 'resetwstoken') {
00055             $token = $webservice->get_created_by_user_ws_token($USER->id, $tokenid);
00057             if (!$confirm) {
00058                 $resetconfirmation = $wsrenderer->user_reset_token_confirmation($token);
00059             } else {
00061                 $webservice->delete_user_ws_token($tokenid);
00062             }
00063     }
00064 
00065     //no point creating the table is we're just displaying a confirmation screen
00066     if (empty($resetconfirmation)) {
00067         $webservice->generate_user_ws_tokens($USER->id); //generate all token that need to be generated
00068         $tokens = $webservice->get_user_ws_tokens($USER->id);
00069         foreach ($tokens as $token) {
00070             if ($token->restrictedusers) {
00071                 $authlist = $webservice->get_ws_authorised_user($token->wsid, $USER->id);
00072                 if (empty($authlist)) {
00073                     $token->enabled = false;
00074                 }
00075             }
00076         }
00077         $webservicetokenboxhtml =  $wsrenderer->user_webservice_tokens_box($tokens, $USER->id,
00078                 $CFG->enablewsdocumentation); //display the box for web service token
00079     }
00080 }
00081 
00082 //RSS keys
00083 if (!empty($CFG->enablerssfeeds)) {
00084     require_once($CFG->dirroot.'/lib/rsslib.php');
00085 
00086     $action  = optional_param('action', '', PARAM_ACTION);
00087     $confirm = optional_param('confirm', 0, PARAM_BOOL);
00088 
00089     $rssrenderer = $PAGE->get_renderer('core', 'rss');
00090 
00091     if ($action=='resetrsstoken') {
00093         if (!$confirm) {
00094             $resetconfirmation = $rssrenderer->user_reset_rss_token_confirmation();
00095         } else {
00096             rss_delete_token($USER->id);
00097         }
00098     }
00099     if (empty($resetconfirmation)) {
00100         $token = rss_get_token($USER->id);
00101         $rsstokenboxhtml = $rssrenderer->user_rss_token_box($token); //display the box for the user's RSS token
00102     }
00103 }
00104 
00105 // PAGE OUTPUT
00106 echo $OUTPUT->header();
00107 if (!empty($resetconfirmation)) {
00108     echo $resetconfirmation;
00109 } else {
00110     echo $webservicetokenboxhtml;
00111     echo $rsstokenboxhtml;
00112 }
00113 echo $OUTPUT->footer();
00114 
00115 
 All Data Structures Namespaces Files Functions Variables Enumerations