Browse Source

Cleanup of session register code.

pull/28/head
Simon Eisenmann 12 years ago
parent
commit
8442e45807
  1. 26
      static/js/directives/settings.js
  2. 14
      static/js/services/mediastream.js

26
static/js/directives/settings.js

@ -130,22 +130,28 @@ define(['underscore', 'text!partials/settings.html'], function(_, template) {
$scope.registerUserid = function(btn) { $scope.registerUserid = function(btn) {
var successHandler = function(data) {
console.info("Created new userid:", data.userid);
// If the server provided us a nonce, we can do everthing on our own.
mediaStream.users.store(data);
$scope.loadedUserlogin = true;
safeApply($scope);
// Directly authenticate ourselves with the provided nonce.
mediaStream.api.requestAuthentication(data.userid, data.nonce);
delete data.nonce;
};
console.log("No userid - creating one ..."); console.log("No userid - creating one ...");
mediaStream.users.register(btn.form, function(data) { mediaStream.users.register(btn.form, function(data) {
console.info("Created new userid:", data.userid);
if (data.nonce) { if (data.nonce) {
// If the server provided us a nonce, we can do everthing on our own. successHandler(data);
mediaStream.users.store(data);
$scope.loadedUserlogin = true;
safeApply($scope);
// Directly authenticate ourselves with the provided nonce.
mediaStream.api.requestAuthentication(data.userid, data.nonce);
delete data.nonce;
} else { } else {
// No nonce received. So this means something we cannot do on our own. // No nonce received. So this means something we cannot do on our own.
// Make are GET request and retrieve nonce that way and let the // Make are GET request and retrieve nonce that way and let the
// browser/server do the rest. // browser/server do the rest.
// TODO(longsleep): Implement me. mediaStream.users.authorize(data, successHandler, function(data, status) {
console.error("Failed to get nonce after create", status, data);
});
} }
}, function(data, status) { }, function(data, status) {
console.error("Failed to create userid", status, data); console.error("Failed to create userid", status, data);

14
static/js/services/mediastream.js

@ -86,16 +86,18 @@ define([
}, 0); }, 0);
var retries = 0; var retries = 0;
var authorize = function() { var authorize = function() {
mediaStream.users.authorize({}, function(data) { mediaStream.users.authorize({
console.info("Retrieved nonce - authenticating as user:", data.userid); count: retries
mediaStream.api.requestAuthentication(data.userid, data.nonce); }, success_cb, function(data, status) {
delete data.nonce; // Error handler retry.
}, function(data, status) {
retries++; retries++;
if (retries <= 10) { if (retries <= 10) {
$timeout(authorize, 2000); $timeout(authorize, 2000);
} else { } else {
console.error("Failed to authorize session", status, data); console.error("Failed to authorize session", status, data);
if (error_cb) {
error_cb(data, status)
}
} }
}); });
}; };
@ -184,7 +186,7 @@ define([
return null; return null;
}, },
forget: function() { forget: function() {
localStorage.removeItem("mediastream-login"); localStorage.removeItem("mediastream-login-"+context.Cfg.UsersMode);
} }
}, },
initialize: function($rootScope, translation) { initialize: function($rootScope, translation) {

Loading…
Cancel
Save