Work on auth error handling / reinstall

This commit is contained in:
lilia 2015-06-19 15:32:25 -07:00
parent ef8a977f38
commit f126e3b21b
5 changed files with 62 additions and 13 deletions

View file

@ -117,6 +117,12 @@
function onError(ev) {
var e = ev.error;
if (e.name === 'HTTPError' && (e.message == 401 || e.message == 403)) {
extension.install();
return;
}
if (!ev.proto) {
console.log(e);
throw e;

View file

@ -39100,6 +39100,14 @@ TextSecureServer = function () {
return requestVerificationCode(number, 'voice');
};
self.getDevices = function(number) {
return doAjax({
call : 'devices',
httpType : 'GET',
do_auth : true
});
};
self.confirmCode = function(number, code, password,
signaling_key, registrationId, deviceName) {
var call = deviceName ? 'devices' : 'accounts';
@ -39494,8 +39502,21 @@ function generateKeys(count, progressCallback) {
MessageReceiver.prototype = {
constructor: MessageReceiver,
connect: function() {
var eventTarget = this.target;
// initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket();
this.socket.onclose = function(e) {
if (e.code === 1006) {
// possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
if (e.name === 'HTTPError' && (e.message == 401 || e.message == 403)) {
var ev = new Event('error');
ev.error = e;
eventTarget.dispatchEvent(ev);
}
});
}
}
new WebSocketResource(this.socket, this.handleRequest.bind(this));
},

View file

@ -74,20 +74,21 @@
});
$(function() {
if (bg.textsecure.registration.isDone()) {
$('#complete-number').text(bg.textsecure.storage.user.getNumber());
$('#setup-complete').show().addClass('in');
initOptions();
} else {
$('#init-setup').show().addClass('in');
$('#status').text("Connecting...");
$('#init-setup').show().addClass('in');
$('#status').text("Connecting...");
var accountManager = new bg.textsecure.AccountManager();
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
bg.openInbox();
window.close();
});
}
var accountManager = new bg.textsecure.AccountManager();
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
bg.openInbox();
window.close();
}).catch(function(e) {
if (e.name === 'HTTPError' && e.message == 411) {
return; // TODO: too many devices
}
else {
throw e;
}
});
});
});
})();

View file

@ -173,6 +173,14 @@ TextSecureServer = function () {
return requestVerificationCode(number, 'voice');
};
self.getDevices = function(number) {
return doAjax({
call : 'devices',
httpType : 'GET',
do_auth : true
});
};
self.confirmCode = function(number, code, password,
signaling_key, registrationId, deviceName) {
var call = deviceName ? 'devices' : 'accounts';

View file

@ -30,8 +30,21 @@
MessageReceiver.prototype = {
constructor: MessageReceiver,
connect: function() {
var eventTarget = this.target;
// initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket();
this.socket.onclose = function(e) {
if (e.code === 1006) {
// possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
if (e.name === 'HTTPError' && (e.message == 401 || e.message == 403)) {
var ev = new Event('error');
ev.error = e;
eventTarget.dispatchEvent(ev);
}
});
}
}
new WebSocketResource(this.socket, this.handleRequest.bind(this));
},