流程制造商 - 使用rest api登录无效

时间:2017-01-21 06:55:37

标签: javascript php angularjs api session

使用以下脚本我可以使用进程制作者rest api检索与特定用户相关的案例,但是在执行此操作后,无法进入主页并按原样使用系统(类似于单点登录)我在这里失踪了什么?我正在重定向到我想要的页面并再次将我带到登录屏幕。我正在使用app.js来调用其余的api和index.php来显示并输入登录凭据。我正在关注本教程http://www.processmaker.com/tutorial-rest-api-angularjs,请帮忙

我的app.js如下:

(function () {
  
  var app;
  app = angular.module('caseLister',[]);
  
  app.controller('listController', ['$http', '$scope', function($http, $scope){
    
    this.server_url = 'http://localhost';
    this.workspace = 'workflow';
    this.credentials = {
         grant_type   : 'password',
         scope        : '*',
         client_id    : 'GFFBDLKMOFFGRLQXELEOIBUVWQXUYANB',
         client_secret: '3429870605882e9af901eb4035842469',
         username     : '',
         password     : ''
    };
	 
	 var access_token = '';	 
	 var list = this;
	 
    this.login = function () {
		 var parameters = {
			 method: 'POST',
			 url: list.server_url+list.workspace+'/oauth2/token',
			 data: this.credentials
	    };
		 $http(parameters).success(function(data){
		 	if (data.error) {
		 		alert(data.error_description);
		 	}else {
		 		parameters = {
					 method: 'GET',
					 url: list.server_url+'api/1.0/'+list.workspace+'/cases',
					 headers: {'Authorization': 'Bearer '+data.access_token}
			    };
				$http(parameters).success(function(data){
					location.href="http://localhost/sysworkflow/en/neoclassic/cases/main";
				  list.cases = data;
				});
			  
			}
		 });
	 };
	 	 
  }]);
  
})();

我的index.php如下:

<!DOCTYPE html>
<html ng-app="caseLister">
  <head>
    <link rel="shortcut icon" type="image/x-icon" href="http://www.processmaker.com/favicon.ico" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
  </head>
  <body ng-controller="listController as list">
    <div class="panel panel-primary">
      <div class="panel-heading">
        <h1>ProcessMaker Case Lister</h1>
        <h6>Build your own user interface using the new ProcessMaker REST API</h6>
      </div>
      <div class="panel-body">
        <div class="well well-sm col-xs-4 pull-right">
        	 <h4>PM Server details</h4>
        	 <strong>URL:</strong> {{list.server_url}}<br>
        	 <strong>Workspace:</strong> {{list.workspace}}<br>
        	 <strong>Client ID:</strong> {{list.credentials.client_id}}<br>
        	 <strong>Client Secret:</strong> {{list.credentials.client_secret}}
        </div>
        <form>
	        <div class="input-group col-xs-6">
	          <div class="input-group-addon">Username:</div>
	          <input type="text" class="form-control" ng-model="list.credentials.username">
	        </div><br>
	        <div class="input-group col-xs-6">
	          <div class="input-group-addon">Password:</div>
	          <input type="password" class="form-control" ng-model="list.credentials.password">
	        </div><br>	
	        <input class="btn btn-info" type="button" value="Get Case List" ng-click="list.login()"><br>
        </form>
        <div ng-show="list.cases.length > 0">
        	 <h3>CASE LIST ({{list.cases.length}})</h3>
        	 <table class="table table-hover table-bordered">
			   <thead><tr class="bg-primary">
			   	<th>#</th>
			   	<th>Case Number</th>
			   	<th>Process</th>
			   	<th>Task</th>
			   	<th>Sent By</th>
			   	<th>Due Date</th>
			   	<th>Status</th></tr></thead>
			   <tr ng-repeat="case in list.cases">
			   	<td>{{$index + 1}}</td>
			   	<td>{{case.app_number}}</td>
			   	<td>{{case.app_pro_title}}</td>
			   	<td>{{case.app_tas_title}}</td>
			   	<td>{{case.app_del_previous_user}}</td>
			   	<td>{{case.del_task_due_date}}</td>
			   	<td>{{case.app_status}}</td></tr>
			 </table>
        </div>
      </div>
    </div>
    </div>
  </body>
</html>

0 个答案:

没有答案