Missed register.js in last commit

This commit is contained in:
Deon George 2020-07-08 12:48:13 +10:00
parent 44cb7838bb
commit 8b6db8df92

96
load/register.js Normal file
View File

@ -0,0 +1,96 @@
var CONTROL_REGISTER ='1';
var EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var cValChars='ACDEFHJKLMNPQRTUVWXY23456789!@#$%&*';
log(LOG_DEBUG,'Control REGISTER loaded');
function register() {
var code = '';
this.handle=function(read) {
log(LOG_DEBUG,'Control REGISTER handle() start. ('+read+')');
log(LOG_DEBUG,'Field '+cf.fname+'('+JSON.stringify(cf)+')');
if ((cf.fname == 'TOKEN') && (read == '#' || read == '\r')) {
if (cf.fvalue !== code) {
sendBaseline('\1n\1h\1RINVAID CODE, PLEASE TRY AGAIN *00',false);
console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m');
read = '';
}
}
log(LOG_DEBUG,'Field Value '+cf.fvalue+'('+JSON.stringify(code)+')');
return read;
}
// Called before processing for a field
this.prefield=function() {
log(LOG_DEBUG,'Field '+cf.fname+'('+JSON.stringify(cf)+')');
if (cf.fname == 'TOKEN') {
log(LOG_DEBUG,'BASELINE '+cf.fname+'('+JSON.stringify(cf)+')');
sendBaseline('\1n\1h\1RPlease wait, while a token is emailed to you...',false);
var email = fo.fieldValue('EMAIL');
var user = fo.fieldValue('UID');
var name = fo.fieldValue('FULLNAME');
log(LOG_DEBUG,'VALIDATE EMAIL TO ('+system.matchuserdata(U_NETMAIL,email)+')');
// Make sure we got an email
// Validate Email hasnt been used
if ((email.indexOf('@') === -1) || ! EMAIL_REGEX.test(email) || (system.matchuserdata(U_NETMAIL,email) !== 0)) {
sendBaseline('\1n\1h\1RINVAID EMAIL, PLEASE TRY AGAIN *00',false);
return;
}
// Validate USER_ID hasnt been used
if (! system.check_name(user)) {
log(LOG_DEBUG,'Cannot use user_id: ('+user+')');
sendBaseline('\1n\1h\1RINVAID USER ID, PLEASE TRY AGAIN *00',false);
}
var msgbase = new MsgBase('mail');
for (var i=0;i<6;i++)
code+=cValChars.substr(parseInt(Math.random() * cValChars.length), 1);
var hdrs = new Object();
hdrs.to=name;
hdrs.to_net_type=netaddr_type(email);
if (hdrs.to_net_type != NET_NONE) {
hdrs.to_net_addr = email;
} else {
sendBaseline('\1n\1h\1RCANNOT SEND VALIDATION CODE, PLEASE TRY AGAIN *00',false);
return;
}
hdrs.from=system.name;
hdrs.from_net_addr='sysop@'+system.inet_addr;
hdrs.from_net_type=NET_INTERNET;
hdrs.subject='Registration TOKEN for '+system.name;
if (msgbase.open != undefined && msgbase.open() == false) {
console.print("\r\n\1n\1h\1rERROR: \1y" + msgbase.last_error + "\1n \r\n");
console.pause();
msgbase.close();
bbs.hangup();
return;
}
var msg="CODE: " + code + "\n\n";
msg += 'Please use the above code to validate your login to '+system.name+'.';
if (! msgbase.save_msg(hdrs,msg)) {
console.print("\r\n\1n\1h\1rERROR: \1y" + msgbase.last_error + "\1n \r\n");
console.pause();
msgbase.close();
bbs.hangup();
return;
}
msgbase.close();
log(LOG_DEBUG,'SEND EMAIL TO ('+x+')');
}
}
}
this;