|
|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
|
"github.com/QuantumNous/new-api/constant"
|
|
|
+ "github.com/QuantumNous/new-api/logger"
|
|
|
"github.com/QuantumNous/new-api/middleware"
|
|
|
"github.com/QuantumNous/new-api/model"
|
|
|
"github.com/QuantumNous/new-api/oauth"
|
|
|
@@ -116,7 +117,6 @@ func GetStatus(c *gin.Context) {
|
|
|
"user_agreement_enabled": legalSetting.UserAgreement != "",
|
|
|
"privacy_policy_enabled": legalSetting.PrivacyPolicy != "",
|
|
|
"checkin_enabled": operation_setting.GetCheckinSetting().Enabled,
|
|
|
- "_qn": "new-api",
|
|
|
}
|
|
|
|
|
|
// 根据启用状态注入可选内容
|
|
|
@@ -308,31 +308,24 @@ func SendPasswordResetEmail(c *gin.Context) {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if !model.IsEmailAlreadyTaken(email) {
|
|
|
- c.JSON(http.StatusOK, gin.H{
|
|
|
- "success": false,
|
|
|
- "message": "该邮箱地址未注册",
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- code := common.GenerateVerificationCode(0)
|
|
|
- common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
|
|
|
- link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", system_setting.ServerAddress, email, code)
|
|
|
- subject := fmt.Sprintf("%s密码重置", common.SystemName)
|
|
|
- content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
|
|
|
- "<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
|
|
|
- "<p>如果链接无法点击,请尝试点击下面的链接或将其复制到浏览器中打开:<br> %s </p>"+
|
|
|
- "<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>", common.SystemName, link, link, common.VerificationValidMinutes)
|
|
|
- err := common.SendEmail(subject, email, content)
|
|
|
- if err != nil {
|
|
|
- common.ApiError(c, err)
|
|
|
- return
|
|
|
+ if model.IsEmailAlreadyTaken(email) {
|
|
|
+ code := common.GenerateVerificationCode(0)
|
|
|
+ common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
|
|
|
+ link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", system_setting.ServerAddress, email, code)
|
|
|
+ subject := fmt.Sprintf("%s密码重置", common.SystemName)
|
|
|
+ content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
|
|
|
+ "<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
|
|
|
+ "<p>如果链接无法点击,请尝试点击下面的链接或将其复制到浏览器中打开:<br> %s </p>"+
|
|
|
+ "<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>", common.SystemName, link, link, common.VerificationValidMinutes)
|
|
|
+ err := common.SendEmail(subject, email, content)
|
|
|
+ if err != nil {
|
|
|
+ logger.LogError(c.Request.Context(), fmt.Sprintf("failed to send password reset email to %s: %s", email, err.Error()))
|
|
|
+ }
|
|
|
}
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
"success": true,
|
|
|
"message": "",
|
|
|
})
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
type PasswordResetRequest struct {
|