2016-03-07 33 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