moves claims into models

This commit is contained in:
dhax 2017-10-04 02:52:19 +02:00
parent 38722c9da5
commit f1c2249744
6 changed files with 57 additions and 35 deletions

View file

@ -5,6 +5,7 @@ import (
"strings"
"time"
"github.com/go-chi/jwtauth"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"github.com/go-pg/pg/orm"
@ -70,6 +71,14 @@ func (a *Account) CanLogin() bool {
return a.Active
}
func (a *Account) Claims() jwtauth.Claims {
return jwtauth.Claims{
"id": a.ID,
"sub": a.Name,
"roles": a.Roles,
}
}
// AccountFilter provides pagination and filtering options on accounts.
type AccountFilter struct {
orm.Pager

View file

@ -3,6 +3,7 @@ package models
import (
"time"
"github.com/go-chi/jwtauth"
"github.com/go-pg/pg/orm"
)
@ -34,3 +35,10 @@ func (t *Token) BeforeUpdate(db orm.DB) error {
t.UpdatedAt = time.Now()
return nil
}
func (t *Token) Claims() jwtauth.Claims {
return jwtauth.Claims{
"id": t.ID,
"token": t.Token,
}
}