MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / TelegramBind

Function TelegramBind

controller/telegram.go:17–69  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

15)
16
17func TelegramBind(c *gin.Context) {
18 if !common.TelegramOAuthEnabled {
19 c.JSON(200, gin.H{
20 "message": "管理员未开启通过 Telegram 登录以及注册",
21 "success": false,
22 })
23 return
24 }
25 params := c.Request.URL.Query()
26 if !checkTelegramAuthorization(params, common.TelegramBotToken) {
27 c.JSON(200, gin.H{
28 "message": "无效的请求",
29 "success": false,
30 })
31 return
32 }
33 telegramId := params["id"][0]
34 if model.IsTelegramIdAlreadyTaken(telegramId) {
35 c.JSON(200, gin.H{
36 "message": "该 Telegram 账户已被绑定",
37 "success": false,
38 })
39 return
40 }
41
42 session := sessions.Default(c)
43 id := session.Get("id")
44 user := model.User{Id: id.(int)}
45 if err := user.FillUserById(); err != nil {
46 c.JSON(200, gin.H{
47 "message": err.Error(),
48 "success": false,
49 })
50 return
51 }
52 if user.Id == 0 {
53 c.JSON(http.StatusOK, gin.H{
54 "success": false,
55 "message": "用户已注销",
56 })
57 return
58 }
59 user.TelegramId = telegramId
60 if err := user.Update(false); err != nil {
61 c.JSON(200, gin.H{
62 "message": err.Error(),
63 "success": false,
64 })
65 return
66 }
67
68 c.Redirect(302, "/setting")
69}
70
71func TelegramLogin(c *gin.Context) {
72 if !common.TelegramOAuthEnabled {

Callers

nothing calls this directly

Calls 6

FillUserByIdMethod · 0.95
UpdateMethod · 0.95
IsTelegramIdAlreadyTakenFunction · 0.92
GetMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected