Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Object Relational Mapping.
*
* @author DarkPark
* @license GNU GENERAL PUBLIC LICENSE Version 3
*/
'use strict';
var orm = require('orm'),
db;
// global options
orm.settings.set('connection.debug', false);
orm.settings.set('instance.cache', false);
// init
//db = orm.connect('sqlite://./db.sqlite');
db = orm.connect('mysql://fortnotes:fortpass@localhost/fortnotes');
db.on('connect', function ( error ) {
function loadResult ( error ) {
if ( error ) { throw error; }
}
if ( error ) { throw error; }
db.use(require('orm-transaction'));
// models
/**
* Object Relational Mapping.
*
* @author DarkPark
* @license GNU GENERAL PUBLIC LICENSE Version 3
*/
'use strict';
var orm = require('orm'),
db;
// global options
orm.settings.set('connection.debug', false);
orm.settings.set('instance.cache', false);
// init
//db = orm.connect('sqlite://./db.sqlite');
db = orm.connect('mysql://fortnotes:fortpass@localhost/fortnotes');
db.on('connect', function ( error ) {
function loadResult ( error ) {
if ( error ) { throw error; }
}
if ( error ) { throw error; }
db.use(require('orm-transaction'));
// models
db.load('./models/keys', loadResult);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(expressValidator());
app.use(cookieParser());
app.use(session({cookie: { maxAge: 60000 }, secret: 'secret'}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
// DB configuration
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(settings.db);
orm.settings.set("instance.returnAllErrors", true);
app.use(orm.express(settings.dsn, {
define: function (db, models, next) {
db.load("./models", function (err) {
models.User = db.models.users;
models.Pad = db.models.pads;
models.Note = db.models.notes;
next();
});
}
}));
// Flash Messages configuration
app.use(function(req, res, next){
res.locals.flash_messages = {
'success': req.flash('success'),
'error': req.flash('error')
module.exports = function (app) {
var orm = require("orm"),
tesla = require('../../lib/tesla')(app),
teslaDB = require('../../lib/tesla.db')(app),
enforce = require("enforce"),
colors = require('colors'),
db = orm.connect(app.config.db.url);
orm.settings.set("instance.returnAllErrors", true);
// DEFINE MODEL SCHEMA
// Be sure to add some files to the schema below or you will not have success quering or adding to the database
var Model = db.define("{model}", {
created : { type: "date", time: true },
updated : { type: "date", time: true }
// _id : { type: "text" },
// name : { type: "text", required: true },
// isAdmin : { type: "boolean", defaultValue: false },
}, {
validations: {
// EXAMPLE VALIDATIONS
// password: orm.enforce.security.password('luns5', 'Passowrd does not meet min security requirements.'),
// email: orm.enforce.patterns.email('Please enter a valid email address.')
// More Options : https://github.com/dresende/node-enforce
}
module.exports = function (app) {
var orm = require('orm'),
tesla = require('../../lib/tesla')(app),
teslaDB = require('../../lib/database')(app),
colors = require('colors'),
db = orm.connect(app.config.db.url);
orm.settings.set('instance.returnAllErrors', true);
// DEFINE MODEL SCHEMA
// Be sure to add some files to the schema below or you will not have success quering or adding to the database
var Model = db.define('{model}', {
created : { type: 'date', time: true },
updated : { type: 'date', time: true }
// _id : { type: 'text' },
// name : { type: 'text', required: true },
// isAdmin : { type: 'boolean', defaultValue: false },
}, {
validations: {
// EXAMPLE VALIDATIONS
// password: orm.enforce.security.password('luns5', 'Passowrd does not meet min security requirements.'),
// email: orm.enforce.patterns.email('Please enter a valid email address.')
// More Options : https://github.com/dresende/node-enforce
}
* @date 20151201
*/
var ejs = require('ejs');
var express = require('express');
var session = require('cookie-session');
var lactate = require('lactate');
var config = require('./config');
var routers = require('./routers');
var bodyParser = require('body-parser');
var flash = require('flashify');
var mysql = require('./models/mysql');
var app = express();
var orm = require('orm');
var path = require('path');
orm.settings.set("connection.pool", true);
Object.keys(config).forEach(function(key) {
app.locals[key] = config[key];
});
app.use(function(req, res, next) {
if (req.headers['user-agent'].indexOf('Chrome') === -1) {
res.send('请使用谷歌浏览器');
} else {
next();
}
});
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
//parse application/x-www-form-urlencoded