i18n: user setting route

pull/1491/head
HFO4 2 years ago
parent 9464ee2103
commit 16d17ac1e6

@ -186,6 +186,8 @@ const (
CodeQQBindOtherAccount = 40067
// QQ 未绑定对应账号
CodeQQNotLinked = 40068
// 密码不正确
CodeIncorrectPassword = 40069
// CodeDBError 数据库操作失败
CodeDBError = 50001
// CodeEncryptError 加密失败

@ -24,7 +24,7 @@ func init() {
func ServeWebDAV(c *gin.Context) {
fs, err := filesystem.NewFileSystemFromContext(c)
if err != nil {
util.Log().Warning("无法为WebDAV初始化文件系统%s", err)
util.Log().Warning("Failed to initialize filesystem for WebDAV%s", err)
return
}

@ -63,7 +63,7 @@ func (service *ListFolderService) List(c *gin.Context) serializer.Response {
// 查找用户
user, err := model.GetUserByID(service.ID)
if err != nil {
return serializer.Err(serializer.CodeUserNotFound, "用户不存在", err)
return serializer.Err(serializer.CodeUserNotFound, "", err)
}
// 创建文件系统

@ -28,36 +28,36 @@ func (service *OneDriveOauthService) Auth(c *gin.Context) serializer.Response {
policyID, ok := util.GetSession(c, "onedrive_oauth_policy").(uint)
if !ok {
return serializer.Err(serializer.CodeNotFound, "授权会话不存在,请重试", nil)
return serializer.Err(serializer.CodeNotFound, "", nil)
}
util.DeleteSession(c, "onedrive_oauth_policy")
policy, err := model.GetPolicyByID(policyID)
if err != nil {
return serializer.Err(serializer.CodeNotFound, "存储策略不存在", nil)
return serializer.Err(serializer.CodePolicyNotExist, "", nil)
}
client, err := onedrive.NewClient(&policy)
if err != nil {
return serializer.Err(serializer.CodeInternalSetting, "无法初始化 OneDrive 客户端", err)
return serializer.Err(serializer.CodeInternalSetting, "Failed to initialize OneDrive client", err)
}
credential, err := client.ObtainToken(c, onedrive.WithCode(service.Code))
if err != nil {
return serializer.Err(serializer.CodeInternalSetting, "AccessToken 获取失败", err)
return serializer.Err(serializer.CodeInternalSetting, "Failed to fetch AccessToken", err)
}
// 更新存储策略的 RefreshToken
client.Policy.AccessKey = credential.RefreshToken
if err := client.Policy.SaveAndClearCache(); err != nil {
return serializer.DBErr("无法更新 RefreshToken", err)
return serializer.DBErr("Failed to update RefreshToken", err)
}
cache.Deletes([]string{client.Policy.AccessKey}, "onedrive_")
if client.Policy.OptionsSerialized.OdDriver != "" && strings.Contains(client.Policy.OptionsSerialized.OdDriver, "http") {
if err := querySharePointSiteID(c, client.Policy); err != nil {
return serializer.Err(serializer.CodeInternalSetting, "无法查询 SharePoint 站点 ID", err)
return serializer.Err(serializer.CodeInternalSetting, "Failed to query SharePoint site ID", err)
}
}

@ -80,7 +80,7 @@ type ThemeChose struct {
func (service *ThemeChose) Update(c *gin.Context, user *model.User) serializer.Response {
user.OptionsSerialized.PreferredTheme = service.Theme
if err := user.UpdateOptions(); err != nil {
return serializer.DBErr("主题切换失败", err)
return serializer.DBErr("Failed to update user preferences", err)
}
return serializer.Response{}
@ -98,25 +98,25 @@ func (service *Enable2FA) Update(c *gin.Context, user *model.User) serializer.Re
// 开启2FA
secret, ok := util.GetSession(c, "2fa_init").(string)
if !ok {
return serializer.Err(serializer.CodeParamErr, "未初始化二步验证", nil)
return serializer.Err(serializer.CodeInternalSetting, "You have not initiated 2FA session", nil)
}
if !totp.Validate(service.Code, secret) {
return serializer.ParamErr("验证码不正确", nil)
return serializer.ParamErr("Incorrect 2FA code", nil)
}
if err := user.Update(map[string]interface{}{"two_factor": secret}); err != nil {
return serializer.DBErr("无法更新二步验证设定", err)
return serializer.DBErr("Failed to update user preferences", err)
}
} else {
// 关闭2FA
if !totp.Validate(service.Code, user.TwoFactor) {
return serializer.ParamErr("验证码不正确", nil)
return serializer.ParamErr("Incorrect 2FA code", nil)
}
if err := user.Update(map[string]interface{}{"two_factor": ""}); err != nil {
return serializer.DBErr("无法更新二步验证设定", err)
return serializer.DBErr("Failed to update user preferences", err)
}
}
@ -130,7 +130,7 @@ func (service *SettingService) Init2FA(c *gin.Context, user *model.User) seriali
AccountName: user.Email,
})
if err != nil {
return serializer.Err(serializer.CodeInternalSetting, "无法生成验密钥", err)
return serializer.Err(serializer.CodeInternalSetting, "Failed to generate TOTP secret", err)
}
util.SetSession(c, map[string]interface{}{"2fa_init": key.Secret()})
@ -141,13 +141,13 @@ func (service *SettingService) Init2FA(c *gin.Context, user *model.User) seriali
func (service *PasswordChange) Update(c *gin.Context, user *model.User) serializer.Response {
// 验证老密码
if ok, _ := user.CheckPassword(service.Old); !ok {
return serializer.Err(serializer.CodeParamErr, "原密码不正确", nil)
return serializer.Err(serializer.CodeIncorrectPassword, "", nil)
}
// 更改为新密码
user.SetPassword(service.New)
if err := user.Update(map[string]interface{}{"password": user.Password}); err != nil {
return serializer.DBErr("密码更换失败", err)
return serializer.DBErr("Failed to update password", err)
}
return serializer.Response{}
@ -157,7 +157,7 @@ func (service *PasswordChange) Update(c *gin.Context, user *model.User) serializ
func (service *HomePage) Update(c *gin.Context, user *model.User) serializer.Response {
user.OptionsSerialized.ProfileOff = !service.Enabled
if err := user.UpdateOptions(); err != nil {
return serializer.DBErr("存储策略切换失败", err)
return serializer.DBErr("Failed to update user preferences", err)
}
return serializer.Response{}
@ -166,7 +166,7 @@ func (service *HomePage) Update(c *gin.Context, user *model.User) serializer.Res
// Update 更改昵称
func (service *ChangerNick) Update(c *gin.Context, user *model.User) serializer.Response {
if err := user.Update(map[string]interface{}{"nick": service.Nick}); err != nil {
return serializer.DBErr("无法更新昵称", err)
return serializer.DBErr("Failed to update user", err)
}
return serializer.Response{}
@ -178,7 +178,7 @@ func (service *AvatarService) Get(c *gin.Context) serializer.Response {
uid, _ := c.Get("object_id")
user, err := model.GetActiveUserByID(uid.(uint))
if err != nil {
return serializer.Err(serializer.CodeNotFound, "用户不存在", err)
return serializer.Err(serializer.CodeUserNotFound, "", err)
}
// 未设定头像时返回404错误
@ -199,7 +199,7 @@ func (service *AvatarService) Get(c *gin.Context) serializer.Response {
server := model.GetSettingByName("gravatar_server")
gravatarRoot, err := url.Parse(server)
if err != nil {
return serializer.Err(serializer.CodeInternalSetting, "无法解析 Gravatar 服务器地址", err)
return serializer.Err(serializer.CodeInternalSetting, "Failed to parse Gravatar server", err)
}
email_lowered := strings.ToLower(user.Email)
has := md5.Sum([]byte(email_lowered))

Loading…
Cancel
Save