Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //includes express, mongoose, User, constants. this part is ok.
- /**
- * Authenticates a user post request
- *
- * @request email string
- * @request password string
- *
- */
- router.post("/", (req, res) => {
- /**
- * Retrieve the user
- */
- User.find(
- {
- email: req.body.email
- },
- (err, user) =>
- {
- /**
- * An error occurred
- */
- if (err)
- {
- res.json({
- success: false,
- message: "An mongodb error occurred.",
- error: err
- });
- }
- /**
- * Check for problems with the email or password.
- * Or an error might have happened.
- */
- if (!user || (user && !user.verifyPassword(req.body.password, (err, match) => match)))
- // the code breaks here, telling me that user.verify... is not a function
- {
- res.json({
- success: false,
- message: "Email or password was incorrect."
- });
- }
- /**
- * User authenticated!
- */
- req.session.user = user;
- res.json({
- success: true,
- message: "Successfully authenticated."
- });
- });
- });
- router.get("/", (req, res, next) => {
- var admin = new User({
- name: "admin",
- password: "admin",
- authorization: constants.authorization.admin
- });
- // the code throws an error here, saying that isModified(...) is not a function
- admin.save(function(err) {
- if (err)
- {
- console.log(err);
- }
- console.log('User saved successfully');
- res.json({ success: true });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment