Files
ai/models/User.go
2023-07-18 17:52:03 +08:00

30 lines
717 B
Go

package models
import (
"crypto/md5"
"fmt"
"main/configs"
"time"
)
type User struct {
ID int `json:"id" gorm:"primary_key"`
Gold int `json:"gold"`
Name string `json:"name"`
Email string `json:"email" gorm:"unique;not null"`
Password string `json:"-"`
Slat string `json:"-"`
Admin bool `json:"admin"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
func init() {
configs.ORMDB().AutoMigrate(&User{})
}
// 驗證用戶密碼
func (user *User) CheckPassword(password string) bool {
return user.Password == fmt.Sprintf("%x", md5.Sum([]byte(password+user.Slat)))
}