2
This commit is contained in:
56
internal/erpserver/model/system/login_log.go
Normal file
56
internal/erpserver/model/system/login_log.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
)
|
||||
|
||||
type LoginLogRepository interface {
|
||||
Create(ctx context.Context, obj *LoginLog) error
|
||||
GetLatest(ctx context.Context, email string) (*LoginLog, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*LoginLog, int64, error)
|
||||
Count(ctx context.Context, email string) (int64, error)
|
||||
}
|
||||
|
||||
type LoginLog struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);not null;"`
|
||||
IsSuccess bool `json:"is_success" gorm:"type:boolean;not null;"`
|
||||
Message string `json:"message" gorm:"type:varchar(300);not null;"`
|
||||
RefererUrl string `json:"referer_url" gorm:"type:varchar(500);not null;"`
|
||||
Url string `json:"url" gorm:"type:varchar(500);not null;"`
|
||||
Os string `json:"os" gorm:"type:varchar(50);not null;"`
|
||||
Ip string `json:"ip" gorm:"type:varchar(20);not null;"`
|
||||
Browser string `json:"browser" gorm:"type:varchar(100);not null;"`
|
||||
}
|
||||
|
||||
func (LoginLog) TableName() string {
|
||||
return "sys_user_login_log"
|
||||
}
|
||||
|
||||
func NewLoginLog(email, os, ip, browser, url, referer string) *LoginLog {
|
||||
return &LoginLog{
|
||||
CreatedAt: time.Now(),
|
||||
Email: email,
|
||||
IsSuccess: false,
|
||||
RefererUrl: referer,
|
||||
Url: url,
|
||||
Os: os,
|
||||
Ip: ip,
|
||||
Browser: browser,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginLog) SetMessage(message string) *LoginLog {
|
||||
l.Message = message
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *LoginLog) SetOk(message string) *LoginLog {
|
||||
l.Message = message
|
||||
l.IsSuccess = true
|
||||
return l
|
||||
}
|
||||
Reference in New Issue
Block a user