Restrict user login with IP

This commit is contained in:
skiffer-git
2022-08-15 17:52:45 +08:00
parent 7d1707ca7c
commit 8b857f9980
3 changed files with 83 additions and 15 deletions
@@ -1,6 +1,9 @@
package im_mysql_model
import "Open_IM/pkg/common/db"
import (
"Open_IM/pkg/common/db"
"time"
)
func IsLimitRegisterIp(RegisterIp string) (bool, error) {
//如果已经存在则限制
@@ -38,3 +41,19 @@ func QueryUserIPLimits(ip string) ([]db.UserIpLimit, error) {
func InsertOneIntoIpLimits(ipLimits db.IpLimit) error {
return db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Create(ipLimits).Error
}
func GetIpLimitsLoginByUserID(userID string) ([]db.UserIpLimit, error) {
var ips []db.UserIpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("user_id=?", userID).Take(&ips).Error
return ips, err
}
func InsertUserIpLimitsLogin(userIp *db.UserIpLimit) error {
userIp.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Create(userIp).Error
}
func DeleteUserIpLimitsLogin(userID, ip string) error {
userIp := db.UserIpLimit{UserID: userID, Ip: ip}
return db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Delete(&userIp).Error
}