Created
April 20, 2015 15:54
-
-
Save hogart/10fe3ef5202bcabd18ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function MainController(model) { | |
| this.model = model; | |
| } | |
| MainController.prototype = { | |
| findAll: function (req, res) { | |
| res.send(200, this.model + '.find({})'); | |
| }, | |
| findById: function (req, res) { | |
| res.send(200, this.model + '.findById(req.params.id)'); | |
| }, | |
| create: function (req, res) { | |
| res.send(200, 'new ' + this.model + '(req.body)'); | |
| }, | |
| update: function (req, res) { | |
| res.send(200, this.model + 'findByIdAndUpdate') | |
| } | |
| }; | |
| module.exports = MainController; |
This file contains hidden or 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 MainController = require('./main'); | |
| var UserController = function () { | |
| UserController.super_.apply(this, 'User'); | |
| }; | |
| UserController.prototype = { | |
| checkAuth: function (req, res, next) { | |
| if (req.session.user) { | |
| res.json({login: req.session.user}); | |
| } else { | |
| next(); | |
| } | |
| }, | |
| login: function (req, res, next) { | |
| var mail = req.body.mail; | |
| var password = req.body.password; | |
| User.authorize(mail, password, function (err, result, user) { | |
| if (result.login == 'yes') { | |
| req.session.user = user._id; | |
| res.json(result); | |
| } else { | |
| res.json({login: "no"}); | |
| } | |
| }) | |
| } | |
| }; | |
| util.inherits(UserController, MainController); | |
| module.exports = UserController; |
This file contains hidden or 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 express = require('express'); | |
| var app = express(); | |
| var UserController = require('./controllers/user'); | |
| var userController = new UserController(); | |
| app.get('/users', userController.findAll.bind(userController)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment