How to save the user's login by using Java + AngularJS

2

I was doing a search on how to save the user session after it has been logged in the system, I found several examples with cookies, however I am using java + angularjs, and in the examples I found it used the method ofPost of jsp, where it received 2 the response and request parameters, and through the response it added the cookie, how can I save the user's session?

    
asked by anonymous 23.01.2017 / 16:24

2 answers

2

Use ngStorage :

var meuApp = angular.module("meuApp", ["ngStorage"]);

meuApp.controller("LoginController", function($scope, $localStorage) {
    $scope.login = function() {
        $localStorage.usuario = "joao";
    }

    $scope.ola = function() {
        $scope.mensagem = "Olá " + $localStorage.usuario;
    }
});
    
23.01.2017 / 16:32
0

Hello, which mvc framework are you using? If it's Spring it's pretty simple, see the example:

public String salvarUsuarioNaSessao(@RequestParam Usuario usuario, HttpSession session){
// Seta na session
session.setAttribute("usuario", usuario);

//Recupera da session
Usuario usuarioNaSession = (Usuario) session.getAttribute("usuario");
return null;

}

    
23.01.2017 / 22:51