SignUp 用户注册
(ctx *gin.Context)
| 58 | |
| 59 | // SignUp 用户注册 |
| 60 | func (uh *UserHandler) SignUp(ctx *gin.Context) { |
| 61 | var req req.SignUpReq |
| 62 | if err := ctx.ShouldBindJSON(&req); err != nil { |
| 63 | apiresponse.ErrorWithMessage(ctx, "无效的请求参数") |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | if req.Password != req.ConfirmPassword { |
| 68 | apiresponse.ErrorWithMessage(ctx, UserPasswordMismatchError) |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | // 尝试注册用户 |
| 73 | err := uh.svc.SignUp(ctx.Request.Context(), domain.User{ |
| 74 | Username: req.Username, |
| 75 | Password: req.Password, |
| 76 | }) |
| 77 | |
| 78 | if err != nil { |
| 79 | apiresponse.ErrorWithData(ctx, err) |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | apiresponse.Success(ctx) |
| 84 | } |
| 85 | |
| 86 | // Login 用户登录 |
| 87 | func (uh *UserHandler) Login(ctx *gin.Context) { |
nothing calls this directly
no test coverage detected