176 lines
3.7 KiB
JavaScript
176 lines
3.7 KiB
JavaScript
|
/**
|
||
|
* This handles user registration.
|
||
|
*
|
||
|
* The form must have the following fields:
|
||
|
* + UID The user's user id to login
|
||
|
* + EMAIL The users's email address - to receive tokens
|
||
|
* + FULLNAME The user's full name
|
||
|
* + PASS The users's preferred password
|
||
|
* + CITY The user's city
|
||
|
* + COUNTRY The user's country - 3 letter ISO code
|
||
|
* + PCODE THe user's postal code
|
||
|
*/
|
||
|
|
||
|
var CONTROL_SQRL = '1';
|
||
|
|
||
|
require('http.js','HTTPRequest');
|
||
|
load('ansitex/load/qrcode-make.js');
|
||
|
load('frame.js');
|
||
|
|
||
|
log(LOG_DEBUG,'+ Control SQRL-LOGIN loaded');
|
||
|
|
||
|
function sqrllogin() {
|
||
|
var complete = false;
|
||
|
var cancel = false;
|
||
|
|
||
|
var page = new Frame(1,2,80,22,BG_BLACK|LIGHTGRAY);
|
||
|
|
||
|
page.gotoxy(1,1);
|
||
|
ans2bin(fo.parse(base64_decode(fo.content)),page);
|
||
|
page.open();
|
||
|
page.cycle();
|
||
|
|
||
|
http = new HTTPRequest();
|
||
|
http.SetupGet('/sqrl/login',undefined,'http://ansitex.leenooks.net');
|
||
|
http.request_headers.push('Accept: application/json');
|
||
|
|
||
|
try {
|
||
|
http.SendRequest();
|
||
|
http.ReadResponse();
|
||
|
log(LOG_INFO,'SQRL: '+JSON.stringify(http.body));
|
||
|
|
||
|
} catch(err) {
|
||
|
log(LOG_INFO, "http error: " + err);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
var data = http.body
|
||
|
.split('')
|
||
|
.map(function(x) {return x.charCodeAt(0)});
|
||
|
var qr = qrcodegen.QrCode.encodeBinary(data, qrcodegen.QrCode.Ecc.LOW);
|
||
|
|
||
|
// SMALL Image
|
||
|
var full = ascii(0xdb);
|
||
|
var top = ascii(0xdf);
|
||
|
var bot = ascii(0xdc);
|
||
|
var blank = ' ';
|
||
|
|
||
|
var qrcode = '';
|
||
|
|
||
|
// Render the top line
|
||
|
var line = ascii(27)+'[1;37m'+bot+bot;
|
||
|
for (var y = 0; y < qr.size; y++) {
|
||
|
line += bot;
|
||
|
}
|
||
|
qrcode += line+bot+bot+ascii(27)+'[0m'+"\r\n";
|
||
|
|
||
|
// Render the body
|
||
|
for (var x = -1; x < qr.size; x=x+2) {
|
||
|
line = ascii(27)+'[1;37m'+full+full;
|
||
|
|
||
|
for (var y = 0; y < qr.size; y++) {
|
||
|
// Top is white
|
||
|
if (((x==-1)? 0 : qr.getModule(x, y)) == 0) {
|
||
|
line += (qr.getModule(x+1, y)) ? top : full;
|
||
|
|
||
|
// Top is black
|
||
|
} else {
|
||
|
line += (qr.getModule(x+1, y)) ? blank : bot;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
qrcode += line+full+full+ascii(27)+'[0m'+"\r\n";
|
||
|
}
|
||
|
|
||
|
// Render the bottom
|
||
|
line = ascii(27)+'[1;37m'+full+full;
|
||
|
for (var y = 0; y < qr.size; y++) {
|
||
|
line += full;
|
||
|
}
|
||
|
qrcode += line+full+full+ascii(27)+'[0m'+"\r\n";
|
||
|
|
||
|
subframe = new Frame(39,2,42,22,BG_BLACK|LIGHTGRAY,page);
|
||
|
ans2bin(fo.parse(qrcode),subframe);
|
||
|
subframe.open();
|
||
|
subframe.cycle();
|
||
|
|
||
|
fo.sendBaseline('CANCEL_MSG',false);
|
||
|
|
||
|
// Loop and see if the user has logged in
|
||
|
nut = http.body.substr(http.body.indexOf('nut='),68);
|
||
|
|
||
|
var read = '';
|
||
|
while (read !== '2') {
|
||
|
read = console.inkey(K_NONE,1000);
|
||
|
|
||
|
if (read == 2)
|
||
|
cancel = true;
|
||
|
|
||
|
http = new HTTPRequest();
|
||
|
http.SetupGet('/api/sqrl?'+nut,undefined,'http://ansitex.leenooks.net');
|
||
|
http.request_headers.push('Accept: application/json');
|
||
|
|
||
|
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
|
||
|
http.SendRequest();
|
||
|
http.ReadResponse();
|
||
|
|
||
|
if (http.response_code == 404) {
|
||
|
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||
|
|
||
|
} else {
|
||
|
log(LOG_INFO,'NUT: ('+JSON.stringify(http.response_code)+'): '+JSON.stringify(http.body));
|
||
|
|
||
|
//@todo
|
||
|
action = ACTION_GOTO;
|
||
|
next_page = { frame: 98,index: 'a' };
|
||
|
|
||
|
complete = true;
|
||
|
subframe.close();
|
||
|
page.close();
|
||
|
|
||
|
// We are done
|
||
|
read = '2';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (cancel) {
|
||
|
complete = true;
|
||
|
subframe.close();
|
||
|
page.close();
|
||
|
action = ACTION_GOTO;
|
||
|
next_page = { frame: 98,index: 'a' };
|
||
|
}
|
||
|
|
||
|
// Called before processing for a field
|
||
|
Object.defineProperty(this, 'getName', {
|
||
|
get: function () {
|
||
|
return 'SQRL-LOGIN';
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
this.prefield=function() {
|
||
|
|
||
|
}
|
||
|
|
||
|
this.process=function() {
|
||
|
subframe.close();
|
||
|
frame.close();
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
this;
|