环回 - 扩展的AccessToken模型无法正常工作

时间:2016-02-04 20:09:31

标签: angularjs node.js loopbackjs strongloop passport-facebook

我正在使用带有AngularJs前端的loopback的护照组件。我已将 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Systems Request</title> <!--bootstrap--> <link href="Assets/css/bootstrap.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="../Assets/javascript/html5shiv.min.js"></script> <script src="../Assets/javascript/respond.min.js"></script> <![endif]--> <!--custom css--> <link rel="stylesheet" type="text/css" media="all" href="Assets/css/style.css"> <link rel="stylesheet" type="text/css" media="all" href="Assets/css/responsive.css"> <script src="Assets/Javascript/jquery-1.11.1.min.js" type= "text/javascript"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="Assets/javascript/bootstrap.js"></script> <script src="Assets/Javascript/textboxname_autocomplete.js" type= "text/javascript"></script> <style type="text/css"> .dropdown{ width: 292px; height: 45px; font-size: 16px; margin-left: 30px; margin-bottom: 10px; background-color: pink; } </style> </head> <body style="background-image: url('../Systems/Assets/images/background.jpg')"> <?php include("includes/createHeader.php");?> <section id="container"> <h2>Systems Request</h2> <form name="systems" id="systems-form" action="Pages/InsertProcess.php" method="post"onsubmit="return formCheck(this);"> <div id="wrapping" class="clearfix"> <section id="aligned"> <label class="label">LanID</label><br><br> <input type="text" name="lanId" id="lanId" autocomplete="off" tabindex="1" class="txtinput" > <label class="label">Employee Name</label><br><br> <input type="text" name="name" id="name" autocomplete="off" tabindex="1" class="txtinput"> <!--manager access db list info located in the includes folder--> <label class="label">Manager</label><br><br> <?php include("includes/accessDB_ManagerData.php");?> <!--department dropdownlist located in the includes folder--> <label class="label">Department</label><br><br> <?php include("includes/departmentDropdownList.php");?> <!--Request Issue list info located in the includes folder--> <label class="label">Request Issue</label><br><br> <!-- #start of Request Issues--> *<select name ="request" id="request" onchange="if (this.selectedIndex==3){this.form['printerType'].style.visibility='visible'}else {this.form['printerType'].style.visibility='hidden'};"> <option value =""><?php echo '&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Select Request Issue...'?></option> <option value ="RESET CASE"><?php echo '&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Reset Case'?></option> <option value ="RESET WM PASSWORD"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;RESET WM PASSWORD"?></option> <option value ="REPLACE TONER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;REPLACE TONER"?></option> <option value ="FIX PRINTER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;FIX PRINTER"?></option> <option value ="FIX DEVICES"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;FIX DEVICE"?></option> <option value ="SAFETY HIGH REQUEST"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SAFETY HIGH REQUEST"?></option> <option value ="OTHER"><?php echo "&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;OTHER"?></option> </select><br> <!-- #end of Request Issues-->* ***<select class="dropdown" style="visibility:hidden;" name="printerType" id="printerType" > <option Value="">Please select Printer Type</option> <option Value="FS 4200DN">Kyocera FS4200DN</option> <option Value="FS 3040MFP">Kyocera FS3040MFP</option> <option Value="Kyocera ">Kyocera FS1370DN </option> <option Value="OKI MPS710C">OKI MPS710C</option> <option Value="OKI MPS711C">OKI MPS711C</option> <option Value="Sharp MX450N">Sharp MX450N</option> </select>*** <br/> <label class="label">Request Description </label><br><br> <textarea name="request_comments" id="message" placeholder="Enter Description of Issue" tabindex="5" class="txtblock"></textarea> <input type="submit" name="submit" id="submitbtn" class="btn btn-primary btn" tabindex="7" value="Submit"> <br style="clear:both;"> <?php #Hidden inputs for Status, tech comments, tech completed, tech completed date?> <input name="status" type="hidden" value="RECEIVED"> <input name="comments" type="hidden" value="No Comment "> <input name="compUser" type="hidden" value="Unassigned"> <input name="compDt" type="hidden" value="Not Completed"> </section> </section> </div> </form> </section> <?php include("includes/footer.php");?> <script src="Assets/Javascript/gen_validatorv4.js" type="text/javascript"></script> </head> <script type="text/javascript"> var frmvalidator = new Validator("systems"); if (document.getElementById('request').selectedIndex==3){ frmvalidator.addValidation("printerType","req","Please enter Printer Type"); } else{ frmvalidator.addValidation("lanId","req","Please enter LanID"); frmvalidator.addValidation("request_comments","req","Please enter request comments"); } </script> </body> </html> 的自定义模型创建为User,将Person创建为AccessToken

我可以通过facebook正确登录并将其重定向到angularjs客户端。但我看到的是访问令牌存储在内置的AccessToken模型中,而不是我的自定义PersonAccessToken模型。
因此,当我调用PersonAccessToken函数时,它会抛出Person.logout(),因为它无法找到存储的任何访问令牌。

Person.json:

500 server error

PersonAccessToken.json:

{
"name": "Person",
  "base": "User",
  "strict": false,
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "properties": {},
  "validations": [],
  "relations": {
    "hasCredentials": {
      "type": "hasMany",
      "model": "PersonCredential",
      "foreignKey": "personId"
    },
    "hasIdentities": {
      "type": "hasMany",
      "model": "PersonIdentity",
      "foreignKey": "personId"
    },
    "hasAccessToken": {
      "type": "hasMany",
      "model": "PersonAccessToken",
      "foreignKey": "personId"
    }
  },
  "acls": [
    {
      "accessType": "WRITE",
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW"
    },
    {
      "accessType": "READ",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW"
    }
  ],
  "methods": {}
}

模型config.json:

{
  "name": "PersonAccessToken",
  "base": "AccessToken",
  "strict": false,
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "properties": {},
  "validations": [],
  "relations": {
    "belongsToPerson": {
      "type": "belongsTo",
      "model": "Person",
      "foreignKey": "personId"
    }
  },
  "acls": [],
  "methods": {}
}

datasources.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models",
      "./node_modules/loopback-component-passport-c/lib/models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "db",
    "public": false
  },
  "AccessToken": {
    "dataSource": "db",
    "public": false
  },
  "ACL": {
    "dataSource": "db",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "db",
    "public": false
  },
  "Role": {
    "dataSource": "db",
    "public": false
  },
  "Person": {
    "dataSource": "db",
    "public": true,
    "$promise": {},
    "$resolved": true
  },
  "PersonIdentity": {
    "dataSource": "db",
    "public": true,
    "$promise": {},
    "$resolved": true
  },
  "PersonCredential": {
    "dataSource": "db",
    "public": true,
    "$promise": {},
    "$resolved": true
  },
  "PersonAccessToken": {
    "dataSource": "db",
    "public": true,
    "$promise": {},
    "$resolved": true
  }
}

并且在server.js中我已经包含了

{
  "db": {
    "name": "db",
    "connector": "memory",
    "file": "db.json"
  }
}

我不知道我错过了什么或做错了什么?为什么不在我的自定义boot(app, __dirname); app.middleware('auth', loopback.token({ model: app.models.PersonAccessToken })); 模型中存储访问令牌?

0 个答案:

没有答案