function isValidPWord( pword1, pword2 ) { var errormsg = ""; if ( (pword1.length < 3) || (pword1.length > 10) ) errormsg = "badlength"; if (pword1 != pword2) errormsg = "nomatch"; return errormsg; } // END isValidPWord() function initSeeker() { var returnVal = ""; cursor = database.cursor("select * from seeker where userid = '" + request.username + "'", true); /* if we can advance the cursor, then a record with the id the user has chosen already exists, and we cannot allow duplicates. */ if(cursor.next()) redirect("newuser.htm?error=notunique&type=" + request.type); cursor.userID = request.username; if ( (returnVal = isValidPWord(request.password1, request.password2)) == "" ) { cursor.password = request.password1; redirectstr = "profile/seditpro.htm" client.valid = true; client.userID = request.username; client.usertype = request.type; } else // otherwise, an error occured while validating the passwords // we also send back the error and the user type in the URL redirectstr = "newuser.htm?error=" + returnVal + "&type=" + request.type; } // END initSeeker() function initEmployer() { var returnVal = ""; cursor = database.cursor("select * from employer where empid = '" + request.username + "'", true); /* if we can advance the cursor, then a record with the id the user has chosen already exists, and we cannot allow duplicates. */ if(cursor.next()) redirect("newuser.htm?error=notunique&type=" + request.type); cursor.empid = request.username; if ( (returnVal = isValidPWord(request.password1, request.password2)) == "" ) { cursor.password = request.password1; redirectstr = "profile/eeditpro.htm" client.valid = true; client.userID = request.username; client.usertype = request.type; } else // otherwise, an error occured while validating the passwords // we also send back the error and the user type in the URL redirectstr = "newuser.htm?error=" + returnVal + "&type=" + request.type; } // END initEmployer() /* In the following series of if-else statements, we determine which table to insert a new user record into base upon what kind of user they are - a seeker or an employer. We will choose the proper "database.cursor()" statement accordingly. "request.type" should equal the name of the appropriate user type, which is equivalent to the name of the table that the user belongs to. */ // BEGIN Main // Initialize database connection if (!dbCheck()) { redirect("error.htm?error=dbfail"); } if (request.type == "seeker") { initSeeker(); } else { if (request.type == "employer") { initEmployer(); } else { // otherwise, the user has arrived here in some invalid way client.errormsg = "You have tried to access a page out of sequence." redirect("error.htm"); } // END inner if-else } // END outer if-else cursor.insertRow(request.type); cursor.close(); redirect(redirectstr);