Junie: fix token authentication
This commit is contained in:
20
data/user.go
20
data/user.go
@@ -25,6 +25,26 @@ type User struct {
|
||||
Roles []string
|
||||
}
|
||||
|
||||
// HasRole checks if the user has a specific role
|
||||
func (u *User) HasRole(role string) bool {
|
||||
for _, r := range u.Roles {
|
||||
if r == role {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasPermission checks if the user has a specific permission using the authorization service
|
||||
func (u *User) HasPermission(authService *AuthorizationService, resource, action string) (bool, error) {
|
||||
return authService.UserHasPermission(u.ID, resource, action)
|
||||
}
|
||||
|
||||
// GetPermissions returns all permissions for the user using the authorization service
|
||||
func (u *User) GetPermissions(authService *AuthorizationService) ([]Permission, error) {
|
||||
return authService.GetUserPermissions(u.ID)
|
||||
}
|
||||
|
||||
type Login struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"password,omitzero"`
|
||||
|
||||
Reference in New Issue
Block a user