mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-06 10:57:50 +08:00
优化cookie登录逻辑
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
Linux_Python / build (push) Has been cancelled
macOS / build (push) Has been cancelled
macOS_Python / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Windows_Python / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
Linux_Python / build (push) Has been cancelled
macOS / build (push) Has been cancelled
macOS_Python / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Windows_Python / build (push) Has been cancelled
This commit is contained in:
parent
3514376a97
commit
0ead9b6945
@ -2428,12 +2428,7 @@ void installWebApi() {
|
||||
|
||||
api_regist("/index/api/login", [](API_ARGS_MAP) {
|
||||
auto logined_cookie = HttpCookieManager::Instance().getCookie(kLoginedCookieName, allArgs.getParser().getHeader());
|
||||
if (logined_cookie) {
|
||||
// 已经登录成功
|
||||
val["code"] = API::Success;
|
||||
val["msg"] = "You are already logined";
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_ARGS("digest");
|
||||
GET_CONFIG(std::string, api_secret, API::kSecret);
|
||||
|
||||
@ -2446,11 +2441,19 @@ void installWebApi() {
|
||||
headerOut["Set-Cookie"] = unlogin_cookie->getCookie(kLoginCookiePath);
|
||||
}
|
||||
val["cookie"] = unlogin_cookie->getCookie();
|
||||
if (logined_cookie) {
|
||||
// secret校验失败,注销登录
|
||||
logined_cookie->setExpired();
|
||||
HttpCookieManager::Instance().delCookie(logined_cookie);
|
||||
headerOut.emplace_force("Set-Cookie", logined_cookie->getCookie(kLoginCookiePath));
|
||||
}
|
||||
throw AuthException("Digest does not match, incorrect secret?", headerOut, val);
|
||||
}
|
||||
// 登录成功, cookie保持24小时
|
||||
logined_cookie = HttpCookieManager::Instance().addCookie(kLoginedCookieName, "", kLoginedCookieLifeSeconds);
|
||||
headerOut["Set-Cookie"] = logined_cookie->getCookie(kLoginCookiePath);
|
||||
if (!logined_cookie) {
|
||||
// 未登陆状态,设置登录成功, cookie保持24小时
|
||||
logined_cookie = HttpCookieManager::Instance().addCookie(kLoginedCookieName, "", kLoginedCookieLifeSeconds);
|
||||
headerOut["Set-Cookie"] = logined_cookie->getCookie(kLoginCookiePath);
|
||||
}
|
||||
|
||||
// 删除未登录状态的cookie
|
||||
unlogin_cookie->setExpired();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user