Register User Login @Summary User Login @Description User Login @Tags User @Accept json @Produce json @Param user body LoginRequest true "User Login Request Data" @Success 200 {object} model.CommonResponse{data=LoginResponse} "Success" @Router /api/login [post]
(c *gin.Context)
| 75 | // @Success 200 {object} model.CommonResponse{data=LoginResponse} "Success" |
| 76 | // @Router /api/login [post] |
| 77 | func Login(c *gin.Context) { |
| 78 | var loginRequest LoginRequest |
| 79 | err := json.NewDecoder(c.Request.Body).Decode(&loginRequest) |
| 80 | if err != nil { |
| 81 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | username := loginRequest.Username |
| 86 | password := loginRequest.Password |
| 87 | eid := config.GetEID(c) |
| 88 | |
| 89 | isEmail := helper.IsValidEmail(username) |
| 90 | isMobile := helper.IsValidPhone(username) |
| 91 | |
| 92 | var user model.User |
| 93 | if isEmail { |
| 94 | user, err = model.GetUserByEmail(eid, username) |
| 95 | } else if isMobile { |
| 96 | user, err = model.GetUserByMobile(eid, username) |
| 97 | } else { |
| 98 | } |
| 99 | |
| 100 | if err != nil { |
| 101 | c.JSON(http.StatusUnauthorized, model.UnauthorizedError.ToResponse(err)) |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | err = user.VerifyPassword(password) |
| 106 | if err != nil { |
| 107 | c.JSON(http.StatusUnauthorized, model.UnauthorizedError.ToResponse(err)) |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | err = user.RefreshAccessToken() |
| 112 | if err != nil { |
| 113 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err)) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | err = user.UpdateStatusToJoin() |
| 118 | if err != nil { |
| 119 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err)) |
| 120 | } |
| 121 | service.InvalidateInternalUserListCache(eid) |
| 122 | |
| 123 | // log := model.SystemLog{ |
| 124 | // Eid: eid, |
| 125 | // UserID: user.UserID, |
| 126 | // Nickname: user.Nickname, |
| 127 | // Module: model.SystemLogModuleSystem, |
| 128 | // Action: model.SystemLogActionLoginOut, |
| 129 | // Content: "登录", |
| 130 | // IP: utils.GetClientIP(c), |
| 131 | // } |
| 132 | // model.CreateSystemLog(&log) |
| 133 | |
| 134 | loginResponse := LoginResponse{ |
nothing calls this directly
no test coverage detected