Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37862e747f | |||
| 9bfc591fcc | |||
| 32facb1767 | |||
| f948a06b66 | |||
|
|
e00a85b1a4 | ||
| 28bfbb84ad | |||
| 6b8887832e | |||
| 4e61d7714e |
2
LICENSE
Normal file
2
LICENSE
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
This software is provided for personal and non-commercial use only.
|
||||||
|
Any commercial use, including but not limited to resale, incorporation into a commercial product, or use in a for-profit service, is strictly prohibited without prior written permission from the author.
|
||||||
@@ -1,6 +1,17 @@
|
|||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
|
vars:
|
||||||
|
test_db: "~/databases/test.db"
|
||||||
|
schema_db: "./sqlite/schema.sql"
|
||||||
|
svg_path: "~/svgs/flaticon_colored_svgs"
|
||||||
tasks:
|
tasks:
|
||||||
sql:
|
sqlc:
|
||||||
cmds:
|
cmds:
|
||||||
- sqlc generate
|
- sqlc generate
|
||||||
|
|
||||||
|
rebuild_test_db:
|
||||||
|
cmds:
|
||||||
|
- go build cmd/nkode/nkode.go
|
||||||
|
- rm {{.test_db}}
|
||||||
|
- sqlite3 {{.test_db}} < {{.schema_db}}
|
||||||
|
- ./nkode -db-path {{.test_db}} -svg-path {{.svg_path}}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"git.infra.nkode.tech/dkelly/nkode-core/config"
|
"git.infra.nkode.tech/dkelly/nkode-core/config"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/email"
|
"git.infra.nkode.tech/dkelly/nkode-core/email"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/memCache"
|
"git.infra.nkode.tech/dkelly/nkode-core/memcache"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/repository"
|
"git.infra.nkode.tech/dkelly/nkode-core/repository"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/security"
|
"git.infra.nkode.tech/dkelly/nkode-core/security"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -24,7 +24,7 @@ type NKodeAPI struct {
|
|||||||
repo repository.CustomerUserRepository
|
repo repository.CustomerUserRepository
|
||||||
signupSessionCache *cache.Cache
|
signupSessionCache *cache.Cache
|
||||||
emailQueue *email.Queue
|
emailQueue *email.Queue
|
||||||
forgotNkodeCache memCache.ForgotNKodeCache
|
forgotNkodeCache memcache.ForgotNKodeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKodeAPI {
|
func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKodeAPI {
|
||||||
@@ -32,11 +32,11 @@ func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKo
|
|||||||
repo: repo,
|
repo: repo,
|
||||||
emailQueue: queue,
|
emailQueue: queue,
|
||||||
signupSessionCache: cache.New(sessionExpiration, sessionCleanupInterval),
|
signupSessionCache: cache.New(sessionExpiration, sessionCleanupInterval),
|
||||||
forgotNkodeCache: memCache.NewForgotNKodeCache(),
|
forgotNkodeCache: memcache.NewForgotNKodeCache(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entities.CustomerId, error) {
|
func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entities.CustomerID, error) {
|
||||||
newCustomer, err := entities.NewCustomer(nkodePolicy)
|
newCustomer, err := entities.NewCustomer(nkodePolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -46,22 +46,22 @@ func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entitie
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &newCustomer.Id, nil
|
return &newCustomer.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) CreateCustomerWithID(id entities.CustomerId, nkodePolicy entities.NKodePolicy) error {
|
func (n *NKodeAPI) CreateCustomerWithID(id entities.CustomerID, nkodePolicy entities.NKodePolicy) error {
|
||||||
newCustomer, err := entities.NewCustomer(nkodePolicy)
|
newCustomer, err := entities.NewCustomer(nkodePolicy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newCustomer.Id = id
|
newCustomer.ID = id
|
||||||
if err = n.repo.CreateCustomer(*newCustomer); err != nil {
|
if err = n.repo.CreateCustomer(*newCustomer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, customerId entities.CustomerId, kp entities.KeypadDimension, reset bool) (*entities.SignupResetInterface, error) {
|
func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, customerId entities.CustomerID, kp entities.KeypadDimension, reset bool) (*entities.SignupResetInterface, error) {
|
||||||
user, err := n.repo.GetUser(userEmail, customerId)
|
user, err := n.repo.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -78,23 +78,23 @@ func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, cu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := n.signupSessionCache.Add(signupSession.Id.String(), *signupSession, sessionExpiration); err != nil {
|
if err := n.signupSessionCache.Add(signupSession.ID.String(), *signupSession, sessionExpiration); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
svgInterface, err := n.repo.GetSvgStringInterface(signupSession.LoginUserInterface.SvgId)
|
svgInterface, err := n.repo.GetSvgStringInterface(signupSession.LoginUserInterface.SvgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := entities.SignupResetInterface{
|
resp := entities.SignupResetInterface{
|
||||||
UserIdxInterface: signupSession.SetIdxInterface,
|
UserIdxInterface: signupSession.SetIdxInterface,
|
||||||
SvgInterface: svgInterface,
|
SvgInterface: svgInterface,
|
||||||
SessionId: uuid.UUID(signupSession.Id).String(),
|
SessionID: uuid.UUID(signupSession.ID).String(),
|
||||||
Colors: signupSession.Colors,
|
Colors: signupSession.Colors,
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) SetNKode(customerId entities.CustomerId, sessionId entities.SessionId, keySelection entities.KeySelection) (entities.IdxInterface, error) {
|
func (n *NKodeAPI) SetNKode(customerId entities.CustomerID, sessionId entities.SessionID, keySelection entities.KeySelection) (entities.IdxInterface, error) {
|
||||||
_, err := n.repo.GetCustomer(customerId)
|
_, err := n.repo.GetCustomer(customerId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -118,7 +118,7 @@ func (n *NKodeAPI) SetNKode(customerId entities.CustomerId, sessionId entities.S
|
|||||||
return confirmInterface, nil
|
return confirmInterface, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerId, sessionId entities.SessionId, keySelection entities.KeySelection) error {
|
func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerID, sessionId entities.SessionID, keySelection entities.KeySelection) error {
|
||||||
session, exists := n.signupSessionCache.Get(sessionId.String())
|
session, exists := n.signupSessionCache.Get(sessionId.String())
|
||||||
if !exists {
|
if !exists {
|
||||||
log.Printf("session id does not exist %s", sessionId)
|
log.Printf("session id does not exist %s", sessionId)
|
||||||
@@ -149,11 +149,11 @@ func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerId, sessionId entiti
|
|||||||
} else {
|
} else {
|
||||||
err = n.repo.WriteNewUser(*user)
|
err = n.repo.WriteNewUser(*user)
|
||||||
}
|
}
|
||||||
n.signupSessionCache.Delete(userSession.Id.String())
|
n.signupSessionCache.Delete(userSession.ID.String())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId entities.CustomerId) (*entities.LoginInterface, error) {
|
func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId entities.CustomerID) (*entities.LoginInterface, error) {
|
||||||
user, err := n.repo.GetUser(userEmail, customerId)
|
user, err := n.repo.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -162,7 +162,7 @@ func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId en
|
|||||||
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
||||||
return nil, config.ErrUserForCustomerDNE
|
return nil, config.ErrUserForCustomerDNE
|
||||||
}
|
}
|
||||||
svgInterface, err := n.repo.GetSvgStringInterface(user.Interface.SvgId)
|
svgInterface, err := n.repo.GetSvgStringInterface(user.Interface.SvgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId en
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) Login(customerId entities.CustomerId, userEmail entities.UserEmail, keySelection entities.KeySelection) (*security.AuthenticationTokens, error) {
|
func (n *NKodeAPI) Login(customerId entities.CustomerID, userEmail entities.UserEmail, keySelection entities.KeySelection) (*security.AuthenticationTokens, error) {
|
||||||
customer, err := n.repo.GetCustomer(customerId)
|
customer, err := n.repo.GetCustomer(customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -205,19 +205,19 @@ func (n *NKodeAPI) Login(customerId entities.CustomerId, userEmail entities.User
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = n.repo.UpdateUserRefreshToken(user.Id, jwtToken.RefreshToken); err != nil {
|
if err = n.repo.UpdateUserRefreshToken(user.ID, jwtToken.RefreshToken); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = user.Interface.LoginShuffle(); err != nil {
|
if err = user.Interface.LoginShuffle(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = n.repo.UpdateUserInterface(user.Id, user.Interface); err != nil {
|
if err = n.repo.UpdateUserInterface(user.ID, user.Interface); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &jwtToken, nil
|
return &jwtToken, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) RenewAttributes(customerId entities.CustomerId) error {
|
func (n *NKodeAPI) RenewAttributes(customerId entities.CustomerID) error {
|
||||||
return n.repo.Renew(customerId)
|
return n.repo.Renew(customerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ func (n *NKodeAPI) RandomSvgInterface() ([]string, error) {
|
|||||||
return n.repo.RandomSvgInterface(entities.KeypadMax)
|
return n.repo.RandomSvgInterface(entities.KeypadMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entities.CustomerId, refreshToken string) (string, error) {
|
func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entities.CustomerID, refreshToken string) (string, error) {
|
||||||
user, err := n.repo.GetUser(userEmail, customerId)
|
user, err := n.repo.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -248,7 +248,7 @@ func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entitie
|
|||||||
return security.EncodeAndSignClaims(newAccessClaims)
|
return security.EncodeAndSignClaims(newAccessClaims)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities.CustomerId) error {
|
func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities.CustomerID) error {
|
||||||
user, err := n.repo.GetUser(userEmail, customerId)
|
user, err := n.repo.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting user in rest nkode %v", err)
|
return fmt.Errorf("error getting user in rest nkode %v", err)
|
||||||
@@ -278,7 +278,7 @@ func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.CustomerId) error {
|
func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.CustomerID) error {
|
||||||
user, err := n.repo.GetUser(userEmail, customerId)
|
user, err := n.repo.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -287,7 +287,7 @@ func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.Cus
|
|||||||
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
||||||
return config.ErrUserForCustomerDNE
|
return config.ErrUserForCustomerDNE
|
||||||
}
|
}
|
||||||
if err = n.repo.UpdateUserRefreshToken(user.Id, ""); err != nil {
|
if err = n.repo.UpdateUserRefreshToken(user.ID, ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
|
|
||||||
dbPath := os.Getenv("TEST_DB")
|
dbPath := os.Getenv("TEST_DB")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sqlitedb, err := repository.NewSqliteRepository(ctx, dbPath)
|
sqlitedb, err := repository.NewSqliteNKodeRepo(ctx, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
sqlitedb.Start()
|
sqlitedb.Start()
|
||||||
defer func(sqldb *repository.SqliteRepository) {
|
defer func(sqldb *repository.SqliteNKodeRepo) {
|
||||||
if err := sqldb.Stop(); err != nil {
|
if err := sqldb.Stop(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -52,8 +52,8 @@ func testNKodeAPI(t *testing.T, db repository.CustomerUserRepository) {
|
|||||||
signupResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, false)
|
signupResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setInterface := signupResponse.UserIdxInterface
|
setInterface := signupResponse.UserIdxInterface
|
||||||
sessionIdStr := signupResponse.SessionId
|
sessionIdStr := signupResponse.SessionID
|
||||||
sessionId, err := entities.SessionIdFromString(sessionIdStr)
|
sessionId, err := entities.SessionIDFromString(sessionIdStr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
||||||
userPasscode := setInterface[:passcodeLen]
|
userPasscode := setInterface[:passcodeLen]
|
||||||
@@ -89,8 +89,8 @@ func testNKodeAPI(t *testing.T, db repository.CustomerUserRepository) {
|
|||||||
resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true)
|
resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setInterface = resetResponse.UserIdxInterface
|
setInterface = resetResponse.UserIdxInterface
|
||||||
sessionIdStr = resetResponse.SessionId
|
sessionIdStr = resetResponse.SessionID
|
||||||
sessionId, err = entities.SessionIdFromString(sessionIdStr)
|
sessionId, err = entities.SessionIDFromString(sessionIdStr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
||||||
userPasscode = setInterface[:passcodeLen]
|
userPasscode = setInterface[:passcodeLen]
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sqliteRepo, err := repository.NewSqliteRepository(ctx, *dbPath)
|
sqliteRepo, err := repository.NewSqliteNKodeRepo(ctx, *dbPath)
|
||||||
sqliteRepo.Start()
|
sqliteRepo.Start()
|
||||||
defer func(sqliteRepo *repository.SqliteRepository) {
|
defer func(sqliteRepo *repository.SqliteNKodeRepo) {
|
||||||
if err := sqliteRepo.Stop(); err != nil {
|
if err := sqliteRepo.Stop(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ func main() {
|
|||||||
log.Println(fmt.Sprintf("Successfully added all SVGs in %s to the database at %s\n", *svgPath, *dbPath))
|
log.Println(fmt.Sprintf("Successfully added all SVGs in %s to the database at %s\n", *svgPath, *dbPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
|
func FlaticonToSqlite(repo *repository.SqliteNKodeRepo, svgDir string) {
|
||||||
files, err := os.ReadDir(svgDir)
|
files, err := os.ReadDir(svgDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Customer struct {
|
type Customer struct {
|
||||||
Id CustomerId
|
ID CustomerID
|
||||||
NKodePolicy NKodePolicy
|
NKodePolicy NKodePolicy
|
||||||
Attributes CustomerAttributes
|
Attributes CustomerAttributes
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ func NewCustomer(nkodePolicy NKodePolicy) (*Customer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
customer := Customer{
|
customer := Customer{
|
||||||
Id: CustomerId(uuid.New()),
|
ID: CustomerID(uuid.New()),
|
||||||
NKodePolicy: nkodePolicy,
|
NKodePolicy: nkodePolicy,
|
||||||
Attributes: *customerAttrs,
|
Attributes: *customerAttrs,
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func (c *Customer) RenewKeys() ([]uint64, []uint64, error) {
|
|||||||
|
|
||||||
func (c *Customer) ToSqlcCreateCustomerParams() sqlc.CreateCustomerParams {
|
func (c *Customer) ToSqlcCreateCustomerParams() sqlc.CreateCustomerParams {
|
||||||
return sqlc.CreateCustomerParams{
|
return sqlc.CreateCustomerParams{
|
||||||
ID: uuid.UUID(c.Id).String(),
|
ID: uuid.UUID(c.ID).String(),
|
||||||
MaxNkodeLen: int64(c.NKodePolicy.MaxNkodeLen),
|
MaxNkodeLen: int64(c.NKodePolicy.MaxNkodeLen),
|
||||||
MinNkodeLen: int64(c.NKodePolicy.MinNkodeLen),
|
MinNkodeLen: int64(c.NKodePolicy.MinNkodeLen),
|
||||||
DistinctSets: int64(c.NKodePolicy.DistinctSets),
|
DistinctSets: int64(c.NKodePolicy.DistinctSets),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func testCustomerValidKeyEntry(t *testing.T) {
|
|||||||
nkodePolicy := NewDefaultNKodePolicy()
|
nkodePolicy := NewDefaultNKodePolicy()
|
||||||
customer, err := NewCustomer(nkodePolicy)
|
customer, err := NewCustomer(nkodePolicy)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
|
||||||
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
userEmail := "testing@example.com"
|
userEmail := "testing@example.com"
|
||||||
@@ -45,7 +45,7 @@ func testCustomerIsValidNKode(t *testing.T) {
|
|||||||
nkodePolicy := NewDefaultNKodePolicy()
|
nkodePolicy := NewDefaultNKodePolicy()
|
||||||
customer, err := NewCustomer(nkodePolicy)
|
customer, err := NewCustomer(nkodePolicy)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
|
||||||
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
userEmail := "testing123@example.com"
|
userEmail := "testing123@example.com"
|
||||||
|
|||||||
@@ -9,30 +9,30 @@ import (
|
|||||||
|
|
||||||
type KeySelection []int
|
type KeySelection []int
|
||||||
|
|
||||||
type CustomerId uuid.UUID
|
type CustomerID uuid.UUID
|
||||||
|
|
||||||
func (c *CustomerId) String() string {
|
func (c *CustomerID) String() string {
|
||||||
id := uuid.UUID(*c)
|
id := uuid.UUID(*c)
|
||||||
return id.String()
|
return id.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionId uuid.UUID
|
type SessionID uuid.UUID
|
||||||
type UserId uuid.UUID
|
type UserID uuid.UUID
|
||||||
|
|
||||||
func (u *UserId) String() string {
|
func (u *UserID) String() string {
|
||||||
id := uuid.UUID(*u)
|
id := uuid.UUID(*u)
|
||||||
return id.String()
|
return id.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserIdFromString(userId string) UserId {
|
func UserIDFromString(userID string) UserID {
|
||||||
id, err := uuid.Parse(userId)
|
id, err := uuid.Parse(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("unable to parse user id %+v", err)
|
fmt.Errorf("unable to parse user id %+v", err)
|
||||||
}
|
}
|
||||||
return UserId(id)
|
return UserID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SessionId) String() string {
|
func (s *SessionID) String() string {
|
||||||
id := uuid.UUID(*s)
|
id := uuid.UUID(*s)
|
||||||
return id.String()
|
return id.String()
|
||||||
}
|
}
|
||||||
@@ -49,15 +49,15 @@ func ParseEmail(email string) (UserEmail, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IdxInterface []int
|
type IdxInterface []int
|
||||||
type SvgIdInterface []int
|
type SvgIDInterface []int
|
||||||
|
|
||||||
func SessionIdFromString(sessionId string) (SessionId, error) {
|
func SessionIDFromString(sessionID string) (SessionID, error) {
|
||||||
id, err := uuid.Parse(sessionId)
|
id, err := uuid.Parse(sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SessionId{}, err
|
return SessionID{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return SessionId(id), nil
|
return SessionID(id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncipheredNKode struct {
|
type EncipheredNKode struct {
|
||||||
@@ -91,7 +91,7 @@ var SetColors = []RGBColor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SignupResetInterface struct {
|
type SignupResetInterface struct {
|
||||||
SessionId string `json:"session_id"`
|
SessionID string `json:"session_id"`
|
||||||
UserIdxInterface IdxInterface `json:"user_interface"`
|
UserIdxInterface IdxInterface `json:"user_interface"`
|
||||||
SvgInterface []string `json:"svg_interface"`
|
SvgInterface []string `json:"svg_interface"`
|
||||||
Colors []RGBColor `json:"colors"`
|
Colors []RGBColor `json:"colors"`
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id UserId
|
ID UserID
|
||||||
CustomerId CustomerId
|
CustomerID CustomerID
|
||||||
Email UserEmail
|
Email UserEmail
|
||||||
EncipheredPasscode EncipheredNKode
|
EncipheredPasscode EncipheredNKode
|
||||||
Kp KeypadDimension
|
Kp KeypadDimension
|
||||||
@@ -130,13 +130,13 @@ func NewUser(customer Customer, userEmail string, passcodeIdx []int, ui UserInte
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
newUser := User{
|
newUser := User{
|
||||||
Id: UserId(uuid.New()),
|
ID: UserID(uuid.New()),
|
||||||
Email: UserEmail(userEmail),
|
Email: UserEmail(userEmail),
|
||||||
EncipheredPasscode: *encipheredNKode,
|
EncipheredPasscode: *encipheredNKode,
|
||||||
CipherKeys: *newKeys,
|
CipherKeys: *newKeys,
|
||||||
Interface: ui,
|
Interface: ui,
|
||||||
Kp: kp,
|
Kp: kp,
|
||||||
CustomerId: customer.Id,
|
CustomerID: customer.ID,
|
||||||
}
|
}
|
||||||
return &newUser, nil
|
return &newUser, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ import (
|
|||||||
|
|
||||||
type UserInterface struct {
|
type UserInterface struct {
|
||||||
IdxInterface IdxInterface
|
IdxInterface IdxInterface
|
||||||
SvgId SvgIdInterface
|
SvgID SvgIDInterface
|
||||||
Kp *KeypadDimension
|
Kp *KeypadDimension
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserInterface(kp *KeypadDimension, svgId SvgIdInterface) (*UserInterface, error) {
|
func NewUserInterface(kp *KeypadDimension, svgID SvgIDInterface) (*UserInterface, error) {
|
||||||
idxInterface := security.IdentityArray(kp.TotalAttrs())
|
idxInterface := security.IdentityArray(kp.TotalAttrs())
|
||||||
userInterface := UserInterface{
|
userInterface := UserInterface{
|
||||||
IdxInterface: idxInterface,
|
IdxInterface: idxInterface,
|
||||||
SvgId: svgId,
|
SvgID: svgID,
|
||||||
Kp: kp,
|
Kp: kp,
|
||||||
}
|
}
|
||||||
if err := userInterface.RandomShuffle(); err != nil {
|
if err := userInterface.RandomShuffle(); err != nil {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UserSignSession struct {
|
type UserSignSession struct {
|
||||||
Id SessionId
|
ID SessionID
|
||||||
CustomerId CustomerId
|
CustomerID CustomerID
|
||||||
LoginUserInterface UserInterface
|
LoginUserInterface UserInterface
|
||||||
Kp KeypadDimension
|
Kp KeypadDimension
|
||||||
SetIdxInterface IdxInterface
|
SetIdxInterface IdxInterface
|
||||||
@@ -24,7 +24,7 @@ type UserSignSession struct {
|
|||||||
Colors []RGBColor
|
Colors []RGBColor
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId CustomerId, svgInterface SvgIdInterface, reset bool) (*UserSignSession, error) {
|
func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId CustomerID, svgInterface SvgIDInterface, reset bool) (*UserSignSession, error) {
|
||||||
loginInterface, err := NewUserInterface(&kp, svgInterface)
|
loginInterface, err := NewUserInterface(&kp, svgInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -34,8 +34,8 @@ func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId C
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
session := UserSignSession{
|
session := UserSignSession{
|
||||||
Id: SessionId(uuid.New()),
|
ID: SessionID(uuid.New()),
|
||||||
CustomerId: customerId,
|
CustomerID: customerId,
|
||||||
LoginUserInterface: *loginInterface,
|
LoginUserInterface: *loginInterface,
|
||||||
SetIdxInterface: signupInterface.IdxInterface,
|
SetIdxInterface: signupInterface.IdxInterface,
|
||||||
ConfirmIdxInterface: nil,
|
ConfirmIdxInterface: nil,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func TestUserInterface_RandomShuffle(t *testing.T) {
|
|||||||
AttrsPerKey: 10,
|
AttrsPerKey: 10,
|
||||||
NumbOfKeys: 8,
|
NumbOfKeys: 8,
|
||||||
}
|
}
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
|
||||||
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
userInterfaceCopy := make([]int, len(userInterface.IdxInterface))
|
userInterfaceCopy := make([]int, len(userInterface.IdxInterface))
|
||||||
@@ -87,7 +87,7 @@ func TestUserInterface_DisperseInterface(t *testing.T) {
|
|||||||
|
|
||||||
for idx := 0; idx < 10000; idx++ {
|
for idx := 0; idx < 10000; idx++ {
|
||||||
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
|
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
|
||||||
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
preDispersion, err := userInterface.AttributeAdjacencyGraph()
|
preDispersion, err := userInterface.AttributeAdjacencyGraph()
|
||||||
@@ -106,7 +106,7 @@ func TestUserInterface_DisperseInterface(t *testing.T) {
|
|||||||
|
|
||||||
func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
|
func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
|
||||||
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
|
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
|
||||||
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
userInterface, err := NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
preShuffle := userInterface.IdxInterface
|
preShuffle := userInterface.IdxInterface
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -7,6 +7,7 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2 v1.33.0
|
github.com/aws/aws-sdk-go-v2 v1.33.0
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.29.1
|
github.com/aws/aws-sdk-go-v2/config v1.29.1
|
||||||
github.com/aws/aws-sdk-go-v2/service/ses v1.29.6
|
github.com/aws/aws-sdk-go-v2/service/ses v1.29.6
|
||||||
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.24
|
github.com/mattn/go-sqlite3 v1.14.24
|
||||||
@@ -34,7 +35,6 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/gin-gonic/gin v1.10.0 // indirect
|
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -45,6 +45,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
|
|||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
@@ -55,6 +57,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
|||||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
@@ -115,6 +119,8 @@ golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
|||||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ type NkodeHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
malformedCustomerId = "malformed customer id"
|
malformedCustomerID = "malformed customer id"
|
||||||
malformedUserEmail = "malformed user email"
|
malformedUserEmail = "malformed user email"
|
||||||
malformedSessionId = "malformed session id"
|
malformedSessionID = "malformed session id"
|
||||||
invalidKeypadDimensions = "invalid keypad dimensions"
|
invalidKeypadDimensions = "invalid keypad dimensions"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,9 +78,9 @@ func (h *NkodeHandler) SignupHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
customerId, err := uuid.Parse(postBody.CustomerId)
|
customerId, err := uuid.Parse(postBody.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func (h *NkodeHandler) SignupHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerId(customerId), kp, false)
|
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerID(customerId), kp, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
@@ -106,18 +106,18 @@ func (h *NkodeHandler) SetNKodeHandler(c *gin.Context) {
|
|||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(postBody.CustomerId)
|
customerId, err := uuid.Parse(postBody.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionId, err := uuid.Parse(postBody.SessionId)
|
sessionId, err := uuid.Parse(postBody.SessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedSessionId)
|
c.String(400, malformedSessionID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmInterface, err := h.API.SetNKode(entities.CustomerId(customerId), entities.SessionId(sessionId), postBody.KeySelection)
|
confirmInterface, err := h.API.SetNKode(entities.CustomerID(customerId), entities.SessionID(sessionId), postBody.KeySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
@@ -133,17 +133,17 @@ func (h *NkodeHandler) ConfirmNKodeHandler(c *gin.Context) {
|
|||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(postBody.CustomerId)
|
customerId, err := uuid.Parse(postBody.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionId, err := uuid.Parse(postBody.SessionId)
|
sessionId, err := uuid.Parse(postBody.SessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedSessionId)
|
c.String(400, malformedSessionID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := h.API.ConfirmNKode(entities.CustomerId(customerId), entities.SessionId(sessionId), postBody.KeySelection); err != nil {
|
if err := h.API.ConfirmNKode(entities.CustomerID(customerId), entities.SessionID(sessionId), postBody.KeySelection); err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ func (h *NkodeHandler) GetLoginInterfaceHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
customerId, err := uuid.Parse(loginInterfacePost.CustomerId)
|
customerId, err := uuid.Parse(loginInterfacePost.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ func (h *NkodeHandler) GetLoginInterfaceHandler(c *gin.Context) {
|
|||||||
c.String(400, malformedUserEmail)
|
c.String(400, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
postBody, err := h.API.GetLoginInterface(userEmail, entities.CustomerId(customerId))
|
postBody, err := h.API.GetLoginInterface(userEmail, entities.CustomerID(customerId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
@@ -185,9 +185,9 @@ func (h *NkodeHandler) LoginHandler(c *gin.Context) {
|
|||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(loginPost.CustomerId)
|
customerId, err := uuid.Parse(loginPost.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ func (h *NkodeHandler) LoginHandler(c *gin.Context) {
|
|||||||
c.String(400, malformedUserEmail)
|
c.String(400, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jwtToken, err := h.API.Login(entities.CustomerId(customerId), userEmail, loginPost.KeySelection)
|
jwtToken, err := h.API.Login(entities.CustomerID(customerId), userEmail, loginPost.KeySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
@@ -213,13 +213,13 @@ func (h *NkodeHandler) RenewAttributesHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
customerId, err := uuid.Parse(renewAttributesPost.CustomerId)
|
customerId, err := uuid.Parse(renewAttributesPost.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.API.RenewAttributes(entities.CustomerId(customerId)); err != nil {
|
if err = h.API.RenewAttributes(entities.CustomerID(customerId)); err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ func (h *NkodeHandler) RefreshTokenHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(refreshClaims.Issuer)
|
customerId, err := uuid.Parse(refreshClaims.Issuer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := entities.ParseEmail(refreshClaims.Subject)
|
userEmail, err := entities.ParseEmail(refreshClaims.Subject)
|
||||||
@@ -259,7 +259,7 @@ func (h *NkodeHandler) RefreshTokenHandler(c *gin.Context) {
|
|||||||
c.String(400, malformedUserEmail)
|
c.String(400, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessToken, err := h.API.RefreshToken(userEmail, entities.CustomerId(customerId), refreshToken)
|
accessToken, err := h.API.RefreshToken(userEmail, entities.CustomerID(customerId), refreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
@@ -274,9 +274,9 @@ func (h *NkodeHandler) ForgotNKodeHandler(c *gin.Context) {
|
|||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(forgotNKodePost.CustomerId)
|
customerId, err := uuid.Parse(forgotNKodePost.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := entities.ParseEmail(forgotNKodePost.UserEmail)
|
userEmail, err := entities.ParseEmail(forgotNKodePost.UserEmail)
|
||||||
@@ -285,7 +285,7 @@ func (h *NkodeHandler) ForgotNKodeHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.API.ForgotNKode(userEmail, entities.CustomerId(customerId)); err != nil {
|
if err := h.API.ForgotNKode(userEmail, entities.CustomerID(customerId)); err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -306,7 +306,7 @@ func (h *NkodeHandler) SignoutHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(accessClaims.Issuer)
|
customerId, err := uuid.Parse(accessClaims.Issuer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := entities.ParseEmail(accessClaims.Subject)
|
userEmail, err := entities.ParseEmail(accessClaims.Subject)
|
||||||
@@ -314,7 +314,7 @@ func (h *NkodeHandler) SignoutHandler(c *gin.Context) {
|
|||||||
c.String(400, malformedUserEmail)
|
c.String(400, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = h.API.Signout(userEmail, entities.CustomerId(customerId)); err != nil {
|
if err = h.API.Signout(userEmail, entities.CustomerID(customerId)); err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -339,9 +339,9 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
|
|||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customerId, err := uuid.Parse(postBody.CustomerId)
|
customerId, err := uuid.Parse(postBody.CustomerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(400, malformedCustomerId)
|
c.String(400, malformedCustomerID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := entities.ParseEmail(postBody.UserEmail)
|
userEmail, err := entities.ParseEmail(postBody.UserEmail)
|
||||||
@@ -350,7 +350,7 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if postBody.UserEmail != resetClaims.Subject ||
|
if postBody.UserEmail != resetClaims.Subject ||
|
||||||
postBody.CustomerId != resetClaims.Issuer {
|
postBody.CustomerID != resetClaims.Issuer {
|
||||||
c.String(403, "forbidden")
|
c.String(403, "forbidden")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -364,7 +364,7 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
|
|||||||
c.String(400, invalidKeypadDimensions)
|
c.String(400, invalidKeypadDimensions)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerId(customerId), kp, true)
|
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerID(customerId), kp, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(c, err)
|
handleError(c, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// *** Set nKode ***
|
// *** Set nKode ***
|
||||||
confirmInterface, status, err := tr.SetNKode(customerID, setKeySelection, resp.SessionId)
|
confirmInterface, status, err := tr.SetNKode(customerID, setKeySelection, resp.SessionID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 200, status)
|
assert.Equal(t, 200, status)
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// *** Confirm nKode ***
|
// *** Confirm nKode ***
|
||||||
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resp.SessionId)
|
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resp.SessionID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 200, status)
|
assert.Equal(t, 200, status)
|
||||||
|
|
||||||
@@ -101,16 +101,16 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
resetResp, status, err := tr.Reset(customerID, attrPerKey, numKeys, userEmail, nkodeResetJwt)
|
resetResp, status, err := tr.Reset(customerID, attrPerKey, numKeys, userEmail, nkodeResetJwt)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 200, status)
|
assert.Equal(t, 200, status)
|
||||||
assert.NotEmpty(t, resetResp.SessionId)
|
assert.NotEmpty(t, resetResp.SessionID)
|
||||||
userPasscode = resetResp.UserIdxInterface[:passcodeLen]
|
userPasscode = resetResp.UserIdxInterface[:passcodeLen]
|
||||||
setKeySelection, err = entities.SelectKeyByAttrIdx(resetResp.UserIdxInterface, userPasscode, kpSet)
|
setKeySelection, err = entities.SelectKeyByAttrIdx(resetResp.UserIdxInterface, userPasscode, kpSet)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmInterface, status, err = tr.SetNKode(customerID, setKeySelection, resetResp.SessionId)
|
confirmInterface, status, err = tr.SetNKode(customerID, setKeySelection, resetResp.SessionID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 200, status)
|
assert.Equal(t, 200, status)
|
||||||
confirmKeySelection, err = entities.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet)
|
confirmKeySelection, err = entities.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resetResp.SessionId)
|
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resetResp.SessionID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 200, status)
|
assert.Equal(t, 200, status)
|
||||||
loginInterface, status, err = tr.GetLoginInterface(userEmail, customerID)
|
loginInterface, status, err = tr.GetLoginInterface(userEmail, customerID)
|
||||||
@@ -133,7 +133,7 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
type TestRouter struct {
|
type TestRouter struct {
|
||||||
router *gin.Engine
|
router *gin.Engine
|
||||||
emailQueue *email.Queue
|
emailQueue *email.Queue
|
||||||
repo *repository.SqliteRepository
|
repo *repository.SqliteNKodeRepo
|
||||||
handler *NkodeHandler
|
handler *NkodeHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ func NewTestRouter() *TestRouter {
|
|||||||
logger := log.Default()
|
logger := log.Default()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
dbPath := os.Getenv("TEST_DB")
|
dbPath := os.Getenv("TEST_DB")
|
||||||
repo, err := repository.NewSqliteRepository(ctx, dbPath)
|
repo, err := repository.NewSqliteNKodeRepo(ctx, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -211,9 +211,9 @@ func (r *TestRouter) SetNKode(
|
|||||||
sessionID string,
|
sessionID string,
|
||||||
) ([]int, int, error) {
|
) ([]int, int, error) {
|
||||||
data := models.SetNKodePost{
|
data := models.SetNKodePost{
|
||||||
CustomerId: customerID,
|
CustomerID: customerID,
|
||||||
KeySelection: selection,
|
KeySelection: selection,
|
||||||
SessionId: sessionID,
|
SessionID: sessionID,
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(data)
|
body, err := json.Marshal(data)
|
||||||
@@ -240,9 +240,9 @@ func (r *TestRouter) ConfirmNKode(
|
|||||||
sessionID string,
|
sessionID string,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
data := models.ConfirmNKodePost{
|
data := models.ConfirmNKodePost{
|
||||||
CustomerId: customerID,
|
CustomerID: customerID,
|
||||||
KeySelection: selection,
|
KeySelection: selection,
|
||||||
SessionId: sessionID,
|
SessionID: sessionID,
|
||||||
}
|
}
|
||||||
body, err := json.Marshal(data)
|
body, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -282,7 +282,7 @@ func (r *TestRouter) Login(
|
|||||||
selection []int,
|
selection []int,
|
||||||
) (security.AuthenticationTokens, int, error) {
|
) (security.AuthenticationTokens, int, error) {
|
||||||
data := models.LoginPost{
|
data := models.LoginPost{
|
||||||
CustomerId: customerID,
|
CustomerID: customerID,
|
||||||
UserEmail: userEmail,
|
UserEmail: userEmail,
|
||||||
KeySelection: selection,
|
KeySelection: selection,
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ func (r *TestRouter) RenewAttributes(
|
|||||||
customerID string,
|
customerID string,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
data := models.RenewAttributesPost{
|
data := models.RenewAttributesPost{
|
||||||
CustomerId: customerID,
|
CustomerID: customerID,
|
||||||
}
|
}
|
||||||
body, err := json.Marshal(data)
|
body, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -323,7 +323,7 @@ func (r *TestRouter) ForgotNKode(
|
|||||||
userEmail string,
|
userEmail string,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
data := models.ForgotNKodePost{
|
data := models.ForgotNKodePost{
|
||||||
CustomerId: customerID,
|
CustomerID: customerID,
|
||||||
UserEmail: userEmail,
|
UserEmail: userEmail,
|
||||||
}
|
}
|
||||||
body, err := json.Marshal(data)
|
body, err := json.Marshal(data)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package memCache
|
package memcache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
||||||
@@ -20,19 +20,19 @@ func NewForgotNKodeCache() ForgotNKodeCache {
|
|||||||
return ForgotNKodeCache{forgotCache}
|
return ForgotNKodeCache{forgotCache}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgotNKodeCache) Set(userEmail entities.UserEmail, customerId entities.CustomerId) {
|
func (f *ForgotNKodeCache) Set(userEmail entities.UserEmail, customerId entities.CustomerID) {
|
||||||
f.innerCache.Set(key(userEmail, customerId), true, forgotExpiration)
|
f.innerCache.Set(key(userEmail, customerId), true, forgotExpiration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgotNKodeCache) Get(userEmail entities.UserEmail, customerId entities.CustomerId) bool {
|
func (f *ForgotNKodeCache) Get(userEmail entities.UserEmail, customerId entities.CustomerID) bool {
|
||||||
_, found := f.innerCache.Get(key(userEmail, customerId))
|
_, found := f.innerCache.Get(key(userEmail, customerId))
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ForgotNKodeCache) Delete(userEmail entities.UserEmail, customerId entities.CustomerId) {
|
func (f *ForgotNKodeCache) Delete(userEmail entities.UserEmail, customerId entities.CustomerID) {
|
||||||
f.innerCache.Delete(key(userEmail, customerId))
|
f.innerCache.Delete(key(userEmail, customerId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func key(email entities.UserEmail, id entities.CustomerId) string {
|
func key(email entities.UserEmail, id entities.CustomerID) string {
|
||||||
return string(email) + id.String()
|
return string(email) + id.String()
|
||||||
}
|
}
|
||||||
@@ -16,44 +16,44 @@ type RefreshTokenResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SignupPostBody struct {
|
type SignupPostBody struct {
|
||||||
CustomerId string `form:"customer_id"`
|
CustomerID string `form:"customer_id"`
|
||||||
AttrsPerKey int `form:"attrs_per_key"`
|
AttrsPerKey int `form:"attrs_per_key"`
|
||||||
NumbOfKeys int `form:"numb_of_keys"`
|
NumbOfKeys int `form:"numb_of_keys"`
|
||||||
UserEmail string `form:"email"`
|
UserEmail string `form:"email"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetNKodePost struct {
|
type SetNKodePost struct {
|
||||||
CustomerId string `json:"customer_id" binding:"required"`
|
CustomerID string `json:"customer_id" binding:"required"`
|
||||||
KeySelection []int `json:"key_selection" binding:"required"`
|
KeySelection []int `json:"key_selection" binding:"required"`
|
||||||
SessionId string `json:"session_id" binding:"required"`
|
SessionID string `json:"session_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfirmNKodePost struct {
|
type ConfirmNKodePost struct {
|
||||||
CustomerId string `json:"customer_id" binding:"required"`
|
CustomerID string `json:"customer_id" binding:"required"`
|
||||||
KeySelection []int `json:"key_selection" binding:"required"`
|
KeySelection []int `json:"key_selection" binding:"required"`
|
||||||
SessionId string `json:"session_id" binding:"required"`
|
SessionID string `json:"session_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginInterfacePost struct {
|
type LoginInterfacePost struct {
|
||||||
UserEmail string `form:"email" binding:"required"`
|
UserEmail string `form:"email" binding:"required"`
|
||||||
CustomerId string `form:"customer_id" binding:"required"`
|
CustomerID string `form:"customer_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginPost struct {
|
type LoginPost struct {
|
||||||
CustomerId string `form:"customer_id" binding:"required"`
|
CustomerID string `form:"customer_id" binding:"required"`
|
||||||
UserEmail string `form:"email" binding:"required"`
|
UserEmail string `form:"email" binding:"required"`
|
||||||
KeySelection entities.KeySelection `form:"key_selection" binding:"required"`
|
KeySelection entities.KeySelection `form:"key_selection" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenewAttributesPost struct {
|
type RenewAttributesPost struct {
|
||||||
CustomerId string `form:"customer_id" binding:"required"`
|
CustomerID string `form:"customer_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForgotNKodePost struct {
|
type ForgotNKodePost struct {
|
||||||
UserEmail string `form:"email" binding:"required"`
|
UserEmail string `form:"email" binding:"required"`
|
||||||
CustomerId string `form:"customer_id" binding:"required"`
|
CustomerID string `form:"customer_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNewCustomerResp struct {
|
type CreateNewCustomerResp struct {
|
||||||
CustomerId string `form:"customer_id" binding:"required"`
|
CustomerID string `form:"customer_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CustomerUserRepository interface {
|
type CustomerUserRepository interface {
|
||||||
GetCustomer(entities.CustomerId) (*entities.Customer, error)
|
GetCustomer(entities.CustomerID) (*entities.Customer, error)
|
||||||
GetUser(entities.UserEmail, entities.CustomerId) (*entities.User, error)
|
GetUser(entities.UserEmail, entities.CustomerID) (*entities.User, error)
|
||||||
CreateCustomer(entities.Customer) error
|
CreateCustomer(entities.Customer) error
|
||||||
WriteNewUser(entities.User) error
|
WriteNewUser(entities.User) error
|
||||||
UpdateUserNKode(entities.User) error
|
UpdateUserNKode(entities.User) error
|
||||||
UpdateUserInterface(entities.UserId, entities.UserInterface) error
|
UpdateUserInterface(entities.UserID, entities.UserInterface) error
|
||||||
UpdateUserRefreshToken(entities.UserId, string) error
|
UpdateUserRefreshToken(entities.UserID, string) error
|
||||||
Renew(entities.CustomerId) error
|
Renew(entities.CustomerID) error
|
||||||
RefreshUserPasscode(entities.User, []int, entities.CustomerAttributes) error
|
RefreshUserPasscode(entities.User, []int, entities.CustomerAttributes) error
|
||||||
RandomSvgInterface(entities.KeypadDimension) ([]string, error)
|
RandomSvgInterface(entities.KeypadDimension) ([]string, error)
|
||||||
RandomSvgIdxInterface(entities.KeypadDimension) (entities.SvgIdInterface, error)
|
RandomSvgIdxInterface(entities.KeypadDimension) (entities.SvgIDInterface, error)
|
||||||
GetSvgStringInterface(entities.SvgIdInterface) ([]string, error)
|
GetSvgStringInterface(entities.SvgIDInterface) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SqliteRepository struct {
|
type SqliteNKodeRepo struct {
|
||||||
Queue *sqlc.Queue
|
Queue *sqlc.Queue
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSqliteRepository(ctx context.Context, dbPath string) (*SqliteRepository, error) {
|
func NewSqliteNKodeRepo(ctx context.Context, dbPath string) (*SqliteNKodeRepo, error) {
|
||||||
sqliteDb, err := sqlc.OpenSqliteDb(dbPath)
|
sqliteDb, err := sqlc.OpenSqliteDb(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -28,21 +28,21 @@ func NewSqliteRepository(ctx context.Context, dbPath string) (*SqliteRepository,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &SqliteRepository{
|
return &SqliteNKodeRepo{
|
||||||
Queue: queue,
|
Queue: queue,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) Start() {
|
func (d *SqliteNKodeRepo) Start() {
|
||||||
d.Queue.Start()
|
d.Queue.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) Stop() error {
|
func (d *SqliteNKodeRepo) Stop() error {
|
||||||
return d.Queue.Stop()
|
return d.Queue.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) CreateCustomer(c entities.Customer) error {
|
func (d *SqliteNKodeRepo) CreateCustomer(c entities.Customer) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.CreateCustomerParams)
|
params, ok := args.(sqlc.CreateCustomerParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -54,7 +54,7 @@ func (d *SqliteRepository) CreateCustomer(c entities.Customer) error {
|
|||||||
return d.Queue.EnqueueWriteTx(queryFunc, c.ToSqlcCreateCustomerParams())
|
return d.Queue.EnqueueWriteTx(queryFunc, c.ToSqlcCreateCustomerParams())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) WriteNewUser(u entities.User) error {
|
func (d *SqliteNKodeRepo) WriteNewUser(u entities.User) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.CreateUserParams)
|
params, ok := args.(sqlc.CreateUserParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -70,11 +70,11 @@ func (d *SqliteRepository) WriteNewUser(u entities.User) error {
|
|||||||
}
|
}
|
||||||
// Map entities.User to CreateUserParams
|
// Map entities.User to CreateUserParams
|
||||||
params := sqlc.CreateUserParams{
|
params := sqlc.CreateUserParams{
|
||||||
ID: uuid.UUID(u.Id).String(),
|
ID: uuid.UUID(u.ID).String(),
|
||||||
Email: string(u.Email),
|
Email: string(u.Email),
|
||||||
Renew: int64(renew),
|
Renew: int64(renew),
|
||||||
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
|
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
|
||||||
CustomerID: uuid.UUID(u.CustomerId).String(),
|
CustomerID: uuid.UUID(u.CustomerID).String(),
|
||||||
Code: u.EncipheredPasscode.Code,
|
Code: u.EncipheredPasscode.Code,
|
||||||
Mask: u.EncipheredPasscode.Mask,
|
Mask: u.EncipheredPasscode.Mask,
|
||||||
AttributesPerKey: int64(u.Kp.AttrsPerKey),
|
AttributesPerKey: int64(u.Kp.AttrsPerKey),
|
||||||
@@ -86,13 +86,13 @@ func (d *SqliteRepository) WriteNewUser(u entities.User) error {
|
|||||||
Salt: u.CipherKeys.Salt,
|
Salt: u.CipherKeys.Salt,
|
||||||
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
|
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
|
||||||
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
|
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
|
||||||
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgId),
|
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgID),
|
||||||
CreatedAt: sql.NullString{String: utils.TimeStamp(), Valid: true},
|
CreatedAt: sql.NullString{String: utils.TimeStamp(), Valid: true},
|
||||||
}
|
}
|
||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
|
func (d *SqliteNKodeRepo) UpdateUserNKode(u entities.User) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.UpdateUserParams)
|
params, ok := args.(sqlc.UpdateUserParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -109,7 +109,7 @@ func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
|
|||||||
Email: string(u.Email),
|
Email: string(u.Email),
|
||||||
Renew: int64(renew),
|
Renew: int64(renew),
|
||||||
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
|
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
|
||||||
CustomerID: uuid.UUID(u.CustomerId).String(),
|
CustomerID: uuid.UUID(u.CustomerID).String(),
|
||||||
Code: u.EncipheredPasscode.Code,
|
Code: u.EncipheredPasscode.Code,
|
||||||
Mask: u.EncipheredPasscode.Mask,
|
Mask: u.EncipheredPasscode.Mask,
|
||||||
AttributesPerKey: int64(u.Kp.AttrsPerKey),
|
AttributesPerKey: int64(u.Kp.AttrsPerKey),
|
||||||
@@ -121,12 +121,12 @@ func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
|
|||||||
Salt: u.CipherKeys.Salt,
|
Salt: u.CipherKeys.Salt,
|
||||||
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
|
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
|
||||||
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
|
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
|
||||||
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgId),
|
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgID),
|
||||||
}
|
}
|
||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) UpdateUserInterface(id entities.UserId, ui entities.UserInterface) error {
|
func (d *SqliteNKodeRepo) UpdateUserInterface(id entities.UserID, ui entities.UserInterface) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.UpdateUserInterfaceParams)
|
params, ok := args.(sqlc.UpdateUserInterfaceParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -143,7 +143,7 @@ func (d *SqliteRepository) UpdateUserInterface(id entities.UserId, ui entities.U
|
|||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) UpdateUserRefreshToken(id entities.UserId, refreshToken string) error {
|
func (d *SqliteNKodeRepo) UpdateUserRefreshToken(id entities.UserID, refreshToken string) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
|
params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -161,7 +161,7 @@ func (d *SqliteRepository) UpdateUserRefreshToken(id entities.UserId, refreshTok
|
|||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) RenewCustomer(renewParams sqlc.RenewCustomerParams) error {
|
func (d *SqliteNKodeRepo) RenewCustomer(renewParams sqlc.RenewCustomerParams) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(sqlc.RenewCustomerParams)
|
params, ok := args.(sqlc.RenewCustomerParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -172,7 +172,7 @@ func (d *SqliteRepository) RenewCustomer(renewParams sqlc.RenewCustomerParams) e
|
|||||||
return d.Queue.EnqueueWriteTx(queryFunc, renewParams)
|
return d.Queue.EnqueueWriteTx(queryFunc, renewParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
func (d *SqliteNKodeRepo) Renew(id entities.CustomerID) error {
|
||||||
setXor, attrXor, err := d.renewCustomer(id)
|
setXor, attrXor, err := d.renewCustomer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -192,8 +192,8 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
|||||||
|
|
||||||
for _, row := range userRenewRows {
|
for _, row := range userRenewRows {
|
||||||
user := entities.User{
|
user := entities.User{
|
||||||
Id: entities.UserIdFromString(row.ID),
|
ID: entities.UserIDFromString(row.ID),
|
||||||
CustomerId: entities.CustomerId{},
|
CustomerID: entities.CustomerID{},
|
||||||
Email: "",
|
Email: "",
|
||||||
EncipheredPasscode: entities.EncipheredNKode{},
|
EncipheredPasscode: entities.EncipheredNKode{},
|
||||||
Kp: entities.KeypadDimension{
|
Kp: entities.KeypadDimension{
|
||||||
@@ -215,7 +215,7 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
|||||||
AlphaKey: security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey),
|
AlphaKey: security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey),
|
||||||
SetKey: security.Uint64ArrToByteArr(user.CipherKeys.SetKey),
|
SetKey: security.Uint64ArrToByteArr(user.CipherKeys.SetKey),
|
||||||
Renew: 1,
|
Renew: 1,
|
||||||
ID: uuid.UUID(user.Id).String(),
|
ID: uuid.UUID(user.ID).String(),
|
||||||
}
|
}
|
||||||
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
|
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -224,7 +224,7 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []uint64, error) {
|
func (d *SqliteNKodeRepo) renewCustomer(id entities.CustomerID) ([]uint64, []uint64, error) {
|
||||||
customer, err := d.GetCustomer(id)
|
customer, err := d.GetCustomer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -244,7 +244,7 @@ func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []ui
|
|||||||
params := sqlc.RenewCustomerParams{
|
params := sqlc.RenewCustomerParams{
|
||||||
AttributeValues: security.Uint64ArrToByteArr(customer.Attributes.AttrVals),
|
AttributeValues: security.Uint64ArrToByteArr(customer.Attributes.AttrVals),
|
||||||
SetValues: security.Uint64ArrToByteArr(customer.Attributes.SetVals),
|
SetValues: security.Uint64ArrToByteArr(customer.Attributes.SetVals),
|
||||||
ID: uuid.UUID(customer.Id).String(),
|
ID: uuid.UUID(customer.ID).String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
|
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
|
||||||
@@ -253,7 +253,7 @@ func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []ui
|
|||||||
return setXor, attrXor, nil
|
return setXor, attrXor, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) RefreshUserPasscode(user entities.User, passcodeIdx []int, customerAttr entities.CustomerAttributes) error {
|
func (d *SqliteNKodeRepo) RefreshUserPasscode(user entities.User, passcodeIdx []int, customerAttr entities.CustomerAttributes) error {
|
||||||
if err := user.RefreshPasscode(passcodeIdx, customerAttr); err != nil {
|
if err := user.RefreshPasscode(passcodeIdx, customerAttr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -273,12 +273,12 @@ func (d *SqliteRepository) RefreshUserPasscode(user entities.User, passcodeIdx [
|
|||||||
PassKey: security.Uint64ArrToByteArr(user.CipherKeys.PassKey),
|
PassKey: security.Uint64ArrToByteArr(user.CipherKeys.PassKey),
|
||||||
MaskKey: security.Uint64ArrToByteArr(user.CipherKeys.MaskKey),
|
MaskKey: security.Uint64ArrToByteArr(user.CipherKeys.MaskKey),
|
||||||
Salt: user.CipherKeys.Salt,
|
Salt: user.CipherKeys.Salt,
|
||||||
ID: uuid.UUID(user.Id).String(),
|
ID: uuid.UUID(user.ID).String(),
|
||||||
}
|
}
|
||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) AddSvg(svg string) error {
|
func (d *SqliteNKodeRepo) AddSvg(svg string) error {
|
||||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||||
params, ok := args.(string)
|
params, ok := args.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -289,14 +289,14 @@ func (d *SqliteRepository) AddSvg(svg string) error {
|
|||||||
return d.Queue.EnqueueWriteTx(queryFunc, svg)
|
return d.Queue.EnqueueWriteTx(queryFunc, svg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) GetCustomer(id entities.CustomerId) (*entities.Customer, error) {
|
func (d *SqliteNKodeRepo) GetCustomer(id entities.CustomerID) (*entities.Customer, error) {
|
||||||
customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String())
|
customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &entities.Customer{
|
return &entities.Customer{
|
||||||
Id: id,
|
ID: id,
|
||||||
NKodePolicy: entities.NKodePolicy{
|
NKodePolicy: entities.NKodePolicy{
|
||||||
MaxNkodeLen: int(customer.MaxNkodeLen),
|
MaxNkodeLen: int(customer.MaxNkodeLen),
|
||||||
MinNkodeLen: int(customer.MinNkodeLen),
|
MinNkodeLen: int(customer.MinNkodeLen),
|
||||||
@@ -309,10 +309,10 @@ func (d *SqliteRepository) GetCustomer(id entities.CustomerId) (*entities.Custom
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities.CustomerId) (*entities.User, error) {
|
func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerID entities.CustomerID) (*entities.User, error) {
|
||||||
userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{
|
userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{
|
||||||
Email: string(email),
|
Email: string(email),
|
||||||
CustomerID: uuid.UUID(customerId).String(),
|
CustomerID: uuid.UUID(customerID).String(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
@@ -331,8 +331,8 @@ func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities
|
|||||||
renew = true
|
renew = true
|
||||||
}
|
}
|
||||||
user := entities.User{
|
user := entities.User{
|
||||||
Id: entities.UserIdFromString(userRow.ID),
|
ID: entities.UserIDFromString(userRow.ID),
|
||||||
CustomerId: customerId,
|
CustomerID: customerID,
|
||||||
Email: email,
|
Email: email,
|
||||||
EncipheredPasscode: entities.EncipheredNKode{
|
EncipheredPasscode: entities.EncipheredNKode{
|
||||||
Code: userRow.Code,
|
Code: userRow.Code,
|
||||||
@@ -350,7 +350,7 @@ func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities
|
|||||||
},
|
},
|
||||||
Interface: entities.UserInterface{
|
Interface: entities.UserInterface{
|
||||||
IdxInterface: security.ByteArrToIntArr(userRow.IdxInterface),
|
IdxInterface: security.ByteArrToIntArr(userRow.IdxInterface),
|
||||||
SvgId: security.ByteArrToIntArr(userRow.SvgIDInterface),
|
SvgID: security.ByteArrToIntArr(userRow.SvgIDInterface),
|
||||||
Kp: &kp,
|
Kp: &kp,
|
||||||
},
|
},
|
||||||
Renew: renew,
|
Renew: renew,
|
||||||
@@ -359,25 +359,25 @@ func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities
|
|||||||
return &user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
|
func (d *SqliteNKodeRepo) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
|
||||||
ids, err := d.getRandomIds(kp.TotalAttrs())
|
ids, err := d.getRandomIDs(kp.TotalAttrs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return d.getSvgsById(ids)
|
return d.getSvgsByID(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIdInterface, error) {
|
func (d *SqliteNKodeRepo) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIDInterface, error) {
|
||||||
return d.getRandomIds(kp.TotalAttrs())
|
return d.getRandomIDs(kp.TotalAttrs())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
|
func (d *SqliteNKodeRepo) GetSvgStringInterface(idxs entities.SvgIDInterface) ([]string, error) {
|
||||||
return d.getSvgsById(idxs)
|
return d.getSvgsByID(idxs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this even useful?
|
// Is this even useful?
|
||||||
func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, customerId entities.CustomerId, permission entities.UserPermission) error {
|
func (d *SqliteNKodeRepo) AddUserPermission(userEmail entities.UserEmail, customerID entities.CustomerID, permission entities.UserPermission) error {
|
||||||
user, err := d.GetUser(userEmail, customerId)
|
user, err := d.GetUser(userEmail, customerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -389,16 +389,16 @@ func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, custo
|
|||||||
return q.AddUserPermission(ctx, params)
|
return q.AddUserPermission(ctx, params)
|
||||||
}
|
}
|
||||||
params := sqlc.AddUserPermissionParams{
|
params := sqlc.AddUserPermissionParams{
|
||||||
UserID: user.Id.String(),
|
UserID: user.ID.String(),
|
||||||
Permission: permission.String(),
|
Permission: permission.String(),
|
||||||
}
|
}
|
||||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
func (d *SqliteNKodeRepo) getSvgsByID(ids []int) ([]string, error) {
|
||||||
svgs := make([]string, len(ids))
|
svgs := make([]string, len(ids))
|
||||||
for idx, id := range ids {
|
for idx, id := range ids {
|
||||||
svg, err := d.Queue.Queries.GetSvgId(d.ctx, int64(id))
|
svg, err := d.Queue.Queries.GetSvgID(d.ctx, int64(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -407,7 +407,7 @@ func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
|||||||
return svgs, nil
|
return svgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
|
func (d *SqliteNKodeRepo) getRandomIDs(count int) ([]int, error) {
|
||||||
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@@ -11,10 +11,10 @@ import (
|
|||||||
func TestNewSqliteDB(t *testing.T) {
|
func TestNewSqliteDB(t *testing.T) {
|
||||||
dbPath := os.Getenv("TEST_DB")
|
dbPath := os.Getenv("TEST_DB")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sqliteDb, err := NewSqliteRepository(ctx, dbPath)
|
sqliteDb, err := NewSqliteNKodeRepo(ctx, dbPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
sqliteDb.Start()
|
sqliteDb.Start()
|
||||||
defer func(t *testing.T, sqliteDb *SqliteRepository) {
|
defer func(t *testing.T, sqliteDb *SqliteNKodeRepo) {
|
||||||
err := sqliteDb.Stop()
|
err := sqliteDb.Stop()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}(t, sqliteDb)
|
}(t, sqliteDb)
|
||||||
@@ -28,24 +28,24 @@ func testSignupLoginRenew(t *testing.T, db CustomerUserRepository) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = db.CreateCustomer(*customerOrig)
|
err = db.CreateCustomer(*customerOrig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
customer, err := db.GetCustomer(customerOrig.Id)
|
customer, err := db.GetCustomer(customerOrig.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, customerOrig, customer)
|
assert.Equal(t, customerOrig, customer)
|
||||||
username := "test_user@example.com"
|
username := "test_user@example.com"
|
||||||
kp := entities.KeypadDefault
|
kp := entities.KeypadDefault
|
||||||
passcodeIdx := []int{0, 1, 2, 3}
|
passcodeIdx := []int{0, 1, 2, 3}
|
||||||
mockSvgInterface := make(entities.SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(entities.SvgIDInterface, kp.TotalAttrs())
|
||||||
ui, err := entities.NewUserInterface(&kp, mockSvgInterface)
|
ui, err := entities.NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
userOrig, err := entities.NewUser(*customer, username, passcodeIdx, *ui, kp)
|
userOrig, err := entities.NewUser(*customer, username, passcodeIdx, *ui, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = db.WriteNewUser(*userOrig)
|
err = db.WriteNewUser(*userOrig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := db.GetUser(entities.UserEmail(username), customer.Id)
|
user, err := db.GetUser(entities.UserEmail(username), customer.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, userOrig, user)
|
assert.Equal(t, userOrig, user)
|
||||||
|
|
||||||
err = db.Renew(customer.Id)
|
err = db.Renew(customer.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,43 @@ package sqlc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AuthorizationCode struct {
|
||||||
|
ID int64
|
||||||
|
Code string
|
||||||
|
CodeChallenge string
|
||||||
|
CodeChallengeMethod string
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
Scope sql.NullString
|
||||||
|
RedirectUri string
|
||||||
|
CreatedAt sql.NullTime
|
||||||
|
ExpiresAt time.Time
|
||||||
|
UsedAt sql.NullTime
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Owner string
|
||||||
|
CreatedAt sql.NullTime
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientApproval struct {
|
||||||
|
ID int64
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClientRedirect struct {
|
||||||
|
ID int64
|
||||||
|
Uri string
|
||||||
|
ClientID string
|
||||||
|
CreatedAt sql.NullTime
|
||||||
|
}
|
||||||
|
|
||||||
type Customer struct {
|
type Customer struct {
|
||||||
ID string
|
ID string
|
||||||
MaxNkodeLen int64
|
MaxNkodeLen int64
|
||||||
@@ -22,11 +57,29 @@ type Customer struct {
|
|||||||
CreatedAt string
|
CreatedAt string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Session struct {
|
||||||
|
ID string
|
||||||
|
UserID string
|
||||||
|
CreatedAt sql.NullTime
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type SvgIcon struct {
|
type SvgIcon struct {
|
||||||
ID int64
|
ID int64
|
||||||
Svg string
|
Svg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Token struct {
|
||||||
|
ID int64
|
||||||
|
TokenType string
|
||||||
|
TokenValue string
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
Scope sql.NullString
|
||||||
|
CreatedAt sql.NullTime
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string
|
ID string
|
||||||
Email string
|
Email string
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package sqlc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const addSvg = `-- name: AddSvg :exec
|
const addSvg = `-- name: AddSvg :exec
|
||||||
@@ -33,6 +34,69 @@ func (q *Queries) AddUserPermission(ctx context.Context, arg AddUserPermissionPa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const approveClient = `-- name: ApproveClient :exec
|
||||||
|
INSERT INTO client_approvals (user_id, client_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type ApproveClientParams struct {
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) ApproveClient(ctx context.Context, arg ApproveClientParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, approveClient, arg.UserID, arg.ClientID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientApproved = `-- name: ClientApproved :one
|
||||||
|
SELECT id, user_id, client_id
|
||||||
|
FROM client_approvals
|
||||||
|
WHERE user_id = ? AND client_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
type ClientApprovedParams struct {
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) ClientApproved(ctx context.Context, arg ClientApprovedParams) (ClientApproval, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, clientApproved, arg.UserID, arg.ClientID)
|
||||||
|
var i ClientApproval
|
||||||
|
err := row.Scan(&i.ID, &i.UserID, &i.ClientID)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createAuthorizationCode = `-- name: CreateAuthorizationCode :exec
|
||||||
|
INSERT INTO authorization_codes (code, code_challenge, code_challenge_method, user_id, client_id, scope, redirect_uri, expires_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateAuthorizationCodeParams struct {
|
||||||
|
Code string
|
||||||
|
CodeChallenge string
|
||||||
|
CodeChallengeMethod string
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
Scope sql.NullString
|
||||||
|
RedirectUri string
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateAuthorizationCode(ctx context.Context, arg CreateAuthorizationCodeParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createAuthorizationCode,
|
||||||
|
arg.Code,
|
||||||
|
arg.CodeChallenge,
|
||||||
|
arg.CodeChallengeMethod,
|
||||||
|
arg.UserID,
|
||||||
|
arg.ClientID,
|
||||||
|
arg.Scope,
|
||||||
|
arg.RedirectUri,
|
||||||
|
arg.ExpiresAt,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const createCustomer = `-- name: CreateCustomer :exec
|
const createCustomer = `-- name: CreateCustomer :exec
|
||||||
INSERT INTO customer (
|
INSERT INTO customer (
|
||||||
id
|
id
|
||||||
@@ -81,6 +145,79 @@ func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createOIDCClient = `-- name: CreateOIDCClient :exec
|
||||||
|
INSERT INTO clients (id, name, owner)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateOIDCClientParams struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Owner string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateOIDCClient(ctx context.Context, arg CreateOIDCClientParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createOIDCClient, arg.ID, arg.Name, arg.Owner)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createRedirectURI = `-- name: CreateRedirectURI :exec
|
||||||
|
INSERT INTO client_redirects (uri, client_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateRedirectURIParams struct {
|
||||||
|
Uri string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateRedirectURI(ctx context.Context, arg CreateRedirectURIParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createRedirectURI, arg.Uri, arg.ClientID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createSession = `-- name: CreateSession :exec
|
||||||
|
INSERT INTO sessions (id, user_id, expires_at)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateSessionParams struct {
|
||||||
|
ID string
|
||||||
|
UserID string
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createSession, arg.ID, arg.UserID, arg.ExpiresAt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const createToken = `-- name: CreateToken :exec
|
||||||
|
INSERT INTO tokens (token_type, token_value, user_id, client_id, scope, expires_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
type CreateTokenParams struct {
|
||||||
|
TokenType string
|
||||||
|
TokenValue string
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
Scope sql.NullString
|
||||||
|
ExpiresAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) CreateToken(ctx context.Context, arg CreateTokenParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, createToken,
|
||||||
|
arg.TokenType,
|
||||||
|
arg.TokenValue,
|
||||||
|
arg.UserID,
|
||||||
|
arg.ClientID,
|
||||||
|
arg.Scope,
|
||||||
|
arg.ExpiresAt,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const createUser = `-- name: CreateUser :exec
|
const createUser = `-- name: CreateUser :exec
|
||||||
INSERT INTO user (
|
INSERT INTO user (
|
||||||
id
|
id
|
||||||
@@ -150,6 +287,130 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteAuthCode = `-- name: DeleteAuthCode :exec
|
||||||
|
DELETE FROM authorization_codes
|
||||||
|
WHERE code = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteAuthCode(ctx context.Context, code string) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteAuthCode, code)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteOldAuthCodes = `-- name: DeleteOldAuthCodes :exec
|
||||||
|
DELETE FROM authorization_codes
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteOldAuthCodes(ctx context.Context) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteOldAuthCodes)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteOldSessions = `-- name: DeleteOldSessions :exec
|
||||||
|
DELETE FROM sessions
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteOldSessions(ctx context.Context) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteOldSessions)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteOldTokens = `-- name: DeleteOldTokens :exec
|
||||||
|
DELETE FROM tokens
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteOldTokens(ctx context.Context) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteOldTokens)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteRedirectURI = `-- name: DeleteRedirectURI :exec
|
||||||
|
DELETE FROM client_redirects
|
||||||
|
WHERE uri = ? AND client_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
type DeleteRedirectURIParams struct {
|
||||||
|
Uri string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) DeleteRedirectURI(ctx context.Context, arg DeleteRedirectURIParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteRedirectURI, arg.Uri, arg.ClientID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteSession = `-- name: DeleteSession :exec
|
||||||
|
DELETE FROM sessions
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteSession(ctx context.Context, id string) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteSession, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getAuthorizationCode = `-- name: GetAuthorizationCode :one
|
||||||
|
SELECT id, code, code_challenge, code_challenge_method, user_id, client_id, scope, redirect_uri, created_at, expires_at, used_at
|
||||||
|
FROM authorization_codes
|
||||||
|
WHERE code = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetAuthorizationCode(ctx context.Context, code string) (AuthorizationCode, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getAuthorizationCode, code)
|
||||||
|
var i AuthorizationCode
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Code,
|
||||||
|
&i.CodeChallenge,
|
||||||
|
&i.CodeChallengeMethod,
|
||||||
|
&i.UserID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.Scope,
|
||||||
|
&i.RedirectUri,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.ExpiresAt,
|
||||||
|
&i.UsedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getClientRedirectURIs = `-- name: GetClientRedirectURIs :many
|
||||||
|
SELECT id, uri, client_id, created_at
|
||||||
|
FROM client_redirects
|
||||||
|
WHERE client_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetClientRedirectURIs(ctx context.Context, clientID string) ([]ClientRedirect, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getClientRedirectURIs, clientID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []ClientRedirect
|
||||||
|
for rows.Next() {
|
||||||
|
var i ClientRedirect
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Uri,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.CreatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getCustomer = `-- name: GetCustomer :one
|
const getCustomer = `-- name: GetCustomer :one
|
||||||
SELECT
|
SELECT
|
||||||
max_nkode_len
|
max_nkode_len
|
||||||
@@ -191,6 +452,42 @@ func (q *Queries) GetCustomer(ctx context.Context, id string) (GetCustomerRow, e
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getOIDCClientByID = `-- name: GetOIDCClientByID :one
|
||||||
|
SELECT id, name, owner, created_at
|
||||||
|
FROM clients
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetOIDCClientByID(ctx context.Context, id string) (Client, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getOIDCClientByID, id)
|
||||||
|
var i Client
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.Owner,
|
||||||
|
&i.CreatedAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSessionByID = `-- name: GetSessionByID :one
|
||||||
|
SELECT id, user_id, created_at, expires_at
|
||||||
|
FROM sessions
|
||||||
|
WHERE id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetSessionByID(ctx context.Context, id string) (Session, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getSessionByID, id)
|
||||||
|
var i Session
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.UserID,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.ExpiresAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const getSvgCount = `-- name: GetSvgCount :one
|
const getSvgCount = `-- name: GetSvgCount :one
|
||||||
SELECT COUNT(*) as count FROM svg_icon
|
SELECT COUNT(*) as count FROM svg_icon
|
||||||
`
|
`
|
||||||
@@ -202,19 +499,41 @@ func (q *Queries) GetSvgCount(ctx context.Context) (int64, error) {
|
|||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSvgId = `-- name: GetSvgId :one
|
const getSvgID = `-- name: GetSvgID :one
|
||||||
SELECT svg
|
SELECT svg
|
||||||
FROM svg_icon
|
FROM svg_icon
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetSvgId(ctx context.Context, id int64) (string, error) {
|
func (q *Queries) GetSvgID(ctx context.Context, id int64) (string, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getSvgId, id)
|
row := q.db.QueryRowContext(ctx, getSvgID, id)
|
||||||
var svg string
|
var svg string
|
||||||
err := row.Scan(&svg)
|
err := row.Scan(&svg)
|
||||||
return svg, err
|
return svg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTokenByValue = `-- name: GetTokenByValue :one
|
||||||
|
SELECT id, token_type, token_value, user_id, client_id, scope, created_at, expires_at
|
||||||
|
FROM tokens
|
||||||
|
WHERE token_value = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetTokenByValue(ctx context.Context, tokenValue string) (Token, error) {
|
||||||
|
row := q.db.QueryRowContext(ctx, getTokenByValue, tokenValue)
|
||||||
|
var i Token
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.TokenType,
|
||||||
|
&i.TokenValue,
|
||||||
|
&i.UserID,
|
||||||
|
&i.ClientID,
|
||||||
|
&i.Scope,
|
||||||
|
&i.CreatedAt,
|
||||||
|
&i.ExpiresAt,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
const getUser = `-- name: GetUser :one
|
const getUser = `-- name: GetUser :one
|
||||||
SELECT
|
SELECT
|
||||||
id
|
id
|
||||||
@@ -282,6 +601,42 @@ func (q *Queries) GetUser(ctx context.Context, arg GetUserParams) (GetUserRow, e
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getUserClients = `-- name: GetUserClients :many
|
||||||
|
|
||||||
|
SELECT id, name, owner, created_at
|
||||||
|
FROM clients
|
||||||
|
WHERE owner = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
// -------- go-oidc ----------
|
||||||
|
func (q *Queries) GetUserClients(ctx context.Context, owner string) ([]Client, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getUserClients, owner)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Client
|
||||||
|
for rows.Next() {
|
||||||
|
var i Client
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Name,
|
||||||
|
&i.Owner,
|
||||||
|
&i.CreatedAt,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getUserPermissions = `-- name: GetUserPermissions :many
|
const getUserPermissions = `-- name: GetUserPermissions :many
|
||||||
SELECT permission FROM user_permission WHERE user_id = ?
|
SELECT permission FROM user_permission WHERE user_id = ?
|
||||||
`
|
`
|
||||||
@@ -438,6 +793,21 @@ func (q *Queries) RenewUser(ctx context.Context, arg RenewUserParams) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const revokeClientApproval = `-- name: RevokeClientApproval :exec
|
||||||
|
DELETE FROM client_approvals
|
||||||
|
WHERE user_id = ? AND client_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
type RevokeClientApprovalParams struct {
|
||||||
|
UserID string
|
||||||
|
ClientID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) RevokeClientApproval(ctx context.Context, arg RevokeClientApprovalParams) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, revokeClientApproval, arg.UserID, arg.ClientID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const updateUser = `-- name: UpdateUser :exec
|
const updateUser = `-- name: UpdateUser :exec
|
||||||
UPDATE user
|
UPDATE user
|
||||||
SET renew = ?
|
SET renew = ?
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ SELECT
|
|||||||
FROM user
|
FROM user
|
||||||
WHERE user.email = ? AND user.customer_id = ?;
|
WHERE user.email = ? AND user.customer_id = ?;
|
||||||
|
|
||||||
-- name: GetSvgId :one
|
-- name: GetSvgID :one
|
||||||
SELECT svg
|
SELECT svg
|
||||||
FROM svg_icon
|
FROM svg_icon
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
@@ -143,3 +143,93 @@ SELECT permission FROM user_permission WHERE user_id = ?;
|
|||||||
|
|
||||||
-- name: AddUserPermission :exec
|
-- name: AddUserPermission :exec
|
||||||
INSERT INTO user_permission (user_id, permission) VALUES (?, ?);
|
INSERT INTO user_permission (user_id, permission) VALUES (?, ?);
|
||||||
|
|
||||||
|
|
||||||
|
---------- go-oidc ----------
|
||||||
|
|
||||||
|
-- name: GetUserClients :many
|
||||||
|
SELECT *
|
||||||
|
FROM clients
|
||||||
|
WHERE owner = ?;
|
||||||
|
|
||||||
|
-- name: GetOIDCClientByID :one
|
||||||
|
SELECT *
|
||||||
|
FROM clients
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
-- name: CreateOIDCClient :exec
|
||||||
|
INSERT INTO clients (id, name, owner)
|
||||||
|
VALUES (?, ?, ?);
|
||||||
|
|
||||||
|
-- name: CreateRedirectURI :exec
|
||||||
|
INSERT INTO client_redirects (uri, client_id)
|
||||||
|
VALUES (?, ?);
|
||||||
|
|
||||||
|
-- name: DeleteRedirectURI :exec
|
||||||
|
DELETE FROM client_redirects
|
||||||
|
WHERE uri = ? AND client_id = ?;
|
||||||
|
|
||||||
|
-- name: GetClientRedirectURIs :many
|
||||||
|
SELECT *
|
||||||
|
FROM client_redirects
|
||||||
|
WHERE client_id = ?;
|
||||||
|
|
||||||
|
-- name: GetAuthorizationCode :one
|
||||||
|
SELECT *
|
||||||
|
FROM authorization_codes
|
||||||
|
WHERE code = ?;
|
||||||
|
|
||||||
|
-- name: CreateAuthorizationCode :exec
|
||||||
|
INSERT INTO authorization_codes (code, code_challenge, code_challenge_method, user_id, client_id, scope, redirect_uri, expires_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||||
|
|
||||||
|
-- name: DeleteOldAuthCodes :exec
|
||||||
|
DELETE FROM authorization_codes
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
-- name: DeleteOldTokens :exec
|
||||||
|
DELETE FROM tokens
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
-- name: DeleteOldSessions :exec
|
||||||
|
DELETE FROM sessions
|
||||||
|
WHERE expires_at < CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
-- name: GetTokenByValue :one
|
||||||
|
SELECT *
|
||||||
|
FROM tokens
|
||||||
|
WHERE token_value = ?;
|
||||||
|
|
||||||
|
-- name: CreateToken :exec
|
||||||
|
INSERT INTO tokens (token_type, token_value, user_id, client_id, scope, expires_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?);
|
||||||
|
|
||||||
|
-- name: ApproveClient :exec
|
||||||
|
INSERT INTO client_approvals (user_id, client_id)
|
||||||
|
VALUES (?, ?);
|
||||||
|
|
||||||
|
-- name: ClientApproved :one
|
||||||
|
SELECT *
|
||||||
|
FROM client_approvals
|
||||||
|
WHERE user_id = ? AND client_id = ?;
|
||||||
|
|
||||||
|
-- name: DeleteAuthCode :exec
|
||||||
|
DELETE FROM authorization_codes
|
||||||
|
WHERE code = ?;
|
||||||
|
|
||||||
|
-- name: GetSessionByID :one
|
||||||
|
SELECT *
|
||||||
|
FROM sessions
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
-- name: CreateSession :exec
|
||||||
|
INSERT INTO sessions (id, user_id, expires_at)
|
||||||
|
VALUES (?, ?, ?);
|
||||||
|
|
||||||
|
-- name: DeleteSession :exec
|
||||||
|
DELETE FROM sessions
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
-- name: RevokeClientApproval :exec
|
||||||
|
DELETE FROM client_approvals
|
||||||
|
WHERE user_id = ? AND client_id = ?;
|
||||||
|
|||||||
@@ -63,4 +63,71 @@ CREATE TABLE IF NOT EXISTS user_permission (
|
|||||||
,permission TEXT NOT NULL
|
,permission TEXT NOT NULL
|
||||||
,FOREIGN KEY (user_id) REFERENCES user(id)
|
,FOREIGN KEY (user_id) REFERENCES user(id)
|
||||||
,UNIQUE(user_id, permission)
|
,UNIQUE(user_id, permission)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
---- go-oidc
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS clients (
|
||||||
|
id TEXT PRIMARY KEY
|
||||||
|
,name TEXT NOT NULL
|
||||||
|
,owner TEXT NOT NULL
|
||||||
|
,created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
,FOREIGN KEY (owner) REFERENCES user (id)
|
||||||
|
,UNIQUE(name, owner)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS client_redirects (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
,uri TEXT NOT NULL
|
||||||
|
,client_id TEXT NOT NULL
|
||||||
|
,created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
,FOREIGN KEY (client_id) REFERENCES clients (id)
|
||||||
|
,UNIQUE(uri, client_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS authorization_codes (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
,code TEXT NOT NULL UNIQUE
|
||||||
|
,code_challenge TEXT NOT NULL UNIQUE
|
||||||
|
,code_challenge_method TEXT NOT NULL CHECK (code_challenge_method IN ('S256', 'plain'))
|
||||||
|
,user_id TEXT NOT NULL
|
||||||
|
,client_id TEXT NOT NULL
|
||||||
|
,scope TEXT
|
||||||
|
,redirect_uri TEXT NOT NULL
|
||||||
|
,created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
,expires_at DATETIME NOT NULL
|
||||||
|
,used_at DATETIME
|
||||||
|
,FOREIGN KEY (user_id) REFERENCES user (id)
|
||||||
|
,FOREIGN KEY (client_id) REFERENCES client (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS tokens (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
,token_type TEXT NOT NULL CHECK (token_type IN ('access', 'refresh'))
|
||||||
|
,token_value TEXT NOT NULL UNIQUE
|
||||||
|
,user_id TEXT NOT NULL
|
||||||
|
,client_id TEXT NOT NULL
|
||||||
|
,scope TEXT
|
||||||
|
,created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
,expires_at DATETIME NOT NULL
|
||||||
|
,FOREIGN KEY (user_id) REFERENCES user (id)
|
||||||
|
,FOREIGN KEY (client_id) REFERENCES clients (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS client_approvals (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
,user_id TEXT NOT NULL
|
||||||
|
,client_id TEXT NOT NULL
|
||||||
|
,UNIQUE(user_id, client_id)
|
||||||
|
,FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
,FOREIGN KEY (client_id) REFERENCES clients (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
|
id TEXT PRIMARY KEY
|
||||||
|
,user_id TEXT NOT NULL
|
||||||
|
,created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
,expires_at DATETIME NOT NULL
|
||||||
|
,FOREIGN KEY (user_id) REFERENCES user (id)
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user