Keep sitting with AngularJs Authentication

1

I'm using this project to do authentication with AngularJS.

I'm using AngularJS 1.6.4 with WildFly 10 with Java 8 and SQL Server 2014. I can login correctly, but when I refresh 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 is the original file ), do I have to do what to be able to keep the session?

Here is my code user.service.js:

(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 have tried everything, or almost everything. I already notice that I am new to AngularJS, HTML5, JavaScript, Java ...

    
asked by anonymous 27.05.2017 / 02:30

0 answers