diff options
Diffstat (limited to 'src/leap/bitmask/core/web')
-rw-r--r-- | src/leap/bitmask/core/web/bitmask.js | 116 | ||||
-rw-r--r-- | src/leap/bitmask/core/web/index.html | 72 |
2 files changed, 147 insertions, 41 deletions
diff --git a/src/leap/bitmask/core/web/bitmask.js b/src/leap/bitmask/core/web/bitmask.js index 39e677f..9ac11b7 100644 --- a/src/leap/bitmask/core/web/bitmask.js +++ b/src/leap/bitmask/core/web/bitmask.js @@ -29,9 +29,14 @@ */ var bitmask = function(){ var event_handlers = {}; + + var api_url = '/API/'; + if (window.location.protocol === "file:") { + api_url = 'http://localhost:7070/API/'; + } function call(command) { - var url = '/API/' + command.slice(0, 2).join('/'); + var url = api_url + command.slice(0, 2).join('/'); var data = JSON.stringify(command.slice(2)); return new Promise(function(resolve, reject) { @@ -88,50 +93,83 @@ var bitmask = function(){ }; return { - /** - * uids are of the form user@provider.net - */ - user: { - /** - * Check wich user is active - * - * @return {Promise<string>} The uid of the active user - */ - active: function() { - return call(['user', 'active']); - }, + bonafide: { + provider: { + create: function(domain) { + return call(['bonafide', 'provider', 'create', domain]); + }, - /** - * Register a new user - * - * @param {string} uid The uid to be created - * @param {string} password The user password - */ - create: function(uid, password) { - return call(['user', 'create', uid, password]); - }, + read: function(domain) { + return call(['bonafide', 'provider', 'read', domain]); + }, - /** - * Login - * - * @param {string} uid The uid to log in - * @param {string} password The user password - */ - auth: function(uid, password) { - return call(['user', 'authenticate', uid, password]); + delete: function(domain) { + return call(['bonafide', 'provider', 'delete', domain]); + }, + + list: function(seeded) { + if (typeof seeded !== 'boolean') { + seeded = false; + } + return call(['bonafide', 'provider', 'list', seeded]); + } }, /** - * Logout - * - * @param {string} uid The uid to log out. - * If no uid is provided the active user will be used + * uids are of the form user@provider.net */ - logout: function(uid) { - if (typeof uid !== 'string') { - uid = ""; + user: { + /** + * Check wich user is active + * + * @return {Promise<string>} The uid of the active user + */ + active: function() { + return call(['bonafide', 'user', 'active']); + }, + + /** + * Register a new user + * + * @param {string} uid The uid to be created + * @param {string} password The user password + * @param {boolean} autoconf If the provider should be autoconfigured if it's not allready known + * If it's not provided it will default to false + */ + create: function(uid, password, autoconf) { + if (typeof autoconf !== 'boolean') { + autoconf = false; + } + return call(['bonafide', 'user', 'create', uid, password, autocnof]); + }, + + /** + * Login + * + * @param {string} uid The uid to log in + * @param {string} password The user password + * @param {boolean} autoconf If the provider should be autoconfigured if it's not allready known + * If it's not provided it will default to false + */ + auth: function(uid, password, autoconf) { + if (typeof autoconf !== 'boolean') { + autoconf = false; + } + return call(['bonafide', 'user', 'authenticate', uid, password, autoconf]); + }, + + /** + * Logout + * + * @param {string} uid The uid to log out. + * If no uid is provided the active user will be used + */ + logout: function(uid) { + if (typeof uid !== 'string') { + uid = ""; + } + return call(['bonafide', 'user', 'logout', uid]); } - return call(['user', 'logout', uid]); } }, @@ -153,7 +191,7 @@ var bitmask = function(){ * @return {Promise<string>} The token */ get_token: function() { - return call(['mail', 'get-token']); + return call(['mail', 'get_token']); } }, diff --git a/src/leap/bitmask/core/web/index.html b/src/leap/bitmask/core/web/index.html index 7ffbb3f..9951a9b 100644 --- a/src/leap/bitmask/core/web/index.html +++ b/src/leap/bitmask/core/web/index.html @@ -12,10 +12,57 @@ bitmask.events.register("KEYMANAGER_KEY_FOUND", event_handler); }; + function configure() { + var domain = document.getElementById('domain').value; + bitmask.bonafide.provider.create(domain).then(function(response) { + log("Provider configured: "); + for (k in response) { + log(" " + k + ": " + response[k]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + + function read() { + var domain = document.getElementById('domain').value; + bitmask.bonafide.provider.read(domain).then(function(response) { + log("Provider configuration: "); + for (k in response) { + log(" " + k + ": " + response[k]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + + function del() { + var domain = document.getElementById('domain').value; + bitmask.bonafide.provider.delete(domain).then(function(response) { + log("Provider deleted: "); + for (k in response) { + log(" " + k + ": " + response[k]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + + function list() { + bitmask.bonafide.provider.list().then(function(response) { + log("List providers: "); + for (k in response) { + log(" domain: " + response[k]["domain"]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + function login() { var email = document.getElementById('email').value; var password = document.getElementById('password').value; - bitmask.user.auth(email, password).then(function(response) { + bitmask.bonafide.user.auth(email, password).then(function(response) { log("We are logged in: "); for (k in response) { log(" " + k + ": " + response[k]); @@ -26,7 +73,7 @@ }; function logout() { - bitmask.user.logout().then(function(response) { + bitmask.bonafide.user.logout().then(function(response) { log("We are logged out: "); for (k in response) { log(" " + k + ": " + response[k]); @@ -36,6 +83,19 @@ }); }; + function user() { + bitmask.bonafide.user.active().then(function(response) { + log("The active user is: " + response); + }, function(error) { + log("Some error ocurred: " + error); + }); + bitmask.mail.get_token().then(function(response) { + log("The token is: " + response); + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + function event_handler(evnt, content) { log("Event: " + evnt); for (i in content) { @@ -53,11 +113,19 @@ <h1>Bitmask Control Panel</h1> <noscript>You must enable JavaScript</noscript> <form> + <p>Provider: <input id="domain" type="text" size="50" maxlength="50" value="mail.bitmask.net"></p> + </form> + <button onclick='configure();'>Configure provider</button> + <button onclick='read();'>Read providers</button> + <button onclick='del();'>Delete providers</button> + <button onclick='list();'>List providers</button> + <form> <p>Email address: <input id="email" type="text" size="50" maxlength="50" value="user@mail.bitmask.net"></p> <p>Password: <input id="password" type="password" size="50" maxlength="50" ></p> </form> <button onclick='login();'>Log In</button> <button onclick='logout();'>Log Out</button> + <button onclick='user();'>User</button> <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre> </body> </html> |