mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-11-04 14:22:51 +00:00 
			
		
		
		
	update to use WebI18n func
This commit is contained in:
		
							parent
							
								
									2bd706aa92
								
							
						
					
					
						commit
						9b7cddbec7
					
				
					 5 changed files with 41 additions and 41 deletions
				
			
		| 
						 | 
					@ -60,7 +60,7 @@ func (a *InboundController) getInbounds(c *gin.Context) {
 | 
				
			||||||
	user := session.GetLoginUser(c)
 | 
						user := session.GetLoginUser(c)
 | 
				
			||||||
	inbounds, err := a.inboundService.GetInbounds(user.Id)
 | 
						inbounds, err := a.inboundService.GetInbounds(user.Id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.toasts.obtain"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.toasts.obtain"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonObj(c, inbounds, nil)
 | 
						jsonObj(c, inbounds, nil)
 | 
				
			||||||
| 
						 | 
					@ -68,12 +68,12 @@ func (a *InboundController) getInbounds(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) getInbound(c *gin.Context) {
 | 
					func (a *InboundController) getInbound(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "get"), err)
 | 
							jsonMsg(c, WebI18n(c, "get"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	inbound, err := a.inboundService.GetInbound(id)
 | 
						inbound, err := a.inboundService.GetInbound(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.toasts.obtain"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.toasts.obtain"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonObj(c, inbound, nil)
 | 
						jsonObj(c, inbound, nil)
 | 
				
			||||||
| 
						 | 
					@ -93,7 +93,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
 | 
				
			||||||
	inbound := &model.Inbound{}
 | 
						inbound := &model.Inbound{}
 | 
				
			||||||
	err := c.ShouldBind(inbound)
 | 
						err := c.ShouldBind(inbound)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.create"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.create"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	user := session.GetLoginUser(c)
 | 
						user := session.GetLoginUser(c)
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
 | 
				
			||||||
	inbound.Enable = true
 | 
						inbound.Enable = true
 | 
				
			||||||
	inbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port)
 | 
						inbound.Tag = fmt.Sprintf("inbound-%v", inbound.Port)
 | 
				
			||||||
	inbound, err = a.inboundService.AddInbound(inbound)
 | 
						inbound, err = a.inboundService.AddInbound(inbound)
 | 
				
			||||||
	jsonMsgObj(c, I18n(c, "pages.inbounds.create"), inbound, err)
 | 
						jsonMsgObj(c, WebI18n(c, "pages.inbounds.create"), inbound, err)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		a.xrayService.SetToNeedRestart()
 | 
							a.xrayService.SetToNeedRestart()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -110,11 +110,11 @@ func (a *InboundController) addInbound(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) delInbound(c *gin.Context) {
 | 
					func (a *InboundController) delInbound(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "delete"), err)
 | 
							jsonMsg(c, WebI18n(c, "delete"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = a.inboundService.DelInbound(id)
 | 
						err = a.inboundService.DelInbound(id)
 | 
				
			||||||
	jsonMsgObj(c, I18n(c, "delete"), id, err)
 | 
						jsonMsgObj(c, WebI18n(c, "delete"), id, err)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		a.xrayService.SetToNeedRestart()
 | 
							a.xrayService.SetToNeedRestart()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -123,7 +123,7 @@ func (a *InboundController) delInbound(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) updateInbound(c *gin.Context) {
 | 
					func (a *InboundController) updateInbound(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	inbound := &model.Inbound{
 | 
						inbound := &model.Inbound{
 | 
				
			||||||
| 
						 | 
					@ -131,11 +131,11 @@ func (a *InboundController) updateInbound(c *gin.Context) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = c.ShouldBind(inbound)
 | 
						err = c.ShouldBind(inbound)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	inbound, err = a.inboundService.UpdateInbound(inbound)
 | 
						inbound, err = a.inboundService.UpdateInbound(inbound)
 | 
				
			||||||
	jsonMsgObj(c, I18n(c, "pages.inbounds.update"), inbound, err)
 | 
						jsonMsgObj(c, WebI18n(c, "pages.inbounds.update"), inbound, err)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		a.xrayService.SetToNeedRestart()
 | 
							a.xrayService.SetToNeedRestart()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -165,7 +165,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
 | 
				
			||||||
	data := &model.Inbound{}
 | 
						data := &model.Inbound{}
 | 
				
			||||||
	err := c.ShouldBind(data)
 | 
						err := c.ShouldBind(data)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) delInboundClient(c *gin.Context) {
 | 
					func (a *InboundController) delInboundClient(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	clientId := c.Param("clientId")
 | 
						clientId := c.Param("clientId")
 | 
				
			||||||
| 
						 | 
					@ -205,7 +205,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
 | 
				
			||||||
	inbound := &model.Inbound{}
 | 
						inbound := &model.Inbound{}
 | 
				
			||||||
	err := c.ShouldBind(inbound)
 | 
						err := c.ShouldBind(inbound)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -223,7 +223,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) resetClientTraffic(c *gin.Context) {
 | 
					func (a *InboundController) resetClientTraffic(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	email := c.Param("email")
 | 
						email := c.Param("email")
 | 
				
			||||||
| 
						 | 
					@ -251,7 +251,7 @@ func (a *InboundController) resetAllTraffics(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
 | 
					func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -266,7 +266,7 @@ func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
 | 
				
			||||||
func (a *InboundController) delDepletedClients(c *gin.Context) {
 | 
					func (a *InboundController) delDepletedClients(c *gin.Context) {
 | 
				
			||||||
	id, err := strconv.Atoi(c.Param("id"))
 | 
						id, err := strconv.Atoi(c.Param("id"))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.inbounds.update"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.inbounds.update"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = a.inboundService.DelDepletedClients(id)
 | 
						err = a.inboundService.DelDepletedClients(id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,15 +49,15 @@ func (a *IndexController) login(c *gin.Context) {
 | 
				
			||||||
	var form LoginForm
 | 
						var form LoginForm
 | 
				
			||||||
	err := c.ShouldBind(&form)
 | 
						err := c.ShouldBind(&form)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		pureJsonMsg(c, false, I18n(c, "pages.login.toasts.invalidFormData"))
 | 
							pureJsonMsg(c, false, WebI18n(c, "pages.login.toasts.invalidFormData"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if form.Username == "" {
 | 
						if form.Username == "" {
 | 
				
			||||||
		pureJsonMsg(c, false, I18n(c, "pages.login.toasts.emptyUsername"))
 | 
							pureJsonMsg(c, false, WebI18n(c, "pages.login.toasts.emptyUsername"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if form.Password == "" {
 | 
						if form.Password == "" {
 | 
				
			||||||
		pureJsonMsg(c, false, I18n(c, "pages.login.toasts.emptyPassword"))
 | 
							pureJsonMsg(c, false, WebI18n(c, "pages.login.toasts.emptyPassword"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ func (a *IndexController) login(c *gin.Context) {
 | 
				
			||||||
	if user == nil {
 | 
						if user == nil {
 | 
				
			||||||
		logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password)
 | 
							logger.Infof("wrong username or password: \"%s\" \"%s\"", form.Username, form.Password)
 | 
				
			||||||
		a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0)
 | 
							a.tgbot.UserLoginNotify(form.Username, getRemoteIp(c), timeStr, 0)
 | 
				
			||||||
		pureJsonMsg(c, false, I18n(c, "pages.login.toasts.wrongUsernameOrPassword"))
 | 
							pureJsonMsg(c, false, WebI18n(c, "pages.login.toasts.wrongUsernameOrPassword"))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logger.Infof("%s login success, Ip Address: %s\n", form.Username, getRemoteIp(c))
 | 
							logger.Infof("%s login success, Ip Address: %s\n", form.Username, getRemoteIp(c))
 | 
				
			||||||
| 
						 | 
					@ -87,7 +87,7 @@ func (a *IndexController) login(c *gin.Context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = session.SetLoginUser(c, user)
 | 
						err = session.SetLoginUser(c, user)
 | 
				
			||||||
	logger.Info("user", user.Id, "login success")
 | 
						logger.Info("user", user.Id, "login success")
 | 
				
			||||||
	jsonMsg(c, I18n(c, "pages.login.toasts.successLogin"), err)
 | 
						jsonMsg(c, WebI18n(c, "pages.login.toasts.successLogin"), err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *IndexController) logout(c *gin.Context) {
 | 
					func (a *IndexController) logout(c *gin.Context) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,7 +81,7 @@ func (a *ServerController) getXrayVersion(c *gin.Context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	versions, err := a.serverService.GetXrayVersions()
 | 
						versions, err := a.serverService.GetXrayVersions()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "getVersion"), err)
 | 
							jsonMsg(c, WebI18n(c, "getVersion"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ func (a *ServerController) getXrayVersion(c *gin.Context) {
 | 
				
			||||||
func (a *ServerController) installXray(c *gin.Context) {
 | 
					func (a *ServerController) installXray(c *gin.Context) {
 | 
				
			||||||
	version := c.Param("version")
 | 
						version := c.Param("version")
 | 
				
			||||||
	err := a.serverService.UpdateXray(version)
 | 
						err := a.serverService.UpdateXray(version)
 | 
				
			||||||
	jsonMsg(c, I18n(c, "install")+" xray", err)
 | 
						jsonMsg(c, WebI18n(c, "install")+" xray", err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *ServerController) stopXrayService(c *gin.Context) {
 | 
					func (a *ServerController) stopXrayService(c *gin.Context) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,7 @@ func (a *SettingController) initRouter(g *gin.RouterGroup) {
 | 
				
			||||||
func (a *SettingController) getAllSetting(c *gin.Context) {
 | 
					func (a *SettingController) getAllSetting(c *gin.Context) {
 | 
				
			||||||
	allSetting, err := a.settingService.GetAllSetting()
 | 
						allSetting, err := a.settingService.GetAllSetting()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonObj(c, allSetting, nil)
 | 
						jsonObj(c, allSetting, nil)
 | 
				
			||||||
| 
						 | 
					@ -58,7 +58,7 @@ func (a *SettingController) getAllSetting(c *gin.Context) {
 | 
				
			||||||
func (a *SettingController) getDefaultJsonConfig(c *gin.Context) {
 | 
					func (a *SettingController) getDefaultJsonConfig(c *gin.Context) {
 | 
				
			||||||
	defaultJsonConfig, err := a.settingService.GetDefaultJsonConfig()
 | 
						defaultJsonConfig, err := a.settingService.GetDefaultJsonConfig()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonObj(c, defaultJsonConfig, nil)
 | 
						jsonObj(c, defaultJsonConfig, nil)
 | 
				
			||||||
| 
						 | 
					@ -67,22 +67,22 @@ func (a *SettingController) getDefaultJsonConfig(c *gin.Context) {
 | 
				
			||||||
func (a *SettingController) getDefaultSettings(c *gin.Context) {
 | 
					func (a *SettingController) getDefaultSettings(c *gin.Context) {
 | 
				
			||||||
	expireDiff, err := a.settingService.GetExpireDiff()
 | 
						expireDiff, err := a.settingService.GetExpireDiff()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	trafficDiff, err := a.settingService.GetTrafficDiff()
 | 
						trafficDiff, err := a.settingService.GetTrafficDiff()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defaultCert, err := a.settingService.GetCertFile()
 | 
						defaultCert, err := a.settingService.GetCertFile()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defaultKey, err := a.settingService.GetKeyFile()
 | 
						defaultKey, err := a.settingService.GetKeyFile()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.getSettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.getSettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	result := map[string]interface{}{
 | 
						result := map[string]interface{}{
 | 
				
			||||||
| 
						 | 
					@ -98,27 +98,27 @@ func (a *SettingController) updateSetting(c *gin.Context) {
 | 
				
			||||||
	allSetting := &entity.AllSetting{}
 | 
						allSetting := &entity.AllSetting{}
 | 
				
			||||||
	err := c.ShouldBind(allSetting)
 | 
						err := c.ShouldBind(allSetting)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = a.settingService.UpdateAllSetting(allSetting)
 | 
						err = a.settingService.UpdateAllSetting(allSetting)
 | 
				
			||||||
	jsonMsg(c, I18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
						jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *SettingController) updateUser(c *gin.Context) {
 | 
					func (a *SettingController) updateUser(c *gin.Context) {
 | 
				
			||||||
	form := &updateUserForm{}
 | 
						form := &updateUserForm{}
 | 
				
			||||||
	err := c.ShouldBind(form)
 | 
						err := c.ShouldBind(form)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	user := session.GetLoginUser(c)
 | 
						user := session.GetLoginUser(c)
 | 
				
			||||||
	if user.Username != form.OldUsername || user.Password != form.OldPassword {
 | 
						if user.Username != form.OldUsername || user.Password != form.OldPassword {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.modifyUser"), errors.New(I18n(c, "pages.settings.toasts.originalUserPassIncorrect")))
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifyUser"), errors.New(WebI18n(c, "pages.settings.toasts.originalUserPassIncorrect")))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if form.NewUsername == "" || form.NewPassword == "" {
 | 
						if form.NewUsername == "" || form.NewPassword == "" {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.modifyUser"), errors.New(I18n(c, "pages.settings.toasts.userPassMustBeNotEmpty")))
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifyUser"), errors.New(WebI18n(c, "pages.settings.toasts.userPassMustBeNotEmpty")))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = a.userService.UpdateUser(user.Id, form.NewUsername, form.NewPassword)
 | 
						err = a.userService.UpdateUser(user.Id, form.NewUsername, form.NewPassword)
 | 
				
			||||||
| 
						 | 
					@ -127,19 +127,19 @@ func (a *SettingController) updateUser(c *gin.Context) {
 | 
				
			||||||
		user.Password = form.NewPassword
 | 
							user.Password = form.NewPassword
 | 
				
			||||||
		session.SetLoginUser(c, user)
 | 
							session.SetLoginUser(c, user)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonMsg(c, I18n(c, "pages.settings.toasts.modifyUser"), err)
 | 
						jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifyUser"), err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *SettingController) restartPanel(c *gin.Context) {
 | 
					func (a *SettingController) restartPanel(c *gin.Context) {
 | 
				
			||||||
	err := a.panelService.RestartPanel(time.Second * 3)
 | 
						err := a.panelService.RestartPanel(time.Second * 3)
 | 
				
			||||||
	jsonMsg(c, I18n(c, "pages.settings.restartPanel"), err)
 | 
						jsonMsg(c, WebI18n(c, "pages.settings.restartPanel"), err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *SettingController) updateSecret(c *gin.Context) {
 | 
					func (a *SettingController) updateSecret(c *gin.Context) {
 | 
				
			||||||
	form := &updateSecretForm{}
 | 
						form := &updateSecretForm{}
 | 
				
			||||||
	err := c.ShouldBind(form)
 | 
						err := c.ShouldBind(form)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		jsonMsg(c, I18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
							jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifySettings"), err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	user := session.GetLoginUser(c)
 | 
						user := session.GetLoginUser(c)
 | 
				
			||||||
	err = a.userService.UpdateUserSecret(user.Id, form.LoginSecret)
 | 
						err = a.userService.UpdateUserSecret(user.Id, form.LoginSecret)
 | 
				
			||||||
| 
						 | 
					@ -147,7 +147,7 @@ func (a *SettingController) updateSecret(c *gin.Context) {
 | 
				
			||||||
		user.LoginSecret = form.LoginSecret
 | 
							user.LoginSecret = form.LoginSecret
 | 
				
			||||||
		session.SetLoginUser(c, user)
 | 
							session.SetLoginUser(c, user)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	jsonMsg(c, I18n(c, "pages.settings.toasts.modifyUser"), err)
 | 
						jsonMsg(c, WebI18n(c, "pages.settings.toasts.modifyUser"), err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *SettingController) getUserSecret(c *gin.Context) {
 | 
					func (a *SettingController) getUserSecret(c *gin.Context) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,12 +38,12 @@ func jsonMsgObj(c *gin.Context, msg string, obj interface{}, err error) {
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		m.Success = true
 | 
							m.Success = true
 | 
				
			||||||
		if msg != "" {
 | 
							if msg != "" {
 | 
				
			||||||
			m.Msg = msg + I18n(c, "success")
 | 
								m.Msg = msg + WebI18n(c, "success")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		m.Success = false
 | 
							m.Success = false
 | 
				
			||||||
		m.Msg = msg + I18n(c, "fail") + ": " + err.Error()
 | 
							m.Msg = msg + WebI18n(c, "fail") + ": " + err.Error()
 | 
				
			||||||
		logger.Warning(msg+I18n(c, "fail")+": ", err)
 | 
							logger.Warning(msg+WebI18n(c, "fail")+": ", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	c.JSON(http.StatusOK, m)
 | 
						c.JSON(http.StatusOK, m)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue