1
I’m wearing the one project to authenticate with Angularjs.
I’m using Angularjs 1.6.4 with Wildfly 10 with Java 8 and SQL Server 2014. I can log in correctly, but when I update the page the session is not maintained.
What am I doing wrong? In addition to the 'Rest' adaptations I have to do in 'user.servi.js' (here’s the original file), I have to do what I can to keep the session?
Here’s my user.service.js code:
(function () {
'use strict';
angular
.module('app')
.factory('UserService', UserService);
UserService.$inject = ['$http'];
function UserService($http) {
var service = {};
//service.GetAll = GetAll;
//service.GetById = GetById;
service.GetByUsername = GetByUsername;
service.Create = Create;
//service.Update = Update;
//service.Delete = Delete;
return service;
//function GetAll() {
// return $http.get('rest/usuarios/login/').then(handleSuccess, handleError('Error getting all users'));
//}
//function GetById(id) {
// return $http.get('rest/usuarios/login/' + id).then(handleSuccess, handleError('Error getting user by id'));
//}
function GetByUsername(usermatricula, usersenha) {
return $http.post('rest/usuarios/login/' + usermatricula + '/' + usersenha).then(handleSuccess, handleError('Error getting user by username'));
}
function Create(user) {
return $http.post('rest/usuarios/', user).then(handleSuccess, handleError('Error creating user'));
}
//function Update(user) {
// return $http.put('rest/usuarios/login/' + user.id, user).then(handleSuccess, handleError('Error updating user'));
//}
//function Delete(id) {
// return $http.delete('rest/usuarios/login/' + id).then(handleSuccess, handleError('Error deleting user'));
//}
// private functions
function handleSuccess(res) {
console.log(res.data);
return res.data;
}
function handleError(error) {
return function () {
return { success: false, message: error };
};
}
}
})();
I’ve tried everything, or almost everything. I’m new to Angularjs, HTML5, Javascript, Java...
Managed to solve?
– Daniel
Not yet!! I’ve tried many things, but so far nothing!! Have something in mind that I can try?
– LTK
I tried his project with Ode, and it worked, apparently - you’ve done this test?
– Daniel
I tested using the file user.service.local-Storage.js, which would be for a Fake User Service and works, but for a real server the same recommends the user.service.js, and with me it’s not working. I don’t know what I’m doing wrong.
– LTK
Yes - I’m referring to before of that - I just downloaded the project, and used the server [tag:nodejs] as described here - I suggest you do that and test. I tested it with the code you posted above, and it worked too, so the problem is elsewhere, and it will be difficult for the community to help you without the missing information. If it is a Wildfly problem, the question has to be rewritten. Test and let us know... ;)
– Daniel
When I tested the project I used the live-server. I think it’s the same thing, isn’t it? In your test, did you actually search the user through the bank? (If so, can http-server connect directly to the bank? In my case SQL Server? ) And how can I know if the problem is Wildfly? : ) Let me know what other part of the code you want me to post.
– LTK
I didn’t get to use database - but do you want to keep SQL logged in as well? I suggest you test each thing separately - move the project that works for Wildfly, and see if it keeps working, so include SQL. http-server seems to only serve static pages and nothing else.
– Daniel
"keep session by SQL too, "get in doubt now, how so? I got interested on the subject. - I will isolate the project, maybe it is better to make a copy. - So what do you recommend, to keep session by Angularjs or otherwise? And what that other way would look like. PS: I didn’t want to use php, just to be clear.
– LTK