51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"kefu/types"
|
|
"time"
|
|
)
|
|
|
|
type IpAuth struct {
|
|
ID uint `gorm:"primary_key" json:"id"`
|
|
IpAddress string `json:"ip_address"`
|
|
ExpireTime string `json:"expire_time"`
|
|
Content string `json:"content"`
|
|
Phone string `json:"phone"`
|
|
NowTime string `gorm:"-" json:"now_time"`
|
|
Status uint `json:"status"`
|
|
CreatedAt types.Time `json:"created_at"`
|
|
Code string `json:"code"`
|
|
}
|
|
|
|
func CreateIpAuth(ip, phone, content, code, expireTime string) IpAuth {
|
|
model := IpAuth{
|
|
IpAddress: ip,
|
|
Phone: phone,
|
|
Content: content,
|
|
ExpireTime: expireTime,
|
|
Status: 1,
|
|
Code: code,
|
|
CreatedAt: types.Time{
|
|
time.Now(),
|
|
},
|
|
}
|
|
DB.Create(&model)
|
|
return model
|
|
}
|
|
func FindServerIpAddress(ip string) IpAuth {
|
|
var ipAuth IpAuth
|
|
DB.Where("ip_address = ?", ip).First(&ipAuth)
|
|
return ipAuth
|
|
}
|
|
func DeleteIpAddress(ip string) {
|
|
DB.Where("ip_address = ?", ip).Delete(IpAuth{})
|
|
}
|
|
func UpdateIpAddress(ip string, phone string, host, code string) {
|
|
info := &IpAuth{
|
|
Phone: phone,
|
|
Content: host,
|
|
Code: code,
|
|
}
|
|
DB.Model(info).Where("ip_address = ?", ip).Update(info)
|
|
}
|