Feat: works on my machine

This commit is contained in:
2025-10-16 05:07:56 +08:00
commit 5bbab63a2c
37 changed files with 4553 additions and 0 deletions

View 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)
}