This commit is contained in:
2024-07-10 12:14:25 +07:00
parent 465e77832e
commit 75abc7e651
5 changed files with 16 additions and 2 deletions
+1
View File
@@ -28,6 +28,7 @@ func InitRouter() *gin.Engine {
r.POST("/v1/users/register", v1.PostUserRegister)
r.POST("/v1/users/login", v1.PostUserLogin)
r.POST("/v1/users/omvlogin", v1.PostOMVLogin)
r.POST("/v1/users/logout", v1.PostLogout)
r.GET("/v1/users/name", v1.GetUserAllUsername) // all/name
r.POST("/v1/users/refresh", v1.PostUserRefreshToken)
// No short-term modifications
+12 -1
View File
@@ -99,7 +99,6 @@ func PostUserRegister(c *gin.Context) {
user.Username = username
user.Password = encryption.GetMD5ByStr(pwd)
user.Role = role
// user.Role = "user"
user = service.MyService.User().CreateUser(user)
if user.Id == 0 {
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
@@ -263,6 +262,18 @@ func PostOMVLogin(c *gin.Context) {
})
}
func PostLogout(c *gin.Context) {
cookies := c.Request.Cookies()
for _, cookie := range cookies {
// Set the cookie to expire immediately
c.SetCookie(cookie.Name, "", -1, "/", "", false, true)
}
c.JSON(common_err.SUCCESS,
model.Result{
Success: common_err.SUCCESS,
Message: common_err.GetMsg(common_err.SUCCESS),
})
}
func isEmpty(obj interface{}) bool {
jsonData, err := json.Marshal(obj)