eta.db.query(sql, [req.session["userid"]], (err: eta.DBError, rows: any[]) => {
     if (err) {
         eta.logger.dbError(err);
         res.redirect("/apply?error=" + querystring.escape("We were unable to process your application due to an internal error."));
         return;
     }
     let valueSql: string = "(?, ?, 1),".repeat(positions.length);
     let sql: string = `
         INSERT INTO ApplicantPosition
         (id, position, count)
         VALUES ${valueSql.substring(0, valueSql.length - 1)}
         ON DUPLICATE KEY UPDATE
             lastApplied = CURRENT_TIMESTAMP(),
             count = count + 1`;
     let params: string[] = [];
     for (let i: number = 0; i < positions.length; i++) {
         params.push(req.session["userid"]);
         params.push(positions[i]);
     }
     eta.db.query(sql, params, (err: eta.DBError, rows: any[]) => {
         if (err) {
             eta.logger.dbError(err);
             res.redirect("/apply?error=" + querystring.escape("We were unable to process your application due to an internal error."));
             return;
         }
         res.redirect("/apply?success=true");
     });
 });
 }, (err: Error, info: nodemailer.SentMessageInfo) => {
     if (err) {
         eta.logger.warn("Could not send mail from " + req.body.email + ": " + err.message);
         res.redirect("/contact?error=" + querystring.escape("failed-to-send-email"));
         return;
     }
     res.redirect("/contact?success=true");
 });
 eta.db.query(sql, params, (err: eta.DBError, rows: any[]) => {
     if (err) {
         eta.logger.dbError(err);
         res.redirect("/apply?error=" + querystring.escape("We were unable to process your application due to an internal error."));
         return;
     }
     res.redirect("/apply?success=true");
 });
 eta.setting.set(req.body.page, req.body.name, req.body.value, req.body.type, (success: boolean) => {
     eta.logger.trace("Setting set: " + success);
     eta.setting.init();
     if (req.body.shouldRedirect) {
         res.redirect("../edit/settings?lastPage=" + querystring.escape(req.body.page));
     } else {
         res.send(success.toString());
     }
 });
Beispiel #5
0
export function requireAuthCookieOrRedirect(req, res, next) {
  if (req['authSession'].signed_in !== true) {
    var url = util.format('/login?redirect=%s', qs.escape(req.path));
    return res.redirect(url);
  }
  res.locals.user = getUser(req);
  res.locals.signOutCsrfToken = req.authSession.signOutCsrfToken;
  next();
}
Beispiel #6
0
	public async generateDataUri(data: string): Promise<string> {
		let result: string = null;
		try {
			const qrSvg = imageSync(data, { size: this.$staticConfig.QR_SIZE, type: "svg" }).toString();
			result = `data:image/svg+xml;utf-8,${escape(qrSvg)}`;
		} catch (err) {
			this.$logger.trace(`Failed to generate QR code for ${data}`, err);
		}

		return result;
	}
 public render(req: express.Request, res: express.Response, callback: (env: { [key: string]: any }) => void): void {
     // check if a position was selected
     let positions: string[] = [];
     for (let param in req.body) {
         if (param.startsWith("Position:")) {
             positions.push(param.split(":")[1]);
         }
     }
     if (positions.length == 0) {
         res.redirect("/apply?error=" + querystring.escape("Please select positions before submitting your application."));
         return;
     }
     let sql: string = `
         INSERT IGNORE INTO Applicant
         (id, notes, workStudy, phone, altEmail)
         VALUES (?, '', 0, '', '')`;
     eta.db.query(sql, [req.session["userid"]], (err: eta.DBError, rows: any[]) => {
         if (err) {
             eta.logger.dbError(err);
             res.redirect("/apply?error=" + querystring.escape("We were unable to process your application due to an internal error."));
             return;
         }
         let valueSql: string = "(?, ?, 1),".repeat(positions.length);
         let sql: string = `
             INSERT INTO ApplicantPosition
             (id, position, count)
             VALUES ${valueSql.substring(0, valueSql.length - 1)}
             ON DUPLICATE KEY UPDATE
                 lastApplied = CURRENT_TIMESTAMP(),
                 count = count + 1`;
         let params: string[] = [];
         for (let i: number = 0; i < positions.length; i++) {
             params.push(req.session["userid"]);
             params.push(positions[i]);
         }
         eta.db.query(sql, params, (err: eta.DBError, rows: any[]) => {
             if (err) {
                 eta.logger.dbError(err);
                 res.redirect("/apply?error=" + querystring.escape("We were unable to process your application due to an internal error."));
                 return;
             }
             res.redirect("/apply?success=true");
         });
     });
 }
Beispiel #8
0
        let sep: string;
        let eq: string;
        let options: querystring.ParseOptions;
        let result: SampleObject;

        result = querystring.parse<SampleObject>(str);
        result = querystring.parse<SampleObject>(str, sep);
        result = querystring.parse<SampleObject>(str, sep, eq);
        result = querystring.parse<SampleObject>(str, sep, eq, options);
    }

    {
        let str: string;
        let result: string;

        result = querystring.escape(str);
        result = querystring.unescape(str);
    }
}

////////////////////////////////////////////////////
/// path tests : http://nodejs.org/api/path.html
////////////////////////////////////////////////////

namespace path_tests {

    path.normalize('/foo/bar//baz/asdf/quux/..');

    path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
    // returns
    //'/foo/bar/baz/asdf'
Beispiel #9
0
////////////////////////////////////////////////////
/// Dgram tests : http://nodejs.org/api/dgram.html
////////////////////////////////////////////////////

var ds: dgram.Socket = dgram.createSocket("udp4", (msg: Buffer, rinfo: dgram.RemoteInfo): void => {
});
var ai: dgram.AddressInfo = ds.address();
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: number): void => {
});

////////////////////////////////////////////////////
///Querystring tests : https://gist.github.com/musubu/2202583
////////////////////////////////////////////////////

var original: string = 'http://example.com/product/abcde.html';
var escaped: string = querystring.escape(original);
console.log(escaped);
// http%3A%2F%2Fexample.com%2Fproduct%2Fabcde.html
var unescaped: string = querystring.unescape(escaped);
console.log(unescaped);
// http://example.com/product/abcde.html

////////////////////////////////////////////////////
/// path tests : http://nodejs.org/api/path.html
////////////////////////////////////////////////////

namespace path_tests {

    path.normalize('/foo/bar//baz/asdf/quux/..');

    path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
Beispiel #10
0
export function percentEncode(input: string): string {
  return qs.escape(input)
           .replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
}