/** * 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; fo.render(); log(LOG_DEBUG,'OPTIONS: '+JSON.stringify(loadOptions('sqrl'))); sqrl = loadOptions('sqrl'); http = new HTTPRequest(); http.SetupGet(sqrl.auth_path,undefined,sqrl.auth_url); http.request_headers.push('Accept: application/json'); try { http.SendRequest(); http.ReadResponse(); log(LOG_INFO,'SQRL: '+JSON.stringify(http.body)); var data = http.body .split('') .map(function(x) {return x.charCodeAt(0)}); var qr = qrcodegen.QrCode.encodeBinary(data,qrcodegen.QrCode.Ecc.LOW); subframe = new Frame(38,2,43,22,BG_BLACK|LIGHTGRAY); fo.qrcode(qr,subframe); 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(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; case 200: if (http.body.isReady) { log(LOG_INFO,'NUT: '+http.body.msg); log(LOG_INFO,'NEXT: '+http.body.nextPage); complete = true; if (typeof subframe === 'object') subframe.close(); // We are done read = '2'; } else { log(LOG_ERROR,'- Unhandled isReady: '+http.body.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; } if (cancel) { complete = true; if (typeof subframe === 'object') subframe.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;