Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

页面跳转 #6

Open
mylylyl opened this issue Oct 10, 2017 · 7 comments
Open

页面跳转 #6

mylylyl opened this issue Oct 10, 2017 · 7 comments

Comments

@mylylyl
Copy link

mylylyl commented Oct 10, 2017

如果有多余两个页面的话要怎么操作跳转...?

@doterlin
Copy link
Owner

不太明白你说的意思哦。

@mylylyl
Copy link
Author

mylylyl commented Oct 12, 2017

本来是想问如果我有多个页面,怎么能checkLogin(demo里是没cookie跳login有cookie跳info)。现在用的笨办法是每个页面判断没cookie跳login。不知道有没有更好的解决方法~

@mylylyl
Copy link
Author

mylylyl commented Oct 12, 2017

另一个问题是,cookie里面设置的token是怎么获取的呢...之前用php的话session是后端自己处理完毕。
想到的流程是

  1. 前端验证登录
  2. api验证登录 信息正确的话生成一串token放在数据库中并返回给前端
    但是这样的话每个页面验证都要读一次数据库 感觉不太对

@doterlin
Copy link
Owner

@fisherwise 一个域名下的所有页面的cookie是共享的,多个页面也没关系吧。
另外,像token这些是后端进行对session做了处理后,返回给客户端,客户端用cookie保存起来。用户打开页面时如果该cookie存在就免登陆不需要每次都到数据库,否则才去请求后端。

@mylylyl
Copy link
Author

mylylyl commented Oct 12, 2017

就是说后端api自己维护一个表?

@doterlin
Copy link
Owner

doterlin commented Oct 13, 2017

我说的token只是打个比方,简单的登录的话就是后端验证账号密码没问题后,就给客户端设置一个cookie就行了(这个cookie就是token)。客户端来判断是否存在这个cookie就ok,在登录后调用api都要带上这个token和user_id等,否则别人手动加了个cookie就可以免登录调到用户信息了。
token的生成是由已有的信息,比如用户的id,登录账号等经过加密处理(如md5( uid + 暗号 ))得到的,一般还要设置有效期扔到Redis这类缓存,所以不需要另建表。

@mylylyl
Copy link
Author

mylylyl commented Oct 13, 2017

get~谢谢大佬w

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants