MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / WeChatAuth

Function WeChatAuth

controller/wechat.go:54–121  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

52}
53
54func WeChatAuth(c *gin.Context) {
55 if !common.WeChatAuthEnabled {
56 c.JSON(http.StatusOK, gin.H{
57 "message": "管理员未开启通过微信登录以及注册",
58 "success": false,
59 })
60 return
61 }
62 code := c.Query("code")
63 wechatId, err := getWeChatIdByCode(code)
64 if err != nil {
65 c.JSON(http.StatusOK, gin.H{
66 "message": err.Error(),
67 "success": false,
68 })
69 return
70 }
71 user := model.User{
72 WeChatId: wechatId,
73 }
74 if model.IsWeChatIdAlreadyTaken(wechatId) {
75 err := user.FillUserByWeChatId()
76 if err != nil {
77 c.JSON(http.StatusOK, gin.H{
78 "success": false,
79 "message": err.Error(),
80 })
81 return
82 }
83 if user.Id == 0 {
84 c.JSON(http.StatusOK, gin.H{
85 "success": false,
86 "message": "用户已注销",
87 })
88 return
89 }
90 } else {
91 if common.RegisterEnabled {
92 user.Username = "wechat_" + strconv.Itoa(model.GetMaxUserId()+1)
93 user.DisplayName = "WeChat User"
94 user.Role = common.RoleCommonUser
95 user.Status = common.UserStatusEnabled
96
97 if err := user.Insert(0); err != nil {
98 c.JSON(http.StatusOK, gin.H{
99 "success": false,
100 "message": err.Error(),
101 })
102 return
103 }
104 } else {
105 c.JSON(http.StatusOK, gin.H{
106 "success": false,
107 "message": "管理员关闭了新用户注册",
108 })
109 return
110 }
111 }

Callers

nothing calls this directly

Calls 7

FillUserByWeChatIdMethod · 0.95
InsertMethod · 0.95
IsWeChatIdAlreadyTakenFunction · 0.92
GetMaxUserIdFunction · 0.92
getWeChatIdByCodeFunction · 0.85
setupLoginFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected