(c *gin.Context)
| 302 | } |
| 303 | |
| 304 | func GenerateAccessToken(c *gin.Context) { |
| 305 | id := c.GetInt("id") |
| 306 | user, err := model.GetUserById(id, true) |
| 307 | if err != nil { |
| 308 | common.ApiError(c, err) |
| 309 | return |
| 310 | } |
| 311 | // get rand int 28-32 |
| 312 | randI := common.GetRandomInt(4) |
| 313 | key, err := common.GenerateRandomKey(29 + randI) |
| 314 | if err != nil { |
| 315 | c.JSON(http.StatusOK, gin.H{ |
| 316 | "success": false, |
| 317 | "message": "生成失败", |
| 318 | }) |
| 319 | common.SysError("failed to generate key: " + err.Error()) |
| 320 | return |
| 321 | } |
| 322 | user.SetAccessToken(key) |
| 323 | |
| 324 | if model.DB.Where("access_token = ?", user.AccessToken).First(user).RowsAffected != 0 { |
| 325 | c.JSON(http.StatusOK, gin.H{ |
| 326 | "success": false, |
| 327 | "message": "请重试,系统生成的 UUID 竟然重复了!", |
| 328 | }) |
| 329 | return |
| 330 | } |
| 331 | |
| 332 | if err := user.Update(false); err != nil { |
| 333 | common.ApiError(c, err) |
| 334 | return |
| 335 | } |
| 336 | |
| 337 | c.JSON(http.StatusOK, gin.H{ |
| 338 | "success": true, |
| 339 | "message": "", |
| 340 | "data": user.AccessToken, |
| 341 | }) |
| 342 | return |
| 343 | } |
| 344 | |
| 345 | type TransferAffQuotaRequest struct { |
| 346 | Quota int `json:"quota" binding:"required"` |
nothing calls this directly
no test coverage detected