func (this *ManagerController) AddIp() { ips := strings.TrimSpace(this.GetString("ips", "")) ip := strings.Split(ips, "\n") user := this.Ctx.Input.GetData("CurrentUser").(*User) var ip_insert []string for i := 0; i < len(ip); i++ { exist := false if !utils.IsIpaddValid(ip[i]) { this.ServeErrJson("IP address is invalid") return } else { for _, val := range user.Ips { if ip[i] == val.Ip { exist = true break } } } if !exist { ip_insert = append(ip_insert, []string{ip[i]}...) } } if len(ip_insert) != 0 { err := InsertIpByuser(ip_insert, user) if err != nil { this.ServeErrJson("add ip err") return } } this.ServeOKJson() }
func (this *ManagerController) RemoveIp() { ips := strings.TrimSpace(this.GetString("ips", "")) ip := strings.Split(ips, "\n") if len(ip) == 0 { this.ServeErrJson("no rows to delete") return } for _, val := range ip { if !utils.IsIpaddValid(val) { this.ServeErrJson("IP address is invalid") return } } err := DeleteIpByuser(ip) if err != nil { this.ServeErrJson("Delete ip error") return } this.ServeOKJson() }