Work on auth error handling / reinstall
This commit is contained in:
parent
ef8a977f38
commit
f126e3b21b
5 changed files with 62 additions and 13 deletions
|
@ -117,6 +117,12 @@
|
||||||
|
|
||||||
function onError(ev) {
|
function onError(ev) {
|
||||||
var e = ev.error;
|
var e = ev.error;
|
||||||
|
|
||||||
|
if (e.name === 'HTTPError' && (e.message == 401 || e.message == 403)) {
|
||||||
|
extension.install();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ev.proto) {
|
if (!ev.proto) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -39100,6 +39100,14 @@ TextSecureServer = function () {
|
||||||
return requestVerificationCode(number, 'voice');
|
return requestVerificationCode(number, 'voice');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.getDevices = function(number) {
|
||||||
|
return doAjax({
|
||||||
|
call : 'devices',
|
||||||
|
httpType : 'GET',
|
||||||
|
do_auth : true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.confirmCode = function(number, code, password,
|
self.confirmCode = function(number, code, password,
|
||||||
signaling_key, registrationId, deviceName) {
|
signaling_key, registrationId, deviceName) {
|
||||||
var call = deviceName ? 'devices' : 'accounts';
|
var call = deviceName ? 'devices' : 'accounts';
|
||||||
|
@ -39494,8 +39502,21 @@ function generateKeys(count, progressCallback) {
|
||||||
MessageReceiver.prototype = {
|
MessageReceiver.prototype = {
|
||||||
constructor: MessageReceiver,
|
constructor: MessageReceiver,
|
||||||
connect: function() {
|
connect: function() {
|
||||||
|
var eventTarget = this.target;
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
this.socket = TextSecureServer.getMessageWebsocket();
|
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));
|
new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||||
},
|
},
|
||||||
|
|
|
@ -74,20 +74,21 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
if (bg.textsecure.registration.isDone()) {
|
$('#init-setup').show().addClass('in');
|
||||||
$('#complete-number').text(bg.textsecure.storage.user.getNumber());
|
$('#status').text("Connecting...");
|
||||||
$('#setup-complete').show().addClass('in');
|
|
||||||
initOptions();
|
|
||||||
} else {
|
|
||||||
$('#init-setup').show().addClass('in');
|
|
||||||
$('#status').text("Connecting...");
|
|
||||||
|
|
||||||
var accountManager = new bg.textsecure.AccountManager();
|
var accountManager = new bg.textsecure.AccountManager();
|
||||||
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
|
accountManager.registerSecondDevice(setProvisioningUrl, confirmNumber, incrementCounter).then(function() {
|
||||||
bg.openInbox();
|
bg.openInbox();
|
||||||
window.close();
|
window.close();
|
||||||
});
|
}).catch(function(e) {
|
||||||
}
|
if (e.name === 'HTTPError' && e.message == 411) {
|
||||||
|
return; // TODO: too many devices
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -173,6 +173,14 @@ TextSecureServer = function () {
|
||||||
return requestVerificationCode(number, 'voice');
|
return requestVerificationCode(number, 'voice');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.getDevices = function(number) {
|
||||||
|
return doAjax({
|
||||||
|
call : 'devices',
|
||||||
|
httpType : 'GET',
|
||||||
|
do_auth : true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.confirmCode = function(number, code, password,
|
self.confirmCode = function(number, code, password,
|
||||||
signaling_key, registrationId, deviceName) {
|
signaling_key, registrationId, deviceName) {
|
||||||
var call = deviceName ? 'devices' : 'accounts';
|
var call = deviceName ? 'devices' : 'accounts';
|
||||||
|
|
|
@ -30,8 +30,21 @@
|
||||||
MessageReceiver.prototype = {
|
MessageReceiver.prototype = {
|
||||||
constructor: MessageReceiver,
|
constructor: MessageReceiver,
|
||||||
connect: function() {
|
connect: function() {
|
||||||
|
var eventTarget = this.target;
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
this.socket = TextSecureServer.getMessageWebsocket();
|
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));
|
new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue