Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkUser(userData) {
- return User.find({ userName: userData.userName }).exec().then((user) => {
- if (user == undefined || user.length == 0) {
- throw new Error("Unable to find user: " + userData.userName);
- }
- else if (user[0].password != userData.password) {
- throw new Error("Incorrect Password for user: " + userData.userName);
- }
- else if (user[0].password == userData.password)
- {
- user[0].loginHistory.push({
- dateTime: (new Date()).toString(),
- userAgent: userData.userAgent});
- user[0].update({
- userName: userData.userName}, {$set: {loginHistory: user[0].loginHistory}}).exec().then((user) => {
- return user[0];
- })
- .catch((err) => {
- console.log(err);
- console.log(err.stack);
- throw new Error("There was an error verifying the user: ${err}");
- })
- }
- }).catch((err) => {
- console.log(err);
- console.log(err.stack);
- throw new Error("Unable to find user: " + err);
- });
- };
- var mongoose = require("mongoose");
- var Schema = mongoose.Schema;
- var userSchema = new Schema({
- "userName": {
- unique: true,
- type: String
- },
- "password": String,
- "email": String,
- "loginHistory": [{ "dateTime": Date, "userAgent": String }]
- });
- let User; //to be defined on new connection
Add Comment
Please, Sign In to add comment