Feat: works on my machine
This commit is contained in:
39
handlers/auth/postLogout.go
Normal file
39
handlers/auth/postLogout.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.konchin.com/ytshih/inp2025/middlewares"
|
||||
"gitea.konchin.com/ytshih/inp2025/models"
|
||||
"gitea.konchin.com/ytshih/inp2025/types"
|
||||
"gitea.konchin.com/ytshih/inp2025/utils"
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
func (self *Handlers) PostLogout(
|
||||
w http.ResponseWriter,
|
||||
req bunrouter.Request,
|
||||
) error {
|
||||
ctx := req.Context()
|
||||
user, ok := ctx.Value(types.UserKey).(models.User)
|
||||
if !ok {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Message: "user not login",
|
||||
}
|
||||
}
|
||||
|
||||
_, err := self.db.NewUpdate().
|
||||
Set("is_logged = ?", false).
|
||||
Where("username = ?", user.Username).
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Message: "failed to update logged in status",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
return utils.Success(w)
|
||||
}
|
||||
Reference in New Issue
Block a user