Draft: big refactor
This commit is contained in:
37
server/backend/auth/getLogin.go
Normal file
37
server/backend/auth/getLogin.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gitea.konchin.com/ytshih/inp2025/game/models"
|
||||
"gitea.konchin.com/ytshih/inp2025/game/server/middlewares"
|
||||
"gitea.konchin.com/ytshih/inp2025/game/types"
|
||||
"gitea.konchin.com/ytshih/inp2025/game/utils"
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
func (self *Handlers) GetLogin(
|
||||
w http.ResponseWriter,
|
||||
req bunrouter.Request,
|
||||
) error {
|
||||
ctx := req.Context()
|
||||
user, ok := ctx.Value(types.User("")).(models.User)
|
||||
if !ok {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Message: "user not found",
|
||||
}
|
||||
}
|
||||
|
||||
err := self.db.InsertUserStatus(ctx,
|
||||
models.UserStatus{Username: user.Username})
|
||||
if err != nil {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Message: "failed to update user status",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
return utils.Success(w)
|
||||
}
|
||||
Reference in New Issue
Block a user