Changes to change system.
the build was successful

This commit is contained in:
2019-06-16 10:32:34 +02:00
parent 13f82399ef
commit 021f67ea4b
19 changed files with 503 additions and 87 deletions
+18 -14
View File
@@ -114,20 +114,24 @@ func CheckToken(tokenString string) (token models.Token, err error) {
return models.Token{}, ErrDeletedUser
}
acceptedPermissions := make([]string, 0, 8)
for _, permission := range permissions {
found := false
acceptedPermissions := make([]string, 0, len(user.Permissions))
if len(permissions) > 0 {
for _, permission := range permissions {
found := false
for _, userPermission := range user.Permissions {
if permission == userPermission {
found = true
break
for _, userPermission := range user.Permissions {
if permission == userPermission {
found = true
break
}
}
if found {
acceptedPermissions = append(acceptedPermissions, permission)
}
}
if found {
acceptedPermissions = append(acceptedPermissions, permission)
}
} else {
acceptedPermissions = append(acceptedPermissions, user.Permissions...)
}
return models.Token{UserID: user.ID, Permissions: acceptedPermissions}, nil
@@ -153,10 +157,10 @@ func parseClaims(jwtClaims jwt.Claims) (userid string, permissions []string, err
permissions = append(permissions, permission)
}
}
}
if len(permissions) == 0 {
return "", nil, ErrInvalidClaims
if len(permissions) == 0 {
return "", nil, ErrInvalidClaims
}
}
return
+44
View File
@@ -0,0 +1,44 @@
package notifier
import (
"context"
"sync"
)
// A Notifier is a synchronization primitive for waking upp all listeners at once.
type Notifier struct {
mutex sync.Mutex
ch chan struct{}
}
// Broadcast wakes all listeners if there are any.
func (notifier *Notifier) Broadcast() {
notifier.mutex.Lock()
if notifier.ch != nil {
close(notifier.ch)
notifier.ch = nil
}
notifier.mutex.Unlock()
}
// C gets the channel that'll close on the next notification.
func (notifier *Notifier) C() <-chan struct{} {
notifier.mutex.Lock()
if notifier.ch == nil {
notifier.ch = make(chan struct{})
}
ch := notifier.ch
notifier.mutex.Unlock()
return ch
}
// Wait waits for the next `Broadcast` call, or the context's termination.
func (notifier *Notifier) Wait(ctx context.Context) error {
select {
case <-notifier.C():
return nil
case <-ctx.Done():
return ctx.Err()
}
}