feat(user):完成用户登出功能。
This commit is contained in:
parent
61fef8d0fa
commit
73737c3753
|
@ -1,9 +1,11 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"electricity_bill_calc/cache"
|
||||||
"electricity_bill_calc/exceptions"
|
"electricity_bill_calc/exceptions"
|
||||||
"electricity_bill_calc/model"
|
"electricity_bill_calc/model"
|
||||||
"electricity_bill_calc/response"
|
"electricity_bill_calc/response"
|
||||||
|
"electricity_bill_calc/security"
|
||||||
"electricity_bill_calc/service"
|
"electricity_bill_calc/service"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -11,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitializeUserHandlers(router *fiber.App) {
|
func InitializeUserHandlers(router *fiber.App) {
|
||||||
|
router.Delete("/login", security.MustAuthenticated, doLogout)
|
||||||
router.Post("/login", doLogin)
|
router.Post("/login", doLogin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,3 +50,16 @@ func doLogin(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
return result.LoginSuccess(session)
|
return result.LoginSuccess(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doLogout(c *fiber.Ctx) error {
|
||||||
|
result := response.NewResult(c)
|
||||||
|
session := c.Locals("session")
|
||||||
|
if session == nil {
|
||||||
|
return result.Success("用户会话已结束。")
|
||||||
|
}
|
||||||
|
_, err := cache.ClearSession(session.(*model.Session).Token)
|
||||||
|
if err != nil {
|
||||||
|
return result.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return result.Success("用户已成功登出系统。")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user