Lint / Lint (Node/Svelte) (push) Successful in 24s
Lint / Lint (Go) (push) Successful in 28s
Lint / Lint (Python) (push) Failing after 14s
Tests / Test (Node/Svelte) (push) Successful in 18s
Tests / Test (Go) (push) Successful in 25s
Tests / Test (Python) (push) Successful in 12s
- Added TOTP support for two-factor authentication in the auth module. - Introduced new types and interfaces for TOTP setup and token actions in the web UI. - Created backend logic for generating and verifying TOTP secrets and tokens. - Implemented user management features including role assignments and user CRUD operations. - Enhanced UI components for managing users and TOTP settings. - Added styles for optional labels and authentication reset links. - Implemented reset code generation and validation for admin accounts.
35 lines
996 B
Go
35 lines
996 B
Go
package auth
|
|
|
|
// Role is the shared account-management role used by the web applications.
|
|
type Role string
|
|
|
|
const (
|
|
RoleSuperAdmin Role = "superadmin"
|
|
RoleAdmin Role = "admin"
|
|
RoleUser Role = "user"
|
|
)
|
|
|
|
// NormalizeRole keeps persisted role values inside the shared contract.
|
|
func NormalizeRole(value string) Role {
|
|
switch Role(value) {
|
|
case RoleSuperAdmin:
|
|
return RoleSuperAdmin
|
|
case RoleAdmin:
|
|
return RoleAdmin
|
|
default:
|
|
return RoleUser
|
|
}
|
|
}
|
|
|
|
// CanManageUsers is the common authorization gate for account CRUD.
|
|
func CanManageUsers(role string) bool {
|
|
role = string(NormalizeRole(role))
|
|
return role == string(RoleSuperAdmin) || role == string(RoleAdmin)
|
|
}
|
|
|
|
// CanAssignRole prevents an administrator from creating or promoting another
|
|
// administrator. Only the first-created superadmin can delegate admin access.
|
|
func CanAssignRole(actorRole, targetRole string) bool {
|
|
return NormalizeRole(actorRole) == RoleSuperAdmin && NormalizeRole(targetRole) != RoleSuperAdmin
|
|
}
|