mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-15 23:54:30 +00:00
feat: update i18n messages and improve error handling
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/songquanpeng/one-api/common"
|
||||
"github.com/songquanpeng/one-api/common/config"
|
||||
"github.com/songquanpeng/one-api/common/i18n"
|
||||
"github.com/songquanpeng/one-api/common/message"
|
||||
"github.com/songquanpeng/one-api/model"
|
||||
|
||||
@@ -86,7 +87,7 @@ func SendEmailVerification(c *gin.Context) {
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -121,7 +122,6 @@ func SendEmailVerification(c *gin.Context) {
|
||||
"<p>验证码 %d 分钟内有效,如果不是本人操作,请忽略。</p>", config.SystemName, code, common.VerificationValidMinutes)
|
||||
err := message.SendEmail(subject, email, content)
|
||||
if err != nil {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": err.Error(),
|
||||
@@ -140,7 +140,7 @@ func SendPasswordResetEmail(c *gin.Context) {
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func SendPasswordResetEmail(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": err.Error(),
|
||||
"message": fmt.Sprintf("%s%s", i18n.Translate(c, "send_email_failed"), err.Error()),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func ResetPassword(c *gin.Context) {
|
||||
if req.Email == "" || req.Token == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@@ -2,12 +2,14 @@ package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/songquanpeng/one-api/common/config"
|
||||
"github.com/songquanpeng/one-api/common/helper"
|
||||
"github.com/songquanpeng/one-api/model"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/songquanpeng/one-api/common/config"
|
||||
"github.com/songquanpeng/one-api/common/helper"
|
||||
"github.com/songquanpeng/one-api/common/i18n"
|
||||
"github.com/songquanpeng/one-api/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -38,7 +40,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ func Login(c *gin.Context) {
|
||||
err := json.NewDecoder(c.Request.Body).Decode(&loginRequest)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -44,7 +44,7 @@ func Login(c *gin.Context) {
|
||||
password := loginRequest.Password
|
||||
if username == "" || password == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -131,7 +131,7 @@ func Register(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -371,7 +371,7 @@ func UpdateUser(c *gin.Context) {
|
||||
if err != nil || updatedUser.Id == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -435,7 +435,7 @@ func UpdateSelf(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -545,7 +545,7 @@ func CreateUser(c *gin.Context) {
|
||||
if err != nil || user.Username == "" || user.Password == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -601,7 +601,7 @@ func ManageUser(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": i18n.Translate(c, "invalid_parameter"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user