Advertisement
Guest User

Untitled

a guest
May 7th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.06 KB | None | 0 0
  1. --begin--
  2.  
  3. /*****************************************************************************
  4.                        Synchronet 3 Create New User Module
  5. ------------------------------------------------------------------------------
  6. FILE NAME : create_new_user.js
  7. CREATED BY: Michael J. Ryan (tracker1[at]theroughnecks.net)
  8. CREATED ON: 2003-01-07
  9. ------------------------------------------------------------------------------
  10. This file requires Synchronet v3.10g or newer.
  11.  
  12. This module will walk through a new user creation, and will email the password
  13. to the user, instead of prompting for it... (telnet validation).
  14.  
  15. to use in your login.js
  16. bbs.newuser = new Function("bbs.exec('?create_new_user.js');return false;");
  17.  
  18. for login.baja .. make sure to *NOT* login/on the user
  19. exec "?create_new_user.js"
  20.  
  21.  
  22. Changes by Merlin to stop it creating a temp user, only make it save to user
  23. database when the entries are all done. It also fixes the bug that stops
  24. users with a single username alias not being able to log on.
  25.  
  26. Also changed the password message.
  27.  
  28. misc changes by -oblivious-, nothing special
  29.  
  30. *****************************************************************************/
  31. load("sbbsdefs.js");
  32. load("inc_dates.js");
  33.  
  34. // Global user object, to store information, status set to deleted.
  35. newinfo = {}; //to temporarily store new user info.
  36.  
  37. //checks for an existing user with the value given
  38. //   ex. checkForUser("alias","myUsername");
  39. function checkForUser(info,value) {
  40.     var oUser = new User(0);
  41.     for (var i=1; i<=system.stats.total_users; i++) {
  42.         oUser.number = i;
  43.        
  44.         if (!(oUser.settings&USER_DELETED)) {
  45.             var info_chk = eval("oUser."+info);
  46.             if (info_chk.replace(/\W/g,"").toLowerCase() == value.replace(/\W/g,"").toLowerCase())
  47.                 return true;
  48.         }
  49.     }
  50.     return false;
  51. }
  52. //get the alias/username
  53. function getAlias() {
  54.     if (!newinfo.alias)
  55.          newinfo.alias = "";
  56.    
  57.     while(bbs.online) {
  58.         console.print(bbs.text(338));
  59.          newinfo.alias = console.getstr( newinfo.alias,25,K_UPRLWR|K_LINE|K_EDIT)
  60.         if ( newinfo.alias == "") {
  61.             if (!console.noyes("Abort new user creation")) {
  62.                  newinfo.abort = true;
  63.                 return;
  64.             }
  65.         } else if (!newinfo.alias.match(/^[a-z][\w\.\_' -]{1,}$/i))
  66.             console.print("\1n    Must begin with a letter, and contain only letters, numbers and spaces.\1n\r\n\r\n");
  67.         else if (checkForUser("alias", newinfo.alias))
  68.             console.print("\1n    A user with that name already exists.\1n\r\n\r\n");
  69.         else
  70.             return;
  71.     }
  72. }
  73.  
  74. function getHandle() {
  75.     if (! newinfo.handle)
  76.          newinfo.handle =  newinfo.alias.substr(0,8);
  77.     var save = false;
  78.    
  79.     while(bbs.online && !save) {
  80.         console.print(bbs.text(341));
  81.          newinfo.handle = console.getstr(newinfo.handle,8,K_LINE|K_EDIT)
  82.         if (newinfo.handle == "") {
  83.             if (!console.noyes("Abort new user creation")) {
  84.                 newinfo.abort = true;
  85.                 return;
  86.             }
  87.         } else if (!newinfo.handle.match(/^[a-z][\w ]{2,}$/i))
  88.             console.print("\1n    Must begin with a letter, and contain only letters, numbers and spaces.\1n\r\n\r\n");
  89.         else if (checkForUser("handle",newinfo.handle))
  90.             console.print("\1n    A user with that chat handle already exists.\1n\r\n\r\n");
  91.         else
  92.             save = true;
  93.     }
  94. }
  95.  
  96. function getName() {
  97.     if (!newinfo.name)
  98.         newinfo.name = "";
  99.     var save = false;
  100.    
  101.     while (bbs.online && !save) {
  102.         console.print(bbs.text(339));
  103.         newinfo.name = console.getstr(newinfo.name,25,K_LINE|K_EDIT|K_UPRLWR)
  104.         if (newinfo.name == "") {
  105.             if (!console.noyes("Abort new user creation")) {
  106.                 newinfo.abort = true;
  107.                 return;
  108.             }
  109.         } else if (!newinfo.name.match(/^[a-z][a-z-]+ [a-z][a-z\.\_' -]*$/i))
  110.             console.print("\1n    First and Last name, only letters, spaces, and \"'.-\".\1n\r\n\r\n");
  111.         else if (checkForUser("name",newinfo.name))
  112.             console.print("\1n    A user with that name already exists.\1n\r\n\r\n");
  113.         else
  114.             save = true;
  115.     }
  116. }
  117.  
  118. function getDOB() {
  119.     var now = new Date();
  120.    
  121.     if (!newinfo.dob)
  122.         newinfo.dob = now.formatDate("yyyy-mm-dd");
  123.    
  124.     var y = parseInt(newinfo.dob.split("-")[0]);
  125.     var m = parseInt(newinfo.dob.split("-")[1]);
  126.     var d = parseInt(newinfo.dob.split("-")[1]);
  127.     var this_year = parseInt(now.formatDate("yyyy"));
  128.    
  129.         console.print("\1h\1w Enter your date of birth:");
  130.     do {
  131.         console.print("\1n    Year : ");
  132.         y = console.getstr(y.toString(),4,K_LINE|K_EDIT|K_NUMBER|K_AUTODEL);
  133.         y = (isNaN(y))?1900:parseInt(y);
  134.         if (y<=1900 || y>=this_year)
  135.                         console.print("\1h\1w    Enter a full year (ex. 1975).\1n\r\n");
  136.     } while (bbs.online && (y<1900 || y>=this_year));
  137.  
  138.     do {
  139.                 console.print("\1h\1w  Month: ");
  140.         m = console.getstr(m.toString(),2,K_LINE|K_EDIT|K_NUMBER|K_AUTODEL);
  141.         m = (isNaN(m))?0:parseInt(m);
  142.         if (m<1 || m>12)
  143.             console.print("\1n    Enter a numeric month (1-12).\1n\r\n");
  144.     } while (bbs.online && (m<1 || m>12));
  145.    
  146.     var max_d = (new Date(y,m,0,0,0,0,0)).formatDate("d");
  147.     do {
  148.                 console.print("\1h\1w  Day  : ");
  149.         d = console.getstr(d.toString(),2,K_LINE|K_EDIT|K_NUMBER|K_AUTODEL);
  150.         d = (isNaN(d))?0:parseInt(d);
  151.         if (d<1 || d>max_d)
  152.             console.print("\1n    Enter a numeric day (1-"+max_d+").\1n\r\n");
  153.     } while (bbs.online && (d<1 || d>max_d));
  154.        
  155.     newinfo.dob = (new Date(y,m-1,d,0,0,0,0)).formatDate("yyyy-mm-dd");
  156. }
  157.  
  158. function getGender() {
  159.     console.print(bbs.text(342))
  160.     newinfo.gender = console.getkeys("MF");
  161. }
  162.  
  163. function getLocation() {
  164.     if (!newinfo.location)
  165.         newinfo.location = "";
  166.    
  167.     do {
  168.         console.print(""+bbs.text(346));
  169.         newinfo.location = console.getstr(newinfo.location,30,K_LINE|K_EDIT|K_NOEXASC|K_UPRLWR);
  170.        
  171.         if (newinfo.location == "") {
  172.             if (!console.noyes("Abort new user creation")) {
  173.                 newinfo.abort = true;
  174.                 return;
  175.             }
  176.         } else
  177.             return;
  178.     } while (bbs.online && !newinfo.location);
  179. }
  180.  
  181. function getEmail() {
  182.     if (!newinfo.email)
  183.         newinfo.email = "";
  184.        
  185.     while (bbs.online) {
  186.                 console.print("\1n\1h\r\1>\1h\1w[\1\1h\1w] \1n\1rPlease enter your email address:\r\n    \1n")
  187.         newinfo.email = console.getstr(newinfo.email,60,K_LINE|K_EDIT).toLowerCase();
  188.        
  189.         if (newinfo.email.match(/^[a-z0-9][\w\.\_-]*@[a-z0-9][\w\.\_-]+\.[a-z]{2,7}$/)) {
  190.                         console.print("\1n\1h\r\1>\1h\1w[\1\1h\1w] \1n\1rPlease confirm your email address:\r\n    \1n")
  191.             if (console.getstr("",60,K_LINE|K_EDIT).toLowerCase() == newinfo.email) {
  192.                 if (system.settings&SYS_FWDTONET)
  193.                     newinfo.emailforward = console.yesno("\r\n"+bbs.text(499));
  194.                 else
  195.                     newinfo.emailforward = false;
  196.                 return;
  197.             } else
  198.                 console.print("    Email addresses don't match.\1n\r\n\r\n");
  199.         } else
  200.             console.print("    Please enter a VALID email address.\r\n\r\n");
  201.     }
  202. }
  203.  
  204. function saveNewUser(pwd) {
  205.     var usr = system.new_user(newinfo.alias);
  206.     usr.alias = newinfo.alias;
  207.     usr.handle = newinfo.handle;
  208.     usr.name = newinfo.name;
  209.    
  210.     var dob = newinfo.dob.split("-");
  211.     dob = new Date(dob[0],dob[1]-1,dob[2],0,0,0,0)
  212.     if (system.settings&SYS_EURODATE)
  213.                 usr.birthdate = dob.formatDate("dd/mm/yy");
  214.     else
  215.                 usr.birthdate = dob.formatDate("mm/dd/yy");
  216.  
  217.         usr.gender = newinfo.gender;
  218.         usr.location = newinfo.location;
  219.  
  220.  
  221.     usr.security.password=pwd; 
  222.  
  223.         usr.netmail = newinfo.email
  224.     if (newinfo.emailforward)
  225.                 usr.settings |= USER_NETMAIL;
  226.     else
  227.                 usr.settings &= ~USER_NETMAIL;
  228.    
  229.     usr.settings |= USER_AUTOTERM;
  230.  
  231.     console.print("\1nSaved #"+ usr.number + " " + usr.alias + "\r\n");
  232.     log("Saved #"+ usr.number + " " + usr.alias);
  233. }
  234.  
  235. function sendPassword(pwd) {
  236.     var mail = new MsgBase("mail");
  237.     if(mail.open!=undefined && mail.open()==false) {
  238.         var err_msg = "!ERROR " + msgbase.last_error;
  239.         console.print(err_msg);
  240.         log(err_msg);
  241.         exit();
  242.     }
  243.    
  244.     var hdr = {
  245.         from:system.name,
  246.         from_net_addr:"sysop"+system.inetaddr,
  247.         to:newinfo.alias,
  248.         to_net_addr:newinfo.email,
  249.                
  250.  
  251. subject:"Your password for " + system.name + "!",
  252.         to_net_type:NET_INTERNET
  253.         }
  254.        
  255.     var msg = "" +
  256.         "Welcome to "+system.name+"!\r\n"+
  257.         "\r\n"+
  258.         "You have received this email because someone logged on as a new user\r\n" +
  259.         "and entered this email address for verification.\r\n" +
  260.         "\r\n" +
  261.         "You now need to reconnect to "+system.name+" and log on using the following:\r\n\r\n"+
  262.         "USERNAME: "+newinfo.alias+"\r\n" +
  263.         "PASSWORD: "+pwd+"\r\n\r\n"+
  264.         "\r\n"+
  265.         "telnet://"+system.inetaddr+"\r\n";
  266.        
  267.     if (!mail.save_msg(hdr,msg)) {
  268.         var err_msg = "!ERROR " + msgbase.last_error + " saving mail.";
  269.         console.print(err_msg);
  270.         log(err_msg);
  271.         exit();
  272.     }
  273.  
  274.     hdr = {
  275.         to: 'sysop',
  276.         to_ext: '1',
  277.         from: system.name,
  278. // edit this line        
  279.         subject: "New User Information"
  280.         };
  281.    
  282.     msg = "" +
  283.         "Alias         : "+newinfo.alias+"\r\n" +
  284.         "Real name     : "+newinfo.name+"\r\n" +
  285.         "Chat handle   : "+newinfo.handle+"\r\n" +
  286.         "Location      : "+newinfo.location+"\r\n" +
  287.         "Gender        : "+((newinfo.gender=="F")?"Female":"Male")+"\r\n" +
  288.         "Date of birth : "+newinfo.dob+"\r\n" +
  289.         "Email         : "+newinfo.email+((newinfo.emailforward)?" (forwarded)":"")+"\r\n";
  290.     mail.save_msg(hdr,msg);
  291.  
  292. // edit this line
  293.         console.print("\1nYour password (which you can change later)\r\n has been sent to \1h\1w"+newinfo.email+"\n\r\nIF YOU DON'T GET A EMAIL INSTANTLY, EMAIL ME AT [put email address here]\r\n, it may not have gone through.");
  294.     log("Password sent to " + newinfo.alias + " at " + newinfo.email);
  295. }
  296.  
  297.  
  298. function showInfo() {
  299.     console.print("\r\n\r\n");
  300.         console.print("\1h\1h\1wAlias         \1k: \1n"+newinfo.alias+"\r\n");
  301.         console.print("\1h\1h\1wReal name     \1k: \1n"+newinfo.name+"\r\n");
  302.         console.print("\1h\1h\1wChat handle   \1k: \1n"+newinfo.handle+"\r\n");
  303.         console.print("\1h\1h\1wLocation      \1k: \1n"+newinfo.location+"\r\n");
  304.         console.print("\1h\1h\1wGender        \1k: \1n"+((newinfo.gender=="F")?"Female":"Male")+"\r\n");
  305.         console.print("\1h\1h\1wDate of birth \1k: \1n"+newinfo.dob+"\r\n");
  306.         console.print("\1h\1h\1wEmail         \1k: \1n"+newinfo.email+((newinfo.emailforward)?" (forwarded)":"")+"\r\n");
  307.     console.print("\r\n");
  308. }
  309.  
  310. function main() {
  311.     bbs.user_event(EVENT_NEWUSER);
  312.     system.node_list[bbs.node_num-1].status = NODE_NEWUSER;
  313.     newinfo.saved = false;
  314.     newinfo.abort = false;
  315.        
  316.     while (bbs.online && !(newinfo.abort||newinfo.saved)) {
  317.         if (!newinfo.abort) getAlias();
  318.         if (!newinfo.abort) getHandle();
  319.         if (!newinfo.abort) getName();
  320.         if (!newinfo.abort) getLocation();
  321.         if (!newinfo.abort) getGender();
  322.         if (!newinfo.abort) getDOB();
  323.         if (!newinfo.abort) getEmail();
  324.        
  325.         if (newinfo.abort)
  326.             console.print("\r\n\r\n\1h\1rAborted.\1n\r\n\r\n");
  327.         else if (newinfo.email) {
  328.             showInfo();
  329.             if (console.yesno("Is this information correct (password will be emailed)")) {
  330.                 console.print("\1n");
  331.                 var passwd = parseInt(Math.random()*1000000).toString(36).toUpperCase().substr(0,8);
  332.                 saveNewUser(passwd);
  333.                 sendPassword(passwd);
  334.                 return;
  335.             } else if (!console.noyes("Abort new user creation")) {
  336.                 return;
  337.             }
  338.         }
  339.     }
  340. }
  341. main();
  342. console.pause();
  343.  
  344.  
  345. --end--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement