Created
December 23, 2017 16:19
-
-
Save cckn1ght/c80be30d27c7b836575bc775d5566049 to your computer and use it in GitHub Desktop.
backend login logic
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
// server will establish a link to mongodb when it starts. | |
console.log('mongodb url: ' + _config2.default.mongoURL); | |
_mongoose2.default.connect(_config2.default.mongoURL, _config2.mongo_options, function (error) { | |
if (error) { | |
console.error('Please make sure Mongodb is installed and running!'); | |
} | |
}); |
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
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
var _mongoose = require('mongoose'); | |
var _mongoose2 = _interopRequireDefault(_mongoose); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var Schema = _mongoose2.default.Schema; // User model | |
// own _id will be the primary key | |
var userSchema = new Schema({ | |
_id: { type: 'ObjectId', required: true }, | |
email: { type: String, required: true, unique: true }, | |
password: { type: String, required: true }, | |
isAdmin: { type: Boolean, required: true, default: false }, | |
firstName: { type: String, trim: true }, | |
lastName: { type: String, trim: true }, | |
isEmailVerified: { type: Boolean, default: false }, | |
dateCreated: { type: Date, default: Date.now, required: true } | |
}); | |
exports.default = _mongoose2.default.model('User', userSchema); |
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 signin(req, res) { | |
var email = req.body.email; | |
var password = req.body.password; | |
if (!email || !password) { | |
return res.status(400).send({ message: "You must send the email and the password" }); | |
} | |
// _user2 is the mongodb model, which talks to the database. | |
// var _user2 = require('../models/user.js'); // user.js is included after this | |
_user2.default.findOne({ | |
email: email | |
}, function (err, user) { | |
if (!user) { | |
return res.status(401).send({ message: "The email or password don't match" }); | |
} | |
// skipping the logics for finding a user. | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment