I want to login using $http
and GET
of REST web services
. What I am doing is:
- Taking data on the basis of username and password using $http.get
- Storing the result:
$scope.getResult=res;
Storing it in some variable:
var result=$scope.getResult; var username=result.userName;
var password=result.password;
var user=this.user; var pass=this.pass;After that I will compare with the ng-model of username and password. If it is successful then it will redirect to another page like below:
if (username == user && password == pass) { window.location="/next.html";
}
Below is my complete code and please suggest the changes required in my case.
$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";
}
}
}
Please tell me how should I change my code in order to do that.
Thanks in advance :)
Replace the raw
window.location
method with the AngularJS$location
service. Callingwindow.location
from inside a$q
service fulfillment handler will generally result in an AngularJS internal error.For more information, see AngularJS $location Service API Reference.
Debugging the Response
What is the specification for the server side API?
What is the server side code that generates the response data?
These are things readers will need to know in order to help you. Otherwise any answer is just a guess.
Industry best practice is to avoid sending passwords as a parameter of a URL as that has security issues.
Two resources recommended by the AngularJS team:2
Deal with users authentication in an AngularJS web app
Authentication in Single Page Applications With Angular.js
Additional Resources
GitHub AngularJS Authentication
Bit of Tech: AngularJS Token Authentication
AngularJS User Registration and Login Example & Tutorial
"http://localhost:17681/api/userRegisters?username= " + username + "&password=" + password
and read the username and password from http://localhost:17681/api/userRegisters this location by using GET HTTP METHOD