kam kam - 2 months ago 10
reST (reStructuredText) Question

How to use these 2 rest services in AngularJS, also how to call requrest for jwt from spring backend

I am trying to consume rest services but don't know how to call web services in angularjs from spring backend, also want to know how to integrage json web based token which I have written in spring backend in angularjs.

Webservice 1 : Login for admin

URL: <http://200.201.4.12:8080/liberary/authenticateUser>
Request type: POST
Header type: Content-Type application/json
Parameters: {
"username":"darek",
"password":"dark99"
}


Webservice 1 : Login for user

URL: <http://200.201.4.12:8080/liberary/authenticateUser>
Request type: POST
Header type: Content-Type application/json
Parameters: {
"username":"polo",
"password":"polo33"
}


My Code is:

authService.login = function(user, success, error) {
$http.post('misc/users.json').success(function(data) {
//this is my dummy technique, normally here the
//user is returned with his data from the db
var users = data.users;
if(users[user.username]){
var loginData = users[user.username];
//insert your custom login function here
if (user.username == loginData.username && user.password == loginData.username) {
//set the browser session, to avoid relogin on refresh
$window.sessionStorage["userInfo"] = JSON.stringify(loginData);

//delete password not to be seen clientside
delete loginData.password;

//update current user into the Session service or $rootScope.currentUser
//whatever you prefer
Session.create(loginData);
//or
$rootScope.currentUser = loginData;

//fire event of successful login
$rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
//run success function
success(loginData);
} else {
//OR ELSE
//unsuccessful login, fire login failed event for
//the according functions to run
$rootScope.$broadcast(AUTH_EVENTS.loginFailed);
error();
}
}
});
};

Answer

You are using $http.post with a json file (Do not know where it comes from

You should replace it with the URL of your webservice + the data

$http.post('http://200.201.4.12:8080/liberary/authenticateUser',
     {"username" : "polo", "password" : dark99}).then(function(data){

    //Do what you want with the data returned from your webservice
}, function(error){
    //Handle error
});

NOTE : You only have 1 webservice which is located on 200.201.4.12:8080