29 lines
659 B
Go
29 lines
659 B
Go
package models
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"main/configs"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID int `json:"id" gorm:"primary_key"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
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)))
|
|
}
|