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)
- {
- return res.json({
- success: false,
- message: "An mongodb error occurred.",
- error: err
- });
- }
- /**
- * Check for problems with the email or password.
- */
- if (!user)
- {
- return res.json({
- success: false,
- message: "Email or password was incorrect."
- });
- }
- // ##########################################################
- // ERROR
- // user.verifyPassword(req.body.password, match => {
- // ^
- // TypeError: user.verifyPassword is not a function
- // ##########################################################
- user.verifyPassword(req.body.password, match => {
- if (!match)
- {
- return 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",
- email: "admin@admin.net",
- password: "admin",
- authorization: constants.authorization.admin
- });
- // ########################################################
- // ERROR
- // if (!user.isModified("password"))
- // ^
- // TypeError: user.isModified is not a function
- // #######################################################
- admin.save(function(err) {
- if (err)
- {
- console.log(err);
- }
- console.log('User saved successfully');
- res.json({ success: true });
- });
- });
Add Comment
Please, Sign In to add comment