My goal is to login using $http
and GET
of REST web services
. This is my approach:
- Retrieve data based on username and password using $http.get
- Store the result in
$scope.getResult=res;
Assign variables to the retrieved data:
var result=$scope.getResult; var username=result.userName;
var password=result.password;
var user=this.user; var pass=this.pass;Next, I compare the stored data with the ng-model of username and password. If they match, redirect to another page as shown below:
if (username == user && password == pass) { window.location="/next.html";
}
Here's my complete code. Any suggestions on how to improve it would be greatly appreciated.
$scope.login = function () {
var user = this.user ; // ng-model of username in html page
var pass = this.pass; //ng-model of password in html page
$http.get("http://localhost:17681/api/userRegisters"+user+pass).success(function (res) {
$scope.getResult = res;
var result = $scope.getResult;
var username = result.userName;
var password = result.password;
if (username == user && password == pass) {
window.location="/next.html";
}
}
}
I'm open to any suggestions on how to enhance my code for better functionality.
Thank you in advance :)