generator.init().then(function () { var idxFirst, idxSecond, idxThird; should.exist(generator.siteMapContent); // TODO: We should validate the contents against the XSD: // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/100</loc>').should.equal(true); validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/200</loc>').should.equal(true); validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/300</loc>').should.equal(true); // Validate order newest to oldest idxFirst = generator.siteMapContent.indexOf('<loc>http://my-ghost-blog.com/url/300</loc>'); idxSecond = generator.siteMapContent.indexOf('<loc>http://my-ghost-blog.com/url/200</loc>'); idxThird = generator.siteMapContent.indexOf('<loc>http://my-ghost-blog.com/url/100</loc>'); idxFirst.should.be.below(idxSecond); idxSecond.should.be.below(idxThird); done(); }).catch(done);
generator.init().then(function () { should.exist(generator.siteMapContent); // TODO: We should validate the contents against the XSD: // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/100</loc>').should.equal(true); validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/200</loc>').should.equal(true); validator.contains(generator.siteMapContent, '<loc>http://my-ghost-blog.com/url/300</loc>').should.equal(true); done(); }).catch(done);
generator.init().then(function () { should.exist(generator.siteMapContent); validator.contains(generator.siteMapContent, '<loc>').should.equal(false); done(); }).catch(done);
* contains(field, value, inString, message){ if(typeof inString !== "string"){ this.validator.addError(field, 'rule', 'contains', 'The number of arguements provided is invalid. Please provide one single string'); return false; }else{ if(!v.contains(value, inString)){ if(message){ message.replace(':substring', inString); } this.validator.addError(field, 'rule', 'contains', message || 'The value of the field can only contain letters and numbers'); return false; } } return true; }
setUserSyncUrl: function(urlTemplate, callback) { if (!validator.contains(urlTemplate, '{id}')) { return null; } callback = callback || function(data, response) { if (response.statusCode == 204) { console.log('livefyre.network.setUserSyncUrl succeeded.'); } else { console.log('livefyre.network.setUserSyncUrl failed.'); } } rest.post(util.format('http://%s', this.networkName), { data: { actor_token: this.buildLivefyreToken(), pull_profile_url: urlTemplate }, }).on('complete', callback); return this; },
return this.setRequirement((val) => validator.contains(val, needle), formatValidationMessage(message, {needle}), `contains ${needle}`);
NANA.prototype.isContain = function isContain(seed) { if (!this.flag) return this; this.flag = validator.contains(this._curArgs, seed); return this; };
check.notContains = function(str, s){ return !validator.contains(str, s); };
Validator.prototype.notContains = function(s, tip) { if (this.goOn && (!isString(this.value) ||v.contains(this.value,s))) { this.addError(tip || this.key + " is must not contain " + s + "."); } return this; };
Validator.contains = (value, str) => { return !value || validator.contains(value, str); };
validate: (val) => validator.contains(val, seed)
compatibleValidator.notContains = function(str, elem) { return !validator.contains(str, elem); };
val.forEach(function (el) { validator.contains(el.route, '/'); validator.isNull(el.dir) });
'notContains': function (x, str) { return !validator.contains(x, str); },
return function (field, value, msg) { if (!validator.contains(value, snippet)) { return new _error.ConformaValidationError(field, msg || 'snippet.not.found.in.value', value); } }
exports.postSignUp = function* (next) { var ctx = this; var body = ctx.request.body; // Sanitize input body.email = v.trim(body.email).toLowerCase(); if (!v.isNull(body.fullname)) { body.fullname = v.trim(body.fullname); } body.orgName = v.trim(body.orgName).toLowerCase(); // Validate var errors = []; //full name is optinal field if(!v.isNull(body.fullname)){ if (!v.isLength(body.fullname, 2)) { errors.push(['fullname', 'Full name must be at least 2 characters long']); }else if(!v.isLength(body.fullname, 2, 31)){ errors.push(['fullname', 'Full name can\'t be longer than 31 characters']); }else if (!/^[a-zA-Z0-9]+[ ]*[a-zA-Z0-9]+$/.test(body.fullname)) { errors.push(['fullname', 'Use only letters, numbers for fullname and space as separator']); } } if (v.isNull(body.email)) { errors.push(['email', 'required']); } else if (!v.isEmail(body.email)) { errors.push(['email', 'Invalid email address']); } if (v.isNull(body.password)) { errors.push(['password', 'required']); } else if (!v.isLength(body.password, 8)) { errors.push(['password', 'Password must be at least 8 characters long']); } if (v.isNull(body.orgName)) { errors.push(['orgName', 'required']); } else if (!/^[a-zA-Z0-9\-\_]+$/.test(body.orgName)) { errors.push(['orgName', 'Use only letters, numbers, \'-\', \'_\'']); } if (errors.length > 0) { delete body.password; ctx.flash = _.defaults({ errors: _.zipObject(errors) }, body); return ctx.redirect('/'); } try { yield User.createOwner(body); var successMessage = 'We have sent you an email for verification to ' + body.email + '. Please click on the link in the email to continue.'; ctx.flash = { success: successMessage }; } catch (error) { if (v.contains(error.message, 'E11000')) { if (v.contains(error.message, 'organizations.$name')) { errors.push(['orgName', 'Duplicate organization name']); } else if (v.contains(error.message, 'users.$email')) { errors.push(['email', 'Duplicate email address']); } } else { log.error(error); errors.push(['error', 'Unknown error occurred. Please contact support.']); } if (errors.length > 0) { delete body.password; ctx.flash = _.defaults({ errors: _.zipObject(errors) }, body); return ctx.redirect('/'); } } ctx.redirect('/signin'); };
app.post('/tooltoclient', function(req, res) { var pendingCB = -1; var requestCount = 0; var errormsg; var ToolGroupName = ""; if (req.session.userAuth == true) { var csrfBodyToken = req.body.csrf; var cookieArray = req.headers.cookie.split(";"); var csrfCookie = ""; for (var i = 0; i < cookieArray.length; i++) { var tempArr = cookieArray[i].split("csrfToken="); if (tempArr.length == 2) { csrfCookie = tempArr[1]; } } if (csrfBodyToken == csrfCookie) { var toolid = req.body.toolid; var clientList = req.body.clientid; var numIds = 1; console.log("clientid = " + clientList); console.log("toolid = " + toolid); console.log("All client ids :" + req.session.userClients); if (clientList == "all") { clientList = req.session.userClients; } // validate client ids from the list and count valid clients ############################################### var array = clientList.toString().split(","); var numclientIds = array.length; var numValidclientIds = numclientIds; for (i = 0; i < numclientIds; i++) { // validate scan id var clientid = array[i]; if ((!validator.isNumeric(clientid)) || (clientid <= 0)) { console.log("Invalid client ID: " + clientid); array.splice(i, 1); --numValidclientIds; // one less call back with report expected } } // determine the number of valid scan IDs console.log("Number of Valid launchers : " + numValidclientIds); /* For toolid is more than one */ // validate tool ids from the list and count valid tools ############################################### var numToolid = 1; var numValidToolid = 1; var arraytoolid = toolid; if (validator.contains(toolid, '/')) { var data = toolid.toString().split("/"); console.log("Data of toolGroup: " + data); var ToolGroupName = data[0]; var toolid = data[1]; console.log("ToolGroupNAme in upload :" + ToolGroupName); } // if close var arraytoolid = toolid.toString().split(","); var numToolid = arraytoolid.length; var numValidToolid = numToolid; console.log("Tools for in toolGroup:" + toolid); for (i = 0; i < numToolid; i++) { // validate scan id var toolid = arraytoolid[i]; if (!validator.isAlphanumeric(toolid)) { console.log("Invalid Tool ID: " + toolid); arraytoolid.splice(i, 1); --numValidToolid; // one less call back with report expected } } // determine the number of valid scan IDs console.log("Number of Valid Toolids : " + numValidToolid); pendingCB = numValidclientIds * numValidToolid; // Making this many request and expecting so many call backs if (pendingCB <= 0) { res.send("No valid clients or no valid tool ids: Nothing to do"); } else { errormsg = ""; for (var j = 0; j < numToolid; j++) { // index is one less so i< numToolid var toolid = arraytoolid[j]; if (!validator.isAlphanumeric(toolid)) { continue; } // else pick next tool for (var i = 0; i < numclientIds; i++) { //index is one less, so i<numScanIds // validate client id var clientid = array[i]; if ((!validator.isNumeric(clientid)) || (clientid <= 0)) { continue; } // else pick next client // Push this tool to this client var body = { "clientID": clientid, "toolID": toolid }; var headers = { 'Content-Type': 'application/json' } var options = { url: "http://" + config.serverIP + ":" + config.serverPort + "/admin/pushtoolclient/", headers: headers, method: "POST", body: JSON.stringify(body) } request(options, function(error, response, body) { --pendingCB; console.log("One more call back done to push tool to client : " + pendingCB + "still to go"); if (error || (body == "error")) { console.log("ERROR :" + error); errormsg = errormsg + ":ERROR:" + error; console.log("Some call back error:" + errormsg); //res.send("Some error occured"); } else { if (pendingCB == 0) { if (ToolGroupName != "") { console.log("Toolgroup push to all clients done "); var body = { "clientList": clientList.toString(), "ToolGroupName": ToolGroupName }; var headers = { 'Content-Type': 'application/json' } var options = { url: "http://" + config.serverIP + ":" + config.serverPort + "/admin/pushclienttoolGroup/", headers: headers, method: "POST", body: JSON.stringify(body) } request(options, function(error, response, body) { //console.log("All Tool List :" + body); if (error) { console.log(error); res.send("Some error occured"); } else if (body == "error") { res.send("Some error occured on client"); } else { res.render("pushstatus.jade", { csrf: req.session.csrfCookie }); } }); } else { console.log("Tool push to client(s) done "); res.render("pushstatus.jade", { csrf: req.session.csrfCookie }); } } // All requests completed } // if error/else completed }); // request completed } // numclientid for loop completed } // for toolid for loop completed } } else { res.send("Invalid CSRF token"); } } else { res.redirect('/'); } });