(c *gin.Context)
| 69 | } |
| 70 | |
| 71 | func TelegramLogin(c *gin.Context) { |
| 72 | if !common.TelegramOAuthEnabled { |
| 73 | c.JSON(200, gin.H{ |
| 74 | "message": "管理员未开启通过 Telegram 登录以及注册", |
| 75 | "success": false, |
| 76 | }) |
| 77 | return |
| 78 | } |
| 79 | params := c.Request.URL.Query() |
| 80 | if !checkTelegramAuthorization(params, common.TelegramBotToken) { |
| 81 | c.JSON(200, gin.H{ |
| 82 | "message": "无效的请求", |
| 83 | "success": false, |
| 84 | }) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | telegramId := params["id"][0] |
| 89 | user := model.User{TelegramId: telegramId} |
| 90 | if err := user.FillUserByTelegramId(); err != nil { |
| 91 | c.JSON(200, gin.H{ |
| 92 | "message": err.Error(), |
| 93 | "success": false, |
| 94 | }) |
| 95 | return |
| 96 | } |
| 97 | setupLogin(&user, c) |
| 98 | } |
| 99 | |
| 100 | func checkTelegramAuthorization(params map[string][]string, token string) bool { |
| 101 | strs := []string{} |
nothing calls this directly
no test coverage detected