update profile api (#16)

* update profile api

* rename

* fix realip assertion

* add waf api
This commit is contained in:
UUBulb
2024-11-23 16:22:22 +08:00
committed by GitHub
parent 22738b6244
commit 885330e948
7 changed files with 85 additions and 7 deletions

View File

@@ -5,3 +5,8 @@ type User struct {
Username string `json:"username,omitempty" gorm:"uniqueIndex"`
Password string `json:"password,omitempty" gorm:"type:char(72)"`
}
type Profile struct {
User
LoginIP string `json:"login_ip,omitempty"`
}

View File

@@ -56,7 +56,22 @@ func ClearIP(db *gorm.DB, ip string) error {
if err != nil {
return err
}
return db.Delete(&WAF{}, "ip = ?", ipBinary).Error
return db.Unscoped().Delete(&WAF{}, "ip = ?", ipBinary).Error
}
func BatchClearIP(db *gorm.DB, ip []string) error {
if len(ip) < 1 {
return nil
}
ips := make([][]byte, 0, len(ip))
for _, s := range ip {
ipBinary, err := utils.IPStringToBinary(s)
if err != nil {
continue
}
ips = append(ips, ipBinary)
}
return db.Unscoped().Delete(&WAF{}, "ip in (?)", ips).Error
}
func BlockIP(db *gorm.DB, ip string, reason uint8) error {