Posts

Showing posts with the label webservice

Angular with a Moodle webservice

Getting Angular to work with a Moodle webservice I am building an application to get Json data from a Moodle web service, and using AngularJs to display the data in the app. There are multiple functions on the Moodle webservice, so I need multiple controllers in the Angular app. I am using Visual Studio and Cordova to write the app. I have come up with a solution for getting the token from Moodle, storing it using jstorage, and displaying it on the various panes of the single-page mobile app. Step 1. Get web token from where you stored it in jstorage (in myApp.js) moodleUrl = 'https://moodle.yourwebsite.com/webservice/rest/server.php' ; session = $ . jStorage . get ( 'session' , '' ); // syntax: $.jStorage.get(keyname, "default value") moodlewsrestformat = 'json' ; wstoken = session ; concatUrl = moodleUrl + '?moodlewsrestformat=' + moodlewsrestformat + '&wstoken=' + wstoken + '&wsfunction=' ; Step...

Authenticate with Moodle from a mobile app

My mobile app needs to log in to Moodle to get Json data from a webservice and display it using Angular. In order to do that, I need to pass in a username and password and get a Moodle webservice token back, so my app doesn't need to log in again (at least until the token expires). Step 1. Check if a token already exists jQuery(document).ready(function () { /* when the user clicks log-out button, destroy the session */ $('#btn_logout').on('click', function () { $('.pane').hide(); /* hide all screens */ $('#menu').toggleClass('ui-panel-open ui-panel-closed'); $.jStorage.deleteKey('session'); makeUserLogin(); }); var session = $.jStorage.get('session', ''); // syntax: $.jStorage.get(keyname, "default value") if (session) { // if there is already a session, redirect to landing pane showApp(); } else { // if there is no session *then...