I am currently facing an issue with my Hprose server and user authentication. My goal is to create a logonService that will return a UserInfo object after the user has successfully logged in. The problem lies in the asynchronous nature of hprose.HttpClient.login() method, which takes seconds to complete. The code within the controller continues executing immediately after creating the logonService instance, resulting in $scope.user always being null and logonService.logon() never being called. I attempted to use $http.get instead, but I couldn't find a way to obtain a Promise object using Hprose. Despite searching on Google for solutions, I have been unable to find anything useful. Does anyone have any ideas on how to resolve this issue? Your help is greatly appreciated.
var app = angular.module("myApp",[])
.service("logonService", function() {
var httpclient = new hprose.HttpClient("http://testurl.com:4800/webapi/", ["login"]);
httpclient.login("userid", "ppt", function(sid) {
console.log("sid1="+sid);
}
this.logon = function() {
console.log("here I am");
return something;
}
})
.controller("myCtrl", ["logonService", function(logonService) {
var user = logonService.logon();
$scope.user = user;
}
)