如何在strong循环中隐藏结果中的特定字段

时间:2016-03-07 09:10:44

标签: javascript rest strongloop

我正在尝试使用strongloop创建一个项目,我正在为用户登录创建一个Web服务,我的代码运行良好&得到所需的输出,除了它不隐藏密码

我的结果为

{
    "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": "anupd@ideaentity.com",
        "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();
                }
            });

这里"结果将提供所有细节"我想隐藏结果中的密码

提前致谢

3 个答案:

答案 0 :(得分:0)

试试这个。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9001" doc:name="HTTP Listener Configuration"/>
    <http:request-config name="HTTP_Request_Configuration" host="10.208.165.126" port="8080" basePath="/ingestion" doc:name="HTTP Request Configuration"/>
    <flow name="ingestionsampleFlow" >
        <http:listener config-ref="HTTP_Listener_Configuration" path="/ingestion/" doc:name="HTTP"/>
        <set-payload doc:name="Set Payload" value="#[payload.user]"/>
       <!--  <json:json-to-object-transformer returnClass="java.util.Map" mimeType="application/json" doc:name="JSON to Object"/>

        <http:request config-ref="HTTP_Request_Configuration" path="esb" method="POST" doc:name="HTTP"/>
         -->

        <!--  <http:inbound-endpoint doc:name="HTTP" exchange-pattern="request-response" contentType="application/json" host="10.208.165.126" port="8080"/> -->

        <http:outbound-endpoint exchange-pattern="request-response" host="10.208.165.126" port="8080"  method="POST" contentType="application/json" doc:name="HTTP" path="esb"/>
        <logger message="2--&gt;#[payload]" level="INFO" doc:name="Logger"/>


    </flow>
</mule>
  

propertyName是要包含的属性(字段)的名称   排除。表示true或false布尔文字。   使用true可包含属性,或使用false可将其从结果中排除。   您也可以使用1表示true,0表示false表示。默认情况下,查询   返回结果中的所有模型属性。但是,如果指定at   至少有一个字段过滤值为true,然后默认为   查询将仅包含您特别包含过滤器的那些。

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

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

否则你可以在afterremotemethod()中手动删除   ctx.result。   请参阅此链接https://docs.strongloop.com/display/public/LB/Remote+hooks

答案 1 :(得分:0)

  

在你的model.json中添加隐藏字段“隐藏”:[“密码”,   “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": {

  }
}

答案 2 :(得分:0)

对我来说

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

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

这很好用

有关母马的详细信息,请查看here