feat: user jwt login
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package model
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
const (
|
||||
GENERAL = iota
|
||||
GUEST // only one exists
|
||||
@ -7,12 +9,12 @@ const (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
Name string `json:"name" gorm:"unique"` // username
|
||||
Password string `json:"password"` // password
|
||||
BasePath string `json:"base_path"` // base path
|
||||
ReadOnly bool `json:"read_only"` // allow upload
|
||||
Role int `json:"role"` // user's role
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
Username string `json:"username" gorm:"unique"` // username
|
||||
Password string `json:"password"` // password
|
||||
BasePath string `json:"base_path"` // base path
|
||||
ReadOnly bool `json:"read_only"` // allow upload
|
||||
Role int `json:"role"` // user's role
|
||||
}
|
||||
|
||||
func (u User) IsGuest() bool {
|
||||
@ -22,3 +24,13 @@ func (u User) IsGuest() bool {
|
||||
func (u User) IsAdmin() bool {
|
||||
return u.Role == ADMIN
|
||||
}
|
||||
|
||||
func (u User) ValidatePassword(password string) error {
|
||||
if password == "" {
|
||||
return errors.New("password is empty")
|
||||
}
|
||||
if u.Password != password {
|
||||
return errors.New("password is incorrect")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user