This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var authHandler = require('./handlers/auth'), | |
petHandler = require('./handlers/pet'); | |
exports.init = function (app) { | |
app.post('/auth', authHandler.generateToken); | |
app.post('/pet', authHandler.authorize, petHandler.addPet); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.generateToken = function(req, res) { | |
var username, password; | |
username = req.param('username'); | |
password = req.param('password'); | |
if(username === 'foo' && password === 'bar') { | |
res.send(200, {'token': "ABC123"}); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.addPet = function (req, res) { | |
//Do something to save the data for a new pet | |
res.send(200, {'result': 'success'}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('userpets', 'dbuser', 'dbpassword', { | |
host: 'localhost', //mysql host name | |
port: 3306 //default mysql port | |
}); | |
var User = sequelize.define( | |
'User', | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('userpets', 'dbuser', 'dbpassword', { | |
host: 'localhost', //mysql host name | |
port: 3306 //default mysql port | |
}); | |
var User = sequelize.define( | |
'User', | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Executing: INSERT INTO `Users` (`firstName`,`lastName`,`password`,`numberOfPets`,`id`,`createdAt`,`updatedAt`) VALUES ('foo','bar','asdfasdf',0,NULL,'2012-12-09 01:20:25','2012-12-09 01:20:25'); | |
Error: ER_NO_SUCH_TABLE: Table 'userpets.users' doesn't exist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('userpets', 'dbuser', 'dbpassword', { | |
host: 'localhost', //mysql host name | |
port: 3306 //default mysql port | |
}); | |
var User = sequelize.define( | |
'User', | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> select * from Users; | |
+-----------+----------+----------+--------------+----+---------------------+---------------------+ | |
| firstName | lastName | password | numberOfPets | id | createdAt | updatedAt | | |
+-----------+----------+----------+--------------+----+---------------------+---------------------+ | |
| foo | bar | asdfasdf | 0 | 1 | 2012-12-09 01:30:15 | 2012-12-09 01:30:15 | | |
+-----------+----------+----------+--------------+----+---------------------+---------------------+ | |
2 rows in set (0.00 sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('userpets', 'dbuser', 'dbpassword', { | |
host: 'localhost', //mysql host name | |
port: 3306 //default mysql port | |
}); | |
var User = sequelize.define( | |
'User', | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ...... | |
var Pet = sequelize.define( | |
'Pet', | |
{ | |
name: { type: Sequelize.STRING }, | |
type: { type: Sequelize.STRING } | |
} | |
); |
OlderNewer