types.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package auth
  2. import "time"
  3. type Role string
  4. const (
  5. RoleFull Role = "full" // All permissions (super admin)
  6. RoleWrite Role = "write" // Config/operation permissions, cannot manage users
  7. RoleRead Role = "read" // View-only permissions
  8. )
  9. type User struct {
  10. Username string `json:"username"`
  11. PasswordHash string `json:"password_hash,omitempty"`
  12. Role Role `json:"role"`
  13. Comment string `json:"comment"`
  14. Disabled bool `json:"disabled"`
  15. CreatedAt time.Time `json:"created_at"`
  16. LastLoginAt time.Time `json:"last_login_at,omitempty"`
  17. }
  18. type PublicUser struct {
  19. Username string `json:"username"`
  20. Role Role `json:"role"`
  21. Comment string `json:"comment"`
  22. Disabled bool `json:"disabled"`
  23. CreatedAt time.Time `json:"created_at"`
  24. LastLoginAt time.Time `json:"last_login_at,omitempty"`
  25. }
  26. type Session struct {
  27. Token string `json:"token"`
  28. Username string `json:"username"`
  29. Role Role `json:"role"`
  30. ExpiresAt time.Time `json:"expires_at"`
  31. }
  32. type LoginRequest struct {
  33. Username string `json:"username"`
  34. Password string `json:"password"`
  35. }
  36. type LoginResponse struct {
  37. Success bool `json:"success"`
  38. Token string `json:"token"`
  39. User PublicUser `json:"user"`
  40. Message string `json:"message,omitempty"`
  41. }
  42. type CreateUserRequest struct {
  43. Username string `json:"username"`
  44. Password string `json:"password"`
  45. Role Role `json:"role"`
  46. Comment string `json:"comment"`
  47. }
  48. type UpdateUserRequest struct {
  49. Role Role `json:"role"`
  50. Comment string `json:"comment"`
  51. Disabled bool `json:"disabled"`
  52. }
  53. type ChangePasswordRequest struct {
  54. OldPassword string `json:"old_password,omitempty"`
  55. NewPassword string `json:"new_password"`
  56. }
  57. type AdminResetPasswordRequest struct {
  58. NewPassword string `json:"new_password"`
  59. }