Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: siteUpdate Arguments: site,sessionkey,fullname,phone,email,username,origpw,pw,pw2,errCmd,succCmd Description: Registers a new user for a site. OPTIONALARGS contain extra arg1, arg2, ... beyond core data Page type: webl Render function: Module: siteutil Page source: /* not ready */ var err = nil; var data = "NO DATA"; // password checks - must exist origpw if (origpw == nil or Str_Trim(origpw) == "") then err = "ERR_NO_PASSWORD" end; // if new pw, must be valid if (err == nil and Size(pw) > 0 and Size(pw) < 8) then err = "ERR_INVALID_PASSWORD" end; // new pw and confirm pw must be the same if (err == nil and pw != pw2) then err = "ERR_PASSWORD_MISMATCH" end; if (err == nil) then site = Str_Trim(site); fullname = Str_Trim(fullname); phone = Str_Trim(phone); email = Str_Trim(email); username = Str_Trim(username); var db = Wub_GetDB(site); // Check original password origpw = Base64_Encode(username + ":" + origpw); var coll = Wub_GetCollection(db, "login"); var origdbobj = Wub_NewDBObject([. username=username, pw=origpw .]); var res = Wub_QueryDB(coll, origdbobj, 20); if (Size(res) != 1) then err = "ERR_INVALID_PASSWORD" end; if (err == nil and (site == "" or fullname == "" or phone == "" or email == "" or username == "")) then err = "ERR_MISSING_INFO" end; if (err == nil) then if (pw != "") then pw = Base64_Encode(username + ":" + pw); else pw = origpw end; data = [. name=fullname, phone=phone, email=email, username=username, pw=pw .]; // Add optional arguments to data record var count = 0; while (count < Size(OPTIONALARGS)) do data["arg" + ToString(count)] := OPTIONALARGS[count]; count = count + 1 end; // update user's information in login database var dbobj = Wub_NewDBObject(data); Wub_UpdateDB(coll, origdbobj, dbobj, false, false); // Update session table origdbobj = Wub_NewDBObject([. key=sessionkey .]); DeleteField(data, "pw"); coll = Wub_GetCollection(db, "session"); dbobj = Wub_NewDBObject([. key=sessionkey, data=data .]); Wub_UpdateDB(coll, origdbobj, dbobj, false, false); end end; if (err == nil) then WubCall(succCmd, ["SUCCESS", sessionkey]) else WubCall(errCmd, [err, sessionkey]); end;