javascript - Webapp 关闭后重新打开无需登录如何操作?
大家讲道理
大家讲道理 2017-04-17 15:17:16
0
3
477

我是个新人,最近给公司做一个webapp(是那种扫描二维码进入页面的),测试的时候有个问题就是,如果关闭了页面,重新扫描二维码会要求重新登录,非常的麻烦,我查询了百度,发现用HTML5的localStorage可以解决,但我毕竟是个新人,所以不知道,这个如何和数据库里面的数据进行匹配或者校验?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
左手右手慢动作

It depends on what kind of authentication your server uses. You have to ask the back-end personnel. If it is cookie authentication, there is no need to add special operations on the front-end.

If you want to authenticate the token, then each time you enter the page, call any interface that requires a token. If the call fails, it means you are not logged in. If the call is successful, it means you have logged in.

As long as you don’t clear the stored token or the token does not expire, you will be logged in automatically.

PHPzhong
islogin(){
    let user = localStorage.getItem("USER_INFO") 
    if(user){
        // 登陆了
    }else{
        // this.login({user})
    }
},
login(){
    ....ajax
    success(user){
        // 登陆成功后
        localStorage.setItem("USER_INFO",user)
    }
}
左手右手慢动作

1. The front and back ends are not separated: the login status should be maintained by the back end;
2. The front and back ends are separated: after the user logs in successfully, the back end returns a token, and the front end stores the token locally (localstorage or cookie). Just bring the token with each request.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!