feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
+38
-21
@@ -25,10 +25,7 @@ import (
|
||||
func TestStatus(c *gin.Context) {
|
||||
err := model.PingDB()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||
"success": false,
|
||||
"message": "数据库连接失败",
|
||||
})
|
||||
writeAccountStatusError(c, http.StatusServiceUnavailable, "Database connection failed")
|
||||
return
|
||||
}
|
||||
// 获取HTTP统计信息
|
||||
@@ -126,6 +123,10 @@ func GetStatus(c *gin.Context) {
|
||||
"user_agreement_enabled": legalSetting.UserAgreement != "",
|
||||
"privacy_policy_enabled": legalSetting.PrivacyPolicy != "",
|
||||
"checkin_enabled": operation_setting.GetCheckinSetting().Enabled,
|
||||
"log_export_enabled": operation_setting.GetLogSetting().UserExportEnabled,
|
||||
"log_max_range_days": operation_setting.GetLogSetting().MaxRangeDays,
|
||||
"quota_remind_enabled": common.QuotaRemindEnabled,
|
||||
"quota_remind_threshold": common.QuotaRemindThreshold,
|
||||
}
|
||||
|
||||
// 根据启用状态注入可选内容
|
||||
@@ -223,15 +224,21 @@ func SendEmailVerification(c *gin.Context) {
|
||||
}
|
||||
|
||||
if model.IsEmailAlreadyTaken(email) {
|
||||
common.ApiErrorI18n(c, i18n.MsgUserEmailAlreadyTaken)
|
||||
common.ApiErrorT(c, "Email address is already in use")
|
||||
return
|
||||
}
|
||||
code := common.GenerateVerificationCode(6)
|
||||
common.RegisterVerificationCodeWithKey(email, code, common.EmailVerificationPurpose)
|
||||
subject := fmt.Sprintf("%s邮箱验证邮件", common.SystemName)
|
||||
content := fmt.Sprintf("<p>您好,你正在进行%s邮箱验证。</p>"+
|
||||
"<p>您的验证码为: <strong>%s</strong></p>"+
|
||||
"<p>验证码 %d 分钟内有效,如果不是本人操作,请忽略。</p>", common.SystemName, code, common.VerificationValidMinutes)
|
||||
// The address may not belong to an account yet, so the mail follows the
|
||||
// request language.
|
||||
systemName := map[string]any{"SystemName": common.SystemName}
|
||||
subject := i18n.T(c, i18n.MsgEmailVerificationSubject, systemName)
|
||||
content := fmt.Sprintf("<p>%s</p>"+
|
||||
"<p>%s</p>"+
|
||||
"<p>%s</p>",
|
||||
i18n.T(c, i18n.MsgEmailVerificationGreeting, systemName),
|
||||
i18n.T(c, i18n.MsgEmailVerificationCode, map[string]any{"Code": code}),
|
||||
i18n.T(c, i18n.MsgEmailVerificationValidity, map[string]any{"Minutes": common.VerificationValidMinutes}))
|
||||
err = common.SendEmail(subject, email, content)
|
||||
if err != nil {
|
||||
common.ApiError(c, err)
|
||||
@@ -247,24 +254,34 @@ func SendEmailVerification(c *gin.Context) {
|
||||
func SendPasswordResetEmail(c *gin.Context) {
|
||||
email := model.NormalizeEmail(c.Query("email"))
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
|
||||
common.ApiErrorT(c, "Invalid parameters")
|
||||
return
|
||||
}
|
||||
if _, err := model.GetUniqueUserByEmail(email); err == nil {
|
||||
if user, err := model.GetUniqueUserByEmail(email); err == nil {
|
||||
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)
|
||||
lang := user.GetSetting().Language
|
||||
if lang == "" {
|
||||
lang = i18n.StatedLang(c)
|
||||
}
|
||||
systemName := map[string]any{"SystemName": common.SystemName}
|
||||
linkParams := map[string]any{"Link": link}
|
||||
subject := i18n.Translate(lang, i18n.MsgEmailPasswordResetSubject, systemName)
|
||||
content := fmt.Sprintf("<p>%s</p>"+
|
||||
"<p>%s</p>"+
|
||||
"<p>%s </p>"+
|
||||
"<p>%s</p>",
|
||||
i18n.Translate(lang, i18n.MsgEmailPasswordResetGreeting, systemName),
|
||||
i18n.Translate(lang, i18n.MsgEmailPasswordResetLink, linkParams),
|
||||
i18n.Translate(lang, i18n.MsgEmailPasswordResetLinkFallback, linkParams),
|
||||
i18n.Translate(lang, i18n.MsgEmailPasswordResetValidity, map[string]any{"Minutes": 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()))
|
||||
logger.LogError(c.Request.Context(), common.LogText("failed to send password reset email to %s: %s", email, err.Error()))
|
||||
}
|
||||
} else if err != nil && !errors.Is(err, model.ErrEmailNotFound) {
|
||||
logger.LogWarn(c.Request.Context(), fmt.Sprintf("skip password reset email for %s: %s", email, err.Error()))
|
||||
logger.LogWarn(c.Request.Context(), common.LogText("skip password reset email for %s: %s", email, err.Error()))
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
@@ -286,18 +303,18 @@ func ResetPassword(c *gin.Context) {
|
||||
}
|
||||
req.Email = model.NormalizeEmail(req.Email)
|
||||
if req.Email == "" || req.Token == "" {
|
||||
common.ApiErrorI18n(c, i18n.MsgInvalidParams)
|
||||
common.ApiErrorT(c, "Invalid parameters")
|
||||
return
|
||||
}
|
||||
if !common.VerifyCodeWithKey(req.Email, req.Token, common.PasswordResetPurpose) {
|
||||
common.ApiErrorI18n(c, i18n.MsgUserPasswordResetLinkInvalid)
|
||||
common.ApiErrorT(c, "Password reset link is invalid or has expired")
|
||||
return
|
||||
}
|
||||
password := common.GenerateVerificationCode(12)
|
||||
err = model.ResetUserPasswordByEmail(req.Email, password)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrEmailNotFound) || errors.Is(err, model.ErrEmailAmbiguous) {
|
||||
common.ApiErrorI18n(c, i18n.MsgUserPasswordResetLinkInvalid)
|
||||
common.ApiErrorT(c, "Password reset link is invalid or has expired")
|
||||
return
|
||||
}
|
||||
common.ApiError(c, err)
|
||||
|
||||
Reference in new issue
Block a user