Feat: add login
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"gitea.konchin.com/go2025/backend/utils"
|
||||
"gitea.konchin.com/go2025/backend/middlewares"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
@@ -24,5 +27,38 @@ type postGenLoginUrlOutput struct {
|
||||
func (self *Handlers) PostGenLoginUrl(
|
||||
w http.ResponseWriter, req bunrouter.Request,
|
||||
) error {
|
||||
return utils.Success(w)
|
||||
ctx := req.Context()
|
||||
|
||||
b, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Message: "failed to read payload",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
var input postGenLoginUrlInput
|
||||
if err := json.Unmarshal(b, &input); err != nil {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Message: "failed to unmarshal json",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
token, err := self.db.UpdateLoginToken(ctx, input.UserId)
|
||||
if err != nil {
|
||||
return middlewares.HTTPError{
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
Message: "failed to update token",
|
||||
OriginError: err,
|
||||
}
|
||||
}
|
||||
|
||||
return bunrouter.JSON(w, postGenLoginUrlOutput{
|
||||
LoginUrl: viper.GetString("extern-url") +
|
||||
"/auth/login?" +
|
||||
"token=" + token,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user