feat: user manage api
This commit is contained in:
@ -86,6 +86,9 @@ func DeleteUserById(id uint) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if old.IsAdmin() || old.IsGuest() {
|
||||
return errors.WithStack(errs.DeleteAdminOrGuest)
|
||||
}
|
||||
userCache.Del(old.Username)
|
||||
return errors.WithStack(db.Delete(&model.User{}, id).Error)
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package errs
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
EmptyUsername = errors.New("username is empty")
|
||||
EmptyPassword = errors.New("password is empty")
|
||||
WrongPassword = errors.New("password is incorrect")
|
||||
EmptyUsername = errors.New("username is empty")
|
||||
EmptyPassword = errors.New("password is empty")
|
||||
WrongPassword = errors.New("password is incorrect")
|
||||
DeleteAdminOrGuest = errors.New("cannot delete admin or guest")
|
||||
)
|
||||
|
@ -12,13 +12,13 @@ const (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
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"` // read only
|
||||
Webdav bool `json:"webdav"` // allow webdav
|
||||
Role int `json:"role"` // user's role
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
Username string `json:"username" gorm:"unique" binding:"required"` // username
|
||||
Password string `json:"password"` // password
|
||||
BasePath string `json:"base_path"` // base path
|
||||
ReadOnly bool `json:"read_only"` // read only
|
||||
Webdav bool `json:"webdav"` // allow webdav
|
||||
Role int `json:"role"` // user's role
|
||||
}
|
||||
|
||||
func (u User) IsGuest() bool {
|
||||
|
Reference in New Issue
Block a user