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

Function SendPasswordResetEmail

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

Source from the content-addressed store, hash-verified

229}
230
231func SendPasswordResetEmail(c *gin.Context) {
232 email := c.Query("email")
233 if err := common.Validate.Var(email, "required,email"); err != nil {
234 c.JSON(http.StatusOK, gin.H{
235 "success": false,
236 "message": "无效的参数",
237 })
238 return
239 }
240 if !model.IsEmailAlreadyTaken(email) {
241 c.JSON(http.StatusOK, gin.H{
242 "success": false,
243 "message": "该邮箱地址未注册",
244 })
245 return
246 }
247 code := common.GenerateVerificationCode(0)
248 common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
249 link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", setting.ServerAddress, email, code)
250 subject := fmt.Sprintf("%s密码重置", common.SystemName)
251 content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
252 "<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
253 "<p>如果链接无法点击,请尝试点击下面的链接或将其复制到浏览器中打开:<br> %s </p>"+
254 "<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>", common.SystemName, link, link, common.VerificationValidMinutes)
255 err := common.SendEmail(subject, email, content)
256 if err != nil {
257 common.ApiError(c, err)
258 return
259 }
260 c.JSON(http.StatusOK, gin.H{
261 "success": true,
262 "message": "",
263 })
264 return
265}
266
267type PasswordResetRequest struct {
268 Email string `json:"email"`

Callers

nothing calls this directly

Calls 5

IsEmailAlreadyTakenFunction · 0.92
GenerateVerificationCodeFunction · 0.92
SendEmailFunction · 0.92
ApiErrorFunction · 0.92

Tested by

no test coverage detected