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

Function Register

controller/user.go:116–244  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

114}
115
116func Register(c *gin.Context) {
117 if !common.RegisterEnabled {
118 c.JSON(http.StatusOK, gin.H{
119 "message": "管理员关闭了新用户注册",
120 "success": false,
121 })
122 return
123 }
124 if !common.PasswordRegisterEnabled {
125 c.JSON(http.StatusOK, gin.H{
126 "message": "管理员关闭了通过密码进行注册,请使用第三方账户验证的形式进行注册",
127 "success": false,
128 })
129 return
130 }
131 var user model.User
132 err := json.NewDecoder(c.Request.Body).Decode(&user)
133 if err != nil {
134 c.JSON(http.StatusOK, gin.H{
135 "success": false,
136 "message": "无效的参数",
137 })
138 return
139 }
140 if err := common.Validate.Struct(&user); err != nil {
141 c.JSON(http.StatusOK, gin.H{
142 "success": false,
143 "message": "输入不合法 " + err.Error(),
144 })
145 return
146 }
147 if common.EmailVerificationEnabled {
148 if user.Email == "" || user.VerificationCode == "" {
149 c.JSON(http.StatusOK, gin.H{
150 "success": false,
151 "message": "管理员开启了邮箱验证,请输入邮箱地址和验证码",
152 })
153 return
154 }
155 if !common.VerifyCodeWithKey(user.Email, user.VerificationCode, common.EmailVerificationPurpose) {
156 c.JSON(http.StatusOK, gin.H{
157 "success": false,
158 "message": "验证码错误或已过期",
159 })
160 return
161 }
162 }
163 exist, err := model.CheckUserExistOrDeleted(user.Username, user.Email)
164 if err != nil {
165 c.JSON(http.StatusOK, gin.H{
166 "success": false,
167 "message": "数据库错误,请稍后重试",
168 })
169 common.SysError(fmt.Sprintf("CheckUserExistOrDeleted error: %v", err))
170 return
171 }
172 if exist {
173 c.JSON(http.StatusOK, gin.H{

Callers

nothing calls this directly

Calls 10

InsertMethod · 0.95
InsertMethod · 0.95
VerifyCodeWithKeyFunction · 0.92
CheckUserExistOrDeletedFunction · 0.92
SysErrorFunction · 0.92
GetUserIdByAffCodeFunction · 0.92
ApiErrorFunction · 0.92
GenerateKeyFunction · 0.92
GetTimestampFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected