简体   繁体   English

AngularJS如何存储会话

[英]AngularJS how to store session

I've found a good flow to manage custom session manage here . 我找到了一个良好的流动性管理自定义会话管理这里 The question now is concerning on, which is the best way to store that the user is already validated? 现在的问题是,存储用户已通过验证的最佳方法是什么?

For example I have a rest api that return 0 or 1 if user's creadentials are valid. 例如,我有一个rest api,如果用户的凭据有效,则返回0或1。 Now, how and where can I store that information? 现在,如何以及在哪里存储该信息? SessionStorage could be good a place but if I store the user's password encrypted for example, then in controller, I have to check against what?? SessionStorage可能是个好地方,但是如果我存储了加密的用户密码,那么在控制器中,我必须检查什么? Where is the true and valid encrypted password? 真实有效的加密密码在哪里?

This question is in general, how to manage user session in angularJS. 这个问题通常是如何在angularJS中管理用户会话。

EDIT : Maybe the answer could be, you shouldn't check only credentials in the client side? 编辑 :也许答案可能是,您不应该只检查客户端中的凭据?

you have to inject 'ngCookies' in you app module and inject '$cookies' in your controller 您必须在应用程序模块中注入“ ngCookies”,并在控制器中注入“ $ cookies”

and you can put value like $cookies.put('variableName', vlue); 您可以输入$cookies.put('variableName', vlue); . and you can retrive $cookies.get('variableName'); 您可以检索$cookies.get('variableName');

I've found the solution. 我找到了解决方案。 Just comment if someone helps. 如果有人帮助,请发表评论。

One of the most important thing is activate credentials in $httpProvider 最重要的事情之一是激活$httpProvider凭据

$httpProvider.defaults.withCredentials = true;

Then in server some cookies must be stored into session and that's all. 然后,必须在服务器中将一些Cookie存储到会话中,仅此而已。 Next requests now are session-validated. 现在,下一个请求已通过会话验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM