Update sqrlogin control to pass through input to main.js, fixes cancel and enables routing away
This commit is contained in:
@@ -24,8 +24,8 @@ function sqrllogin() {
|
||||
var complete = false;
|
||||
var cancel = false;
|
||||
|
||||
log(LOG_DEBUG,'OPTIONS: '+JSON.stringify(loadOptions('sqrl')));
|
||||
var sqrl = loadOptions('sqrl');
|
||||
log(LOG_DEBUG,'OPTIONS: '+JSON.stringify(sqrl));
|
||||
var http = new HTTPRequest();
|
||||
http.SetupGet(sqrl.auth_path,undefined,sqrl.auth_url);
|
||||
http.request_headers.push('Accept: application/json');
|
||||
@@ -48,22 +48,45 @@ function sqrllogin() {
|
||||
// Loop and see if the user has logged in
|
||||
var nut = http.body.substr(http.body.indexOf('nut='),68);
|
||||
|
||||
var read = '';
|
||||
while (read !== '2') {
|
||||
read = console.inkey(K_NONE,1000);
|
||||
} catch (err) {
|
||||
log(LOG_INFO,'SQRL Error: '+err+' '+JSON.stringify(sqrl));
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (read === 2)
|
||||
cancel = true;
|
||||
// Called before processing for a field
|
||||
Object.defineProperty(this, 'getName', {
|
||||
get: function () {
|
||||
return 'SQRL-LOGIN';
|
||||
}
|
||||
});
|
||||
|
||||
http = new HTTPRequest();
|
||||
http.SetupGet(sqrl.auth_post+'?'+nut,undefined,sqrl.auth_url);
|
||||
http.request_headers.push('Accept: application/json');
|
||||
Object.defineProperty(this, 'isComplete', {
|
||||
get: function () {
|
||||
return complete;
|
||||
}
|
||||
});
|
||||
|
||||
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
|
||||
http.SendRequest();
|
||||
http.ReadResponse();
|
||||
// Nothing to do here
|
||||
this.handle=function(read) {
|
||||
log(LOG_DEBUG,'Control SQRL-LOGIN handle() start. ('+read+')');
|
||||
|
||||
switch (http.response_code) {
|
||||
if (read === '2') {
|
||||
log(LOG_INFO,'SQRL: Cancelled with 2');
|
||||
cancel = true;
|
||||
|
||||
} else {
|
||||
log(LOG_DEBUG,'SQRL read ['+read+']');
|
||||
|
||||
try {
|
||||
http = new HTTPRequest();
|
||||
http.SetupGet(sqrl.auth_post+'?'+nut,undefined,sqrl.auth_url);
|
||||
http.request_headers.push('Accept: application/json');
|
||||
|
||||
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
|
||||
http.SendRequest();
|
||||
http.ReadResponse();
|
||||
|
||||
switch (http.response_code) {
|
||||
case 404:
|
||||
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||||
break;
|
||||
@@ -120,7 +143,6 @@ function sqrllogin() {
|
||||
log(LOG_DEBUG,' - SEND TO EXIT:');
|
||||
|
||||
complete = true;
|
||||
read = '2';
|
||||
action = ACTION_EXIT;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
@@ -129,72 +151,52 @@ function sqrllogin() {
|
||||
|
||||
} else {
|
||||
log(LOG_ERROR,'- Login Failed? ');
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
log(LOG_ERROR,'- Unhandled User Details: '+http.response_code);
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
log(LOG_ERROR,'- Unhandled isReady msg: '+result.msg);
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
complete = true;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
|
||||
} else {
|
||||
log(LOG_ERROR,'- Unhandled isReady: '+result.isReady);
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
log(LOG_ERROR,'- Unhandled response code: '+http.response_code);
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
log(LOG_INFO,'SQRL Error: '+err+' '+JSON.stringify(sqrl));
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
complete = true;
|
||||
if (cancel) {
|
||||
log(LOG_INFO,'SQRL: Processing CANCEL ['+read+'].');
|
||||
complete = true;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
|
||||
} catch (err) {
|
||||
log(LOG_INFO,'SQRL Error: '+err+' '+JSON.stringify(sqrl));
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
complete = true;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
action = ACTION_GOTO;
|
||||
next_page = LOGIN_FRAME;
|
||||
}
|
||||
|
||||
// Called before processing for a field
|
||||
Object.defineProperty(this, 'getName', {
|
||||
get: function () {
|
||||
return 'SQRL-LOGIN';
|
||||
action = ACTION_GOTO;
|
||||
next_page = LOGIN_FRAME;
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'isComplete', {
|
||||
get: function () {
|
||||
return complete;
|
||||
}
|
||||
});
|
||||
|
||||
// Nothing to do here
|
||||
this.handle=function(read) {
|
||||
log(LOG_DEBUG,'Control SQRL-LOGIN handle() start. ('+read+')');
|
||||
|
||||
return read;
|
||||
}
|
||||
|
Reference in New Issue
Block a user