Exemplo n.º 1
0
 findByName: function (name) {
     BookCategory.findByName(name, function (err, category) {
         if (err || category === null) {
             return res('heresy');
         } else {
             return res(category);
         }
     });
 },
Exemplo n.º 2
0
 findByName: function (name) {
     Editure.findByName(name, function (err, editure) {
         if (err || editure == null) {
             return res('heresy');
         } else {
             return res(editure);
         }
     });
 },
Exemplo n.º 3
0
  .get(function (req, res) {

    Story.findByName(req.params.storyId, function (err, story) {
      if (err) {
        fail(res, 404, 'Cannot get story');
      }

      res.json(story);
    });
  })
Exemplo n.º 4
0
checkUserToken = function (req, res, cb) {
  var token = getToken(req.headers);
  if (token) {
    var decoded = jwt.decode(token, secret);
    User.findByName(decoded.name, function (err, user) {
      if (err) throw err;

      if (!user) {
        return fail(res, 403, 'Authentication failed. User not found.');
      } else {
        cb(req, res, user);
      }
    });
  } else {
    return fail(res, 403, 'No token provided.');
  }
}
Exemplo n.º 5
0
    checkUserToken(req, res, function (req, res, user) {
      if (!user.isAdmin())
        return fail(res, 403, "Forbidden");
      Story.findByName(req.params.name, function (err, story) {
        if (err) {
          res.json({success: false, msg: 'Cannot get story', error: err});
        }

        story.name = req.body.name;
        story.iconUrl = req.body.iconUrl;
        story.startingSceneName = req.body.startingSceneName;
        story.version = req.body.version;
        story.resources = req.body.resources;

        story.save(function (err) {
          if (err)
            fail(res, 500, 'Cannot update story');

          success(res, 'Successful updated story!');
        });
      });
    });
Exemplo n.º 6
0
module.exports = function(req, res) {
    console.log('????????????????/');
    User.findByName(req.body.name, function(err, user) {
        console.log('1------', req.body);
        if (err) {
            return res.status(500).send(err);
        }

        if (!user) {
            console.log('The user does not exist!');
            return res.status(404).send({message: 'The user does not exist!'});
        }

        console.log('The user exist!');
        if (user.password != req.body.password) {
            console.log('Incorrect password!');
            return res.status(401).send({message: 'Incorrect password!'});
        }

        generateToken(function(err, token) {
            if (err) {
                return res.status(500).send(err);
            }

            User.update({name: req.body.name},{token: token}, function(err, numAffect) {
                if (err) {
                    console.log('Could not update!');
                    return res.status(500).send();
                }

                console.log(numAffect);
                return res.status(200).send({token: token});
            });
        });
    });
};
Exemplo n.º 7
0
 .then( function(newTestDoctor4) { return Doctor.findByName( newTestDoctor4.name ) })