Add token creation (login)

This commit is contained in:
Howl
2016-04-05 22:22:13 +02:00
parent b3b4dde8f2
commit d02f3f9951
6 changed files with 215 additions and 2 deletions

View File

@@ -98,3 +98,31 @@ func (p Privileges) String() string {
}
return strings.Join(pvs, ", ")
}
var privilegeMustBe = [...]int{
1,
1,
1,
3,
3,
4,
4,
4,
4,
4,
3,
}
// CanOnly removes any privilege that the user has requested to have, but cannot have due to their rank.
func (p Privileges) CanOnly(rank int) Privileges {
newPrivilege := 0
for i, v := range privilegeMustBe {
wants := p&1 == 1
can := rank >= v
if wants && can {
newPrivilege |= 1 << uint(i)
}
p >>= 1
}
return Privileges(newPrivilege)
}