2016-03-07 62 views
4

我试图创建一个使用strongloop的项目,其中我创建用户登录的Web服务的具体领域,我的代码运行良好&得到所需的输出,除了一个事实,即它不隐藏密码如何从结果隐藏strongloop

我得到的结果

{ 
    "result": [{ 
     "_id": 2, 
     "address": "abc", 
     "created_by": 1, 
     "created_date": "2016-03-04T00:00:00.000Z", 
     "firstname": "Anup", 
     "isdeleted": 0, 
     "lastname": "Deshpande", 
     "mobile_number": "9700128907", 
     "oldpassword": "string", 
     "profile_picturename": "anup.jpeg", 
     "role_id": 1, 
     "user_email_id": "[email protected]", 
     "user_password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", 
     "user_status": 1 
    }] 
} 

,我想隐藏或删除"user_password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",领域。

谁能告诉我,我该怎么办,在strongloop的远程方法

我renote方法的代码是这样如下

db.collection('users').find({ 
       user_email_id : par, 
       user_password : sha256(par2) 
      }).toArray(function(err, result) { 

       // var passwordHash = hashPassword(user_password); 
       // console.log(passwordHash); 
       if (err) { 
        throw err; 
       } 
       if (result.length > 0) { 
        self.callback(null, result); 
        // db.disconnect(); 
       } else { 
        self.callback(null, response); 
        // db.disconnect(); 
       } 
      }); 

这里“的结果将给所有的细节:”我想隐藏结果密码

在此先感谢

回答

0

试试这个。

{ fields: {propertyName: <true|false>, propertyName: <true|false>, ... } } 

propertyName为属性(字段)的名称来包括或排除 。表示布尔文字的真或假。 使用真到包括财产或虚假的,从结果中排除。 您还可以使用1真,0表示假。默认情况下,查询 返回结果中的所有模型属性。不过,如果你在 至少一个字段指定具有true值过滤,则默认情况下 查询将仅包括您具体包括有过滤器。

参考此链接 https://docs.strongloop.com/display/public/LB/Fields+filter

Example: 
var query = { fields: {password: false} } 
Model.find(query, function() 
{ 
}); 

否则,你可以在afterremotemethod)手动删除(在 ctx.result。在你model.json是 “隐藏” 指该链接https://docs.strongloop.com/display/public/LB/Remote+hooks

+0

请检查更新的问题和你能告诉我如何我可以在我的代码行“self.callback过滤领域有结果(空,结果); “ –

+0

你收到了吗?还检查我的第二个答案 –

0

添加隐藏字段: “密码”, “verificationToken”],

Example: 
{ 
    "name": "User", 
    "properties": { 
    "realm": { 
     "type": "string" 
    }, 
    "username": { 
     "type": "string" 
    }, 
    "password": { 
     "type": "string", 
     "required": true 
    }, 
    "credentials": { 
     "type": "object", 
     "deprecated": true 
    }, 
    "challenges": { 
     "type": "object", 
     "deprecated": true 
    }, 
    "email": { 
     "type": "string", 
     "required": true 
    }, 
    "emailVerified": "boolean", 
    "verificationToken": "string", 
    "status": "string", 
    "created": "date", 
    "lastUpdated": "date" 
    }, 
    "options": { 
    "caseSensitiveEmail": true 
    }, 
    "hidden": ["password", "verificationToken"], 
    "acls": [ 

    ], 
    "relations": { 

    } 
} 
0

// {user_password:0} - 隐藏密码

db.collection('users').find({ 
       user_email_id : par, 
       user_password : sha256(par2) 
      },{user_password:0}).toArray(function(err, result) { 

这个工作得很好

为母马的细节,你可以检查here