小编mrc*_*cni的帖子

TypeError:无法读取undefined的属性'id' - sails和mongodb

Sails @ beta,mongodb,windows 7 32bit,

我试图通过应用程序创建一个新用户后收到上述错误.当我从config/policies.js删除策略isPawn一切正常.我不明白这个政策有什么问题.在我看来,我错误地访问mongodb id属性.

isPawn.js https://github.com/mrcn/C_Express/blob/master/api/policies/isPawn.js

module.exports = function(req, res, next) {

  var sessionUserMatchesId = req.session.User.id === req.param('id');
  var isAdmin = req.session.User.admin;

  // The requested id does not match the user's id,
  // and this is not an admin

  if (!(sessionUserMatchesId || isAdmin)) {
    var noRightsError =
    [{
      name: 'noRights',
      message: 'You must be an admin.'
    }];
    req.session.flash = {
      err: noRightsError
    };
    res.redirect('/session/new');
    return;
  }

  next();

};
Run Code Online (Sandbox Code Playgroud)

用户模型 - user.js https://github.com/mrcn/C_Express/blob/master/api/models/User.js

module.exports = {

  schema: true, …
Run Code Online (Sandbox Code Playgroud)

node.js sails.js sails-mongo

3
推荐指数
1
解决办法
9949
查看次数

使用sails.js确认密码

我想在帆0.10.0-rc9中设置密码确认.这是一个新用户注册.当我在两个字段中使用相同的密码时,控制台确认它正在抓取相同的密码,然后吐出它们不匹配的错误.我想知道我错过了什么......

model - user.js - 看起来像 https://github.com/mrcn/C_Express/blob/master/api/models/User.error.js

module.exports = {
  schema: true,
  attributes: {
    name: {
      type: "string",
      required: true
    },
    email: {
      type: "string",
      email: true,
      required: true,
      unique: true
    },
    encryptedPassword: {
      type: "string"
    },
    toJSON: function() {
      var obj = this.toObject();
      delete obj.password;
      delete obj.confirmation;
      delete obj.encryptedPassword;
      delete obj._csrf;
      return obj;
    }
  },
  beforeCreate: function (values, next) {
      console.log("Called beforeCreate User ");
      console.log(values);
    if(!values.password || values.password != values.confirmation) {
      console.log("\n if statement call \n");
      return next({
        err …
Run Code Online (Sandbox Code Playgroud)

javascript node.js sails.js

0
推荐指数
1
解决办法
958
查看次数

标签 统计

node.js ×2

sails.js ×2

javascript ×1

sails-mongo ×1