-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4267a2
commit 13843da
Showing
11 changed files
with
76 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package auth | ||
package perms | ||
|
||
import "errors" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/auth/sessionservice.go → modules/auth/session/service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package auth | ||
package sess | ||
|
||
import "github.com/google/uuid" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package auth | ||
package sess | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sess | ||
|
||
import ( | ||
"time" | ||
|
||
perms "github.com/NeuralNexusDev/neuralnexus-api/modules/auth/permissions" | ||
"github.com/google/uuid" | ||
) | ||
|
||
// Session struct | ||
type Session struct { | ||
ID uuid.UUID `json:"session_id" xml:"session_id" db:"session_id"` | ||
UserID uuid.UUID `json:"user_id" xml:"user_id" db:"user_id"` | ||
Permissions []string `json:"permissions" xml:"permissions" db:"permissions"` | ||
IssuedAt int64 `json:"iat" xml:"iat" db:"iat"` | ||
LastUsedAt int64 `json:"lua" xml:"lua" db:"lua"` | ||
ExpiresAt int64 `json:"exp" xml:"exp" db:"exp"` | ||
} | ||
|
||
// HasPermission checks if a session has a permission | ||
func (s *Session) HasPermission(permission perms.Scope) bool { | ||
for _, p := range s.Permissions { | ||
if p == permission.Name+"|"+permission.Value { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// IsExpired checks if a session is expired | ||
func (s *Session) IsValid() bool { | ||
if s.ExpiresAt == 0 { | ||
return true | ||
} | ||
return time.Now().Unix() < s.ExpiresAt | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters