Labs/F1/Modularity/WebMod HOWTO: Difference between revisions

Jump to navigation Jump to search
Line 59: Line 59:
     WebMod.onLogin(function(credentials, callback) {
     WebMod.onLogin(function(credentials, callback) {
       // inspect the credentials object and use it to authenticate
       // inspect the credentials object and use it to authenticate
 
       // return basic user data via the callback
       // if the user is properly authenticated, provide useful display information
       callback({'status': 'ok', 'displayname': 'Bob Smith', 'username' : 'bobsmith'});
      // otherwise indicate that a login is needed.
       if (properly_logged_in) {
        callback({'status': 'ok', 'displayname': 'Bob Smith', 'username' : 'bobsmith'});
      } else {
        callback({'status': 'notloggedin'});
      }
     });
     });
   
   
Line 81: Line 86:


Note that jQuery is not required, it is used here to simplify the code.
Note that jQuery is not required, it is used here to simplify the code.
== Authentication ==
For the WebMod to do its work, it may require the user to be logged in. The <tt>login</tt> parameter in the manifest indicates a dialog that the browser may open up when it needs to log in the user. This login dialog should look like this:
<html>
<head>
  <script src="jquery.js" />
  <script src="https://webmods.mozilla.org/js/include.js" />
</head>
<body>
  <script>
    // this function should be run when the user has successfully logged in
    // in the dialog box.
    function when_logged_in() {
      WebMod.successfulLogin(credentials);
    }
  </script>
  ... user interface ...
</body>
668

edits

Navigation menu