41 lines
886 B
Go
41 lines
886 B
Go
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().
|
|
Model((*models.User)(nil)).
|
|
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)
|
|
}
|