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

Function SendEmailVerification

controller/misc.go:160–229  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

158}
159
160func SendEmailVerification(c *gin.Context) {
161 email := c.Query("email")
162 if err := common.Validate.Var(email, "required,email"); err != nil {
163 c.JSON(http.StatusOK, gin.H{
164 "success": false,
165 "message": "无效的参数",
166 })
167 return
168 }
169 parts := strings.Split(email, "@")
170 if len(parts) != 2 {
171 c.JSON(http.StatusOK, gin.H{
172 "success": false,
173 "message": "无效的邮箱地址",
174 })
175 return
176 }
177 localPart := parts[0]
178 domainPart := parts[1]
179 if common.EmailDomainRestrictionEnabled {
180 allowed := false
181 for _, domain := range common.EmailDomainWhitelist {
182 if domainPart == domain {
183 allowed = true
184 break
185 }
186 }
187 if !allowed {
188 c.JSON(http.StatusOK, gin.H{
189 "success": false,
190 "message": "The administrator has enabled the email domain name whitelist, and your email address is not allowed due to special symbols or it's not in the whitelist.",
191 })
192 return
193 }
194 }
195 if common.EmailAliasRestrictionEnabled {
196 containsSpecialSymbols := strings.Contains(localPart, "+") || strings.Contains(localPart, ".")
197 if containsSpecialSymbols {
198 c.JSON(http.StatusOK, gin.H{
199 "success": false,
200 "message": "管理员已启用邮箱地址别名限制,您的邮箱地址由于包含特殊符号而被拒绝。",
201 })
202 return
203 }
204 }
205
206 if model.IsEmailAlreadyTaken(email) {
207 c.JSON(http.StatusOK, gin.H{
208 "success": false,
209 "message": "邮箱地址已被占用",
210 })
211 return
212 }
213 code := common.GenerateVerificationCode(6)
214 common.RegisterVerificationCodeWithKey(email, code, common.EmailVerificationPurpose)
215 subject := fmt.Sprintf("%s邮箱验证邮件", common.SystemName)
216 content := fmt.Sprintf("<p>您好,你正在进行%s邮箱验证。</p>"+
217 "<p>您的验证码为: <strong>%s</strong></p>"+

Callers

nothing calls this directly

Calls 6

IsEmailAlreadyTakenFunction · 0.92
GenerateVerificationCodeFunction · 0.92
SendEmailFunction · 0.92
ApiErrorFunction · 0.92
ContainsMethod · 0.80

Tested by

no test coverage detected