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) { @@ -130,22 +130,28 @@ define(['underscore', 'text!partials/settings.html'], function(_, template) {
$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 ...");
mediaStream.users.register(btn.form, function(data) {
console.info("Created new userid:", data.userid);
if (data.nonce) {
// 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;
successHandler(data);
} else {
// 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.
// 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) {
console.error("Failed to create userid", status, data);

14
static/js/services/mediastream.js

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

Loading…
Cancel
Save