89 lines
2.1 KiB
Go
Raw Normal View History

2023-06-04 22:54:54 +08:00
package apps
import (
"ai-gateway/common/constant"
"ai-gateway/common/dto"
"ai-gateway/common/utils"
"ai-gateway/infrastructure/repository"
"ai-gateway/service"
2024-02-21 12:04:40 +08:00
"context"
2023-06-04 22:54:54 +08:00
"github.com/labstack/echo/v4"
"net/http"
)
func InitUserGroup(g *echo.Group) {
2024-04-29 19:35:18 +08:00
//注册
2024-05-15 14:24:48 +08:00
g.POST("register", func(c echo.Context) error {
2024-04-29 19:35:18 +08:00
req := new(dto.ThirdRegisterReq)
if err := c.Bind(req); err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
err := service.Login.Register(ctx, *req)
if err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
2024-05-15 13:53:27 +08:00
//登录
token, _ := service.Login.Login(ctx, dto.ThirdLoginReq{
Account: req.Account,
Password: req.Password,
})
return c.JSON(http.StatusOK, utils.Ok(token))
2024-04-29 19:35:18 +08:00
})
//登录
2024-05-15 14:24:48 +08:00
g.POST("login", func(c echo.Context) error {
2023-06-04 22:54:54 +08:00
req := new(dto.ThirdLoginReq)
if err := c.Bind(req); err != nil {
2024-04-29 19:35:18 +08:00
return c.JSON(http.StatusOK, utils.Error(err))
2023-06-04 22:54:54 +08:00
}
2024-02-21 12:04:40 +08:00
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
2023-06-04 22:54:54 +08:00
token, err := service.Login.Login(ctx, *req)
if err != nil {
2024-04-29 19:35:18 +08:00
return c.JSON(http.StatusOK, utils.Error(err))
2023-06-04 22:54:54 +08:00
}
return c.JSON(http.StatusOK, utils.Ok(token))
})
2024-04-29 19:35:18 +08:00
//发送 重置密码 验证码
2024-05-15 14:24:48 +08:00
g.POST("sendResetPwdCode", func(c echo.Context) error {
2024-04-29 19:35:18 +08:00
req := new(dto.SendResetPwdCodeReq)
if err := c.Bind(req); err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
err := service.Login.SendResetPwdCode(context.Background(), req.Account)
if err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
return c.JSON(http.StatusOK, utils.Ok(true))
})
//重置密码
2024-05-15 14:24:48 +08:00
g.POST("resetPwd", func(c echo.Context) error {
2024-04-29 19:35:18 +08:00
req := new(dto.ThirdResetPwdReq)
if err := c.Bind(req); err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
ctx := context.WithValue(context.Background(), constant.DBKey, repository.Db)
err := service.Login.ResetPwd(ctx, *req)
if err != nil {
return c.JSON(http.StatusOK, utils.Error(err))
}
return c.JSON(http.StatusOK, utils.Ok(true))
})
2023-06-04 22:54:54 +08:00
}