fix: update to use db.Provider
This commit is contained in:
parent
8a4b2feffe
commit
cb96d2d8d1
|
@ -1,115 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/arangodb/go-driver"
|
|
||||||
arangoDriver "github.com/arangodb/go-driver"
|
|
||||||
"github.com/arangodb/go-driver/http"
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
|
||||||
)
|
|
||||||
|
|
||||||
// for this we need arangodb instance up and running
|
|
||||||
// for local testing we can use dockerized version of it
|
|
||||||
// docker run -p 8529:8529 -e ARANGO_ROOT_PASSWORD=root arangodb/arangodb:3.8.4
|
|
||||||
|
|
||||||
func initArangodb() (arangoDriver.Database, error) {
|
|
||||||
ctx := context.Background()
|
|
||||||
conn, err := http.NewConnection(http.ConnectionConfig{
|
|
||||||
Endpoints: []string{envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL)},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
arangoClient, err := arangoDriver.NewClient(arangoDriver.ClientConfig{
|
|
||||||
Connection: conn,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var arangodb driver.Database
|
|
||||||
|
|
||||||
arangodb_exists, err := arangoClient.DatabaseExists(nil, envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName))
|
|
||||||
|
|
||||||
if arangodb_exists {
|
|
||||||
log.Println(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName) + " db exists already")
|
|
||||||
arangodb, err = arangoClient.Database(nil, envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
arangodb, err = arangoClient.CreateDatabase(nil, envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
userCollectionExists, err := arangodb.CollectionExists(ctx, Collections.User)
|
|
||||||
if userCollectionExists {
|
|
||||||
log.Println(Collections.User + " collection exists already")
|
|
||||||
} else {
|
|
||||||
_, err = arangodb.CreateCollection(ctx, Collections.User, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error creating collection("+Collections.User+"):", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userCollection, _ := arangodb.Collection(nil, Collections.User)
|
|
||||||
userCollection.EnsureHashIndex(ctx, []string{"email"}, &arangoDriver.EnsureHashIndexOptions{
|
|
||||||
Unique: true,
|
|
||||||
Sparse: true,
|
|
||||||
})
|
|
||||||
userCollection.EnsureHashIndex(ctx, []string{"phone_number"}, &arangoDriver.EnsureHashIndexOptions{
|
|
||||||
Unique: true,
|
|
||||||
Sparse: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
verificationRequestCollectionExists, err := arangodb.CollectionExists(ctx, Collections.VerificationRequest)
|
|
||||||
if verificationRequestCollectionExists {
|
|
||||||
log.Println(Collections.VerificationRequest + " collection exists already")
|
|
||||||
} else {
|
|
||||||
_, err = arangodb.CreateCollection(ctx, Collections.VerificationRequest, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error creating collection("+Collections.VerificationRequest+"):", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
verificationRequestCollection, _ := arangodb.Collection(nil, Collections.VerificationRequest)
|
|
||||||
verificationRequestCollection.EnsureHashIndex(ctx, []string{"email", "identifier"}, &arangoDriver.EnsureHashIndexOptions{
|
|
||||||
Unique: true,
|
|
||||||
Sparse: true,
|
|
||||||
})
|
|
||||||
verificationRequestCollection.EnsureHashIndex(ctx, []string{"token"}, &arangoDriver.EnsureHashIndexOptions{
|
|
||||||
Sparse: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
sessionCollectionExists, err := arangodb.CollectionExists(ctx, Collections.Session)
|
|
||||||
if sessionCollectionExists {
|
|
||||||
log.Println(Collections.Session + " collection exists already")
|
|
||||||
} else {
|
|
||||||
_, err = arangodb.CreateCollection(ctx, Collections.Session, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error creating collection("+Collections.Session+"):", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionCollection, _ := arangodb.Collection(nil, Collections.Session)
|
|
||||||
sessionCollection.EnsureHashIndex(ctx, []string{"user_id"}, &arangoDriver.EnsureHashIndexOptions{
|
|
||||||
Sparse: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
configCollectionExists, err := arangodb.CollectionExists(ctx, Collections.Env)
|
|
||||||
if configCollectionExists {
|
|
||||||
log.Println(Collections.Env + " collection exists already")
|
|
||||||
} else {
|
|
||||||
_, err = arangodb.CreateCollection(ctx, Collections.Env, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error creating collection("+Collections.Env+"):", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return arangodb, err
|
|
||||||
}
|
|
138
server/db/db.go
138
server/db/db.go
|
@ -3,158 +3,42 @@ package db
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
arangoDriver "github.com/arangodb/go-driver"
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db/providers"
|
"github.com/authorizerdev/authorizer/server/db/providers"
|
||||||
"github.com/authorizerdev/authorizer/server/db/providers/arangodb"
|
"github.com/authorizerdev/authorizer/server/db/providers/arangodb"
|
||||||
"github.com/authorizerdev/authorizer/server/db/providers/mongodb"
|
"github.com/authorizerdev/authorizer/server/db/providers/mongodb"
|
||||||
"github.com/authorizerdev/authorizer/server/db/providers/sql"
|
"github.com/authorizerdev/authorizer/server/db/providers/sql"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
"gorm.io/driver/mysql"
|
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/driver/sqlite"
|
|
||||||
"gorm.io/driver/sqlserver"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/schema"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Manager interface {
|
// Provider returns the current database provider
|
||||||
AddUser(user User) (User, error)
|
var Provider providers.Provider
|
||||||
UpdateUser(user User) (User, error)
|
|
||||||
DeleteUser(user User) error
|
|
||||||
GetUsers() ([]User, error)
|
|
||||||
GetUserByEmail(email string) (User, error)
|
|
||||||
GetUserByID(email string) (User, error)
|
|
||||||
AddVerification(verification VerificationRequest) (VerificationRequest, error)
|
|
||||||
GetVerificationByToken(token string) (VerificationRequest, error)
|
|
||||||
DeleteVerificationRequest(verificationRequest VerificationRequest) error
|
|
||||||
GetVerificationRequests() ([]VerificationRequest, error)
|
|
||||||
GetVerificationByEmail(email string, identifier string) (VerificationRequest, error)
|
|
||||||
AddSession(session Session) error
|
|
||||||
DeleteUserSession(userId string) error
|
|
||||||
AddEnv(env Env) (Env, error)
|
|
||||||
UpdateEnv(env Env) (Env, error)
|
|
||||||
GetEnv() (Env, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type manager struct {
|
|
||||||
sqlDB *gorm.DB
|
|
||||||
arangodb arangoDriver.Database
|
|
||||||
mongodb *mongo.Database
|
|
||||||
}
|
|
||||||
|
|
||||||
// mainly used by nosql dbs
|
|
||||||
type CollectionList struct {
|
|
||||||
User string
|
|
||||||
VerificationRequest string
|
|
||||||
Session string
|
|
||||||
Env string
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
IsORMSupported bool
|
|
||||||
IsArangoDB bool
|
|
||||||
IsMongoDB bool
|
|
||||||
Mgr Manager
|
|
||||||
Provider providers.Provider
|
|
||||||
Prefix = "authorizer_"
|
|
||||||
Collections = CollectionList{
|
|
||||||
User: Prefix + "users",
|
|
||||||
VerificationRequest: Prefix + "verification_requests",
|
|
||||||
Session: Prefix + "sessions",
|
|
||||||
Env: Prefix + "env",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitDB() {
|
func InitDB() {
|
||||||
var sqlDB *gorm.DB
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
IsORMSupported = envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) != constants.DbTypeArangodb && envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) != constants.DbTypeMongodb
|
isSQL := envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) != constants.DbTypeArangodb && envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) != constants.DbTypeMongodb
|
||||||
IsArangoDB = envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) == constants.DbTypeArangodb
|
isArangoDB := envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) == constants.DbTypeArangodb
|
||||||
IsMongoDB = envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) == constants.DbTypeMongodb
|
isMongoDB := envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) == constants.DbTypeMongodb
|
||||||
|
|
||||||
// sql db orm config
|
if isSQL {
|
||||||
ormConfig := &gorm.Config{
|
|
||||||
NamingStrategy: schema.NamingStrategy{
|
|
||||||
TablePrefix: Prefix,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
Provider, err = sql.NewProvider()
|
Provider, err = sql.NewProvider()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("=> error setting sql provider:", err)
|
log.Fatal("=> error setting sql provider:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if IsArangoDB {
|
if isArangoDB {
|
||||||
Provider, err = arangodb.NewProvider()
|
Provider, err = arangodb.NewProvider()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("=> error setting arangodb provider:", err)
|
log.Fatal("=> error setting arangodb provider:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if IsMongoDB {
|
if isMongoDB {
|
||||||
Provider, err = mongodb.NewProvider()
|
Provider, err = mongodb.NewProvider()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("=> error setting arangodb provider:", err)
|
log.Fatal("=> error setting arangodb provider:", err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("db type:", envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType))
|
|
||||||
|
|
||||||
switch envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseType) {
|
|
||||||
case constants.DbTypePostgres:
|
|
||||||
sqlDB, err = gorm.Open(postgres.Open(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL)), ormConfig)
|
|
||||||
break
|
|
||||||
case constants.DbTypeSqlite:
|
|
||||||
sqlDB, err = gorm.Open(sqlite.Open(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL)), ormConfig)
|
|
||||||
break
|
|
||||||
case constants.DbTypeMysql:
|
|
||||||
sqlDB, err = gorm.Open(mysql.Open(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL)), ormConfig)
|
|
||||||
break
|
|
||||||
case constants.DbTypeSqlserver:
|
|
||||||
sqlDB, err = gorm.Open(sqlserver.Open(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL)), ormConfig)
|
|
||||||
break
|
|
||||||
case constants.DbTypeArangodb:
|
|
||||||
arangodb, err := initArangodb()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("error initializing arangodb:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
Mgr = &manager{
|
|
||||||
sqlDB: nil,
|
|
||||||
arangodb: arangodb,
|
|
||||||
mongodb: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
case constants.DbTypeMongodb:
|
|
||||||
mongodb, err := initMongodb()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("error initializing mongodb connection:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
Mgr = &manager{
|
|
||||||
sqlDB: nil,
|
|
||||||
arangodb: nil,
|
|
||||||
mongodb: mongodb,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// common for all sql dbs that are configured via go-orm
|
|
||||||
if IsORMSupported {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Failed to init sqlDB:", err)
|
|
||||||
} else {
|
|
||||||
sqlDB.AutoMigrate(&User{}, &VerificationRequest{}, &Session{}, &Env{})
|
|
||||||
}
|
|
||||||
Mgr = &manager{
|
|
||||||
sqlDB: sqlDB,
|
|
||||||
arangodb: nil,
|
|
||||||
mongodb: nil,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
161
server/db/env.go
161
server/db/env.go
|
@ -1,161 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
arangoDriver "github.com/arangodb/go-driver"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Env struct {
|
|
||||||
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
|
|
||||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
|
|
||||||
EnvData []byte `gorm:"type:text" json:"env" bson:"env"`
|
|
||||||
Hash string `gorm:"type:hash" json:"hash" bson:"hash"`
|
|
||||||
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
|
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddEnv function to add env to db
|
|
||||||
func (mgr *manager) AddEnv(env Env) (Env, error) {
|
|
||||||
if env.ID == "" {
|
|
||||||
env.ID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
// copy id as value for fields required for mongodb & arangodb
|
|
||||||
env.Key = env.ID
|
|
||||||
result := mgr.sqlDB.Create(&env)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error adding config:", result.Error)
|
|
||||||
return env, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
env.CreatedAt = time.Now().Unix()
|
|
||||||
env.UpdatedAt = time.Now().Unix()
|
|
||||||
configCollection, _ := mgr.arangodb.Collection(nil, Collections.Env)
|
|
||||||
meta, err := configCollection.CreateDocument(arangoDriver.WithOverwrite(nil), env)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error adding config:", err)
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
env.Key = meta.Key
|
|
||||||
env.ID = meta.ID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
env.CreatedAt = time.Now().Unix()
|
|
||||||
env.UpdatedAt = time.Now().Unix()
|
|
||||||
env.Key = env.ID
|
|
||||||
configCollection := mgr.mongodb.Collection(Collections.Env, options.Collection())
|
|
||||||
_, err := configCollection.InsertOne(nil, env)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error adding config:", err)
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return env, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateEnv function to update env in db
|
|
||||||
func (mgr *manager) UpdateEnv(env Env) (Env, error) {
|
|
||||||
env.UpdatedAt = time.Now().Unix()
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Save(&env)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error updating config:", result.Error)
|
|
||||||
return env, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
collection, _ := mgr.arangodb.Collection(nil, Collections.Env)
|
|
||||||
meta, err := collection.UpdateDocument(nil, env.Key, env)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error updating config:", err)
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
|
|
||||||
env.Key = meta.Key
|
|
||||||
env.ID = meta.ID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
configCollection := mgr.mongodb.Collection(Collections.Env, options.Collection())
|
|
||||||
_, err := configCollection.UpdateOne(nil, bson.M{"_id": bson.M{"$eq": env.ID}}, bson.M{"$set": env}, options.MergeUpdateOptions())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error updating config:", err)
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return env, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetConfig function to get config
|
|
||||||
func (mgr *manager) GetEnv() (Env, error) {
|
|
||||||
var env Env
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.First(&env)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
return env, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s RETURN d", Collections.Env)
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, nil)
|
|
||||||
if err != nil {
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !cursor.HasMore() {
|
|
||||||
if env.Key == "" {
|
|
||||||
return env, fmt.Errorf("config not found")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_, err := cursor.ReadDocument(nil, &env)
|
|
||||||
if err != nil {
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
configCollection := mgr.mongodb.Collection(Collections.Env, options.Collection())
|
|
||||||
cursor, err := configCollection.Find(nil, bson.M{}, options.Find())
|
|
||||||
if err != nil {
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
defer cursor.Close(nil)
|
|
||||||
|
|
||||||
for cursor.Next(nil) {
|
|
||||||
err := cursor.Decode(&env)
|
|
||||||
if err != nil {
|
|
||||||
return env, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if env.ID == "" {
|
|
||||||
return env, fmt.Errorf("config not found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return env, nil
|
|
||||||
}
|
|
|
@ -1,80 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
|
||||||
)
|
|
||||||
|
|
||||||
func initMongodb() (*mongo.Database, error) {
|
|
||||||
mongodbOptions := options.Client().ApplyURI(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseURL))
|
|
||||||
maxWait := time.Duration(5 * time.Second)
|
|
||||||
mongodbOptions.ConnectTimeout = &maxWait
|
|
||||||
mongoClient, err := mongo.NewClient(mongodbOptions)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
|
|
||||||
err = mongoClient.Connect(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = mongoClient.Ping(ctx, readpref.Primary())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
mongodb := mongoClient.Database(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyDatabaseName), options.Database())
|
|
||||||
|
|
||||||
mongodb.CreateCollection(ctx, Collections.User, options.CreateCollection())
|
|
||||||
userCollection := mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
userCollection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
|
||||||
mongo.IndexModel{
|
|
||||||
Keys: bson.M{"email": 1},
|
|
||||||
Options: options.Index().SetUnique(true).SetSparse(true),
|
|
||||||
},
|
|
||||||
}, options.CreateIndexes())
|
|
||||||
userCollection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
|
||||||
mongo.IndexModel{
|
|
||||||
Keys: bson.M{"phone_number": 1},
|
|
||||||
Options: options.Index().SetUnique(true).SetSparse(true).SetPartialFilterExpression(map[string]interface{}{
|
|
||||||
"phone_number": map[string]string{"$type": "string"},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
}, options.CreateIndexes())
|
|
||||||
|
|
||||||
mongodb.CreateCollection(ctx, Collections.VerificationRequest, options.CreateCollection())
|
|
||||||
verificationRequestCollection := mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
verificationRequestCollection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
|
||||||
mongo.IndexModel{
|
|
||||||
Keys: bson.M{"email": 1, "identifier": 1},
|
|
||||||
Options: options.Index().SetUnique(true).SetSparse(true),
|
|
||||||
},
|
|
||||||
}, options.CreateIndexes())
|
|
||||||
verificationRequestCollection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
|
||||||
mongo.IndexModel{
|
|
||||||
Keys: bson.M{"token": 1},
|
|
||||||
Options: options.Index().SetSparse(true),
|
|
||||||
},
|
|
||||||
}, options.CreateIndexes())
|
|
||||||
|
|
||||||
mongodb.CreateCollection(ctx, Collections.Session, options.CreateCollection())
|
|
||||||
sessionCollection := mongodb.Collection(Collections.Session, options.Collection())
|
|
||||||
sessionCollection.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
|
||||||
mongo.IndexModel{
|
|
||||||
Keys: bson.M{"user_id": 1},
|
|
||||||
Options: options.Index().SetSparse(true),
|
|
||||||
},
|
|
||||||
}, options.CreateIndexes())
|
|
||||||
|
|
||||||
mongodb.CreateCollection(ctx, Collections.Env, options.CreateCollection())
|
|
||||||
|
|
||||||
return mongodb, nil
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Session struct {
|
|
||||||
Key string `json:"_key,omitempty" bson:"_key,omitempty"` // for arangodb
|
|
||||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
|
|
||||||
UserID string `gorm:"type:char(36),index:" json:"user_id" bson:"user_id"`
|
|
||||||
User User `json:"-" bson:"-"`
|
|
||||||
UserAgent string `json:"user_agent" bson:"user_agent"`
|
|
||||||
IP string `json:"ip" bson:"ip"`
|
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
|
|
||||||
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddSession function to save user sessiosn
|
|
||||||
func (mgr *manager) AddSession(session Session) error {
|
|
||||||
if session.ID == "" {
|
|
||||||
session.ID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
session.Key = session.ID
|
|
||||||
res := mgr.sqlDB.Clauses(
|
|
||||||
clause.OnConflict{
|
|
||||||
DoNothing: true,
|
|
||||||
}).Create(&session)
|
|
||||||
if res.Error != nil {
|
|
||||||
log.Println(`error saving session`, res.Error)
|
|
||||||
return res.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
|
||||||
session.UpdatedAt = time.Now().Unix()
|
|
||||||
sessionCollection, _ := mgr.arangodb.Collection(nil, Collections.Session)
|
|
||||||
_, err := sessionCollection.CreateDocument(nil, session)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(`error saving session`, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
session.Key = session.ID
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
|
||||||
session.UpdatedAt = time.Now().Unix()
|
|
||||||
sessionCollection := mgr.mongodb.Collection(Collections.Session, options.Collection())
|
|
||||||
_, err := sessionCollection.InsertOne(nil, session)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(`error saving session`, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mgr *manager) DeleteUserSession(userId string) error {
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Where("user_id = ?", userId).Delete(&Session{})
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error deleting session:`, result.Error)
|
|
||||||
return result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @userId REMOVE { _key: d._key } IN %s`, Collections.Session, Collections.Session)
|
|
||||||
bindVars := map[string]interface{}{
|
|
||||||
"userId": userId,
|
|
||||||
}
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, bindVars)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("=> error deleting arangodb session:", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
sessionCollection := mgr.mongodb.Collection(Collections.Session, options.Collection())
|
|
||||||
_, err := sessionCollection.DeleteMany(nil, bson.M{"user_id": userId}, options.Delete())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error deleting session:", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,318 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/arangodb/go-driver"
|
|
||||||
arangoDriver "github.com/arangodb/go-driver"
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
|
|
||||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
|
|
||||||
|
|
||||||
Email string `gorm:"unique" json:"email" bson:"email"`
|
|
||||||
EmailVerifiedAt *int64 `json:"email_verified_at" bson:"email_verified_at"`
|
|
||||||
Password *string `gorm:"type:text" json:"password" bson:"password"`
|
|
||||||
SignupMethods string `json:"signup_methods" bson:"signup_methods"`
|
|
||||||
GivenName *string `json:"given_name" bson:"given_name"`
|
|
||||||
FamilyName *string `json:"family_name" bson:"family_name"`
|
|
||||||
MiddleName *string `json:"middle_name" bson:"middle_name"`
|
|
||||||
Nickname *string `json:"nickname" bson:"nickname"`
|
|
||||||
Gender *string `json:"gender" bson:"gender"`
|
|
||||||
Birthdate *string `json:"birthdate" bson:"birthdate"`
|
|
||||||
PhoneNumber *string `gorm:"unique" json:"phone_number" bson:"phone_number"`
|
|
||||||
PhoneNumberVerifiedAt *int64 `json:"phone_number_verified_at" bson:"phone_number_verified_at"`
|
|
||||||
Picture *string `gorm:"type:text" json:"picture" bson:"picture"`
|
|
||||||
Roles string `json:"roles" bson:"roles"`
|
|
||||||
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
|
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUser function to add user even with email conflict
|
|
||||||
func (mgr *manager) AddUser(user User) (User, error) {
|
|
||||||
if user.ID == "" {
|
|
||||||
user.ID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Roles == "" {
|
|
||||||
user.Roles = strings.Join(envstore.EnvInMemoryStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles), ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
// copy id as value for fields required for mongodb & arangodb
|
|
||||||
user.Key = user.ID
|
|
||||||
result := mgr.sqlDB.Clauses(
|
|
||||||
clause.OnConflict{
|
|
||||||
UpdateAll: true,
|
|
||||||
Columns: []clause.Column{{Name: "email"}},
|
|
||||||
}).Create(&user)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error adding user:", result.Error)
|
|
||||||
return user, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
user.CreatedAt = time.Now().Unix()
|
|
||||||
user.UpdatedAt = time.Now().Unix()
|
|
||||||
userCollection, _ := mgr.arangodb.Collection(nil, Collections.User)
|
|
||||||
meta, err := userCollection.CreateDocument(arangoDriver.WithOverwrite(nil), user)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error adding user:", err)
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
user.Key = meta.Key
|
|
||||||
user.ID = meta.ID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
user.CreatedAt = time.Now().Unix()
|
|
||||||
user.UpdatedAt = time.Now().Unix()
|
|
||||||
user.Key = user.ID
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
_, err := userCollection.InsertOne(nil, user)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error adding user:", err)
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateUser function to update user with ID conflict
|
|
||||||
func (mgr *manager) UpdateUser(user User) (User, error) {
|
|
||||||
user.UpdatedAt = time.Now().Unix()
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Save(&user)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error updating user:", result.Error)
|
|
||||||
return user, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
collection, _ := mgr.arangodb.Collection(nil, Collections.User)
|
|
||||||
meta, err := collection.UpdateDocument(nil, user.Key, user)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error updating user:", err)
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
|
|
||||||
user.Key = meta.Key
|
|
||||||
user.ID = meta.ID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
_, err := userCollection.UpdateOne(nil, bson.M{"_id": bson.M{"$eq": user.ID}}, bson.M{"$set": user}, options.MergeUpdateOptions())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error updating user:", err)
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUsers function to get all users
|
|
||||||
func (mgr *manager) GetUsers() ([]User, error) {
|
|
||||||
var users []User
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Find(&users)
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error getting users:", result.Error)
|
|
||||||
return users, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s RETURN d", Collections.User)
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, nil)
|
|
||||||
if err != nil {
|
|
||||||
return users, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
var user User
|
|
||||||
meta, err := cursor.ReadDocument(nil, &user)
|
|
||||||
|
|
||||||
if driver.IsNoMoreDocuments(err) {
|
|
||||||
break
|
|
||||||
} else if err != nil {
|
|
||||||
return users, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if meta.Key != "" {
|
|
||||||
users = append(users, user)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
cursor, err := userCollection.Find(nil, bson.M{}, options.Find())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error getting users:", err)
|
|
||||||
return users, err
|
|
||||||
}
|
|
||||||
defer cursor.Close(nil)
|
|
||||||
|
|
||||||
for cursor.Next(nil) {
|
|
||||||
var user User
|
|
||||||
err := cursor.Decode(&user)
|
|
||||||
if err != nil {
|
|
||||||
return users, err
|
|
||||||
}
|
|
||||||
users = append(users, user)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return users, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUserByEmail function to get user by email
|
|
||||||
func (mgr *manager) GetUserByEmail(email string) (User, error) {
|
|
||||||
var user User
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Where("email = ?", email).First(&user)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
return user, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", Collections.User)
|
|
||||||
bindVars := map[string]interface{}{
|
|
||||||
"email": email,
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, bindVars)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !cursor.HasMore() {
|
|
||||||
if user.Key == "" {
|
|
||||||
return user, fmt.Errorf("user not found")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_, err := cursor.ReadDocument(nil, &user)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
err := userCollection.FindOne(nil, bson.M{"email": email}).Decode(&user)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUserByID function to get user by ID
|
|
||||||
func (mgr *manager) GetUserByID(id string) (User, error) {
|
|
||||||
var user User
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Where("id = ?", id).First(&user)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
return user, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d._id == @id LIMIT 1 RETURN d", Collections.User)
|
|
||||||
bindVars := map[string]interface{}{
|
|
||||||
"id": id,
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, bindVars)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !cursor.HasMore() {
|
|
||||||
if user.Key == "" {
|
|
||||||
return user, fmt.Errorf("user not found")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_, err := cursor.ReadDocument(nil, &user)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
err := userCollection.FindOne(nil, bson.M{"_id": id}).Decode(&user)
|
|
||||||
if err != nil {
|
|
||||||
return user, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteUser function to delete user
|
|
||||||
func (mgr *manager) DeleteUser(user User) error {
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Delete(&user)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error deleting user:`, result.Error)
|
|
||||||
return result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
collection, _ := mgr.arangodb.Collection(nil, Collections.User)
|
|
||||||
_, err := collection.RemoveDocument(nil, user.Key)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(`error deleting user:`, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
|
|
||||||
_, err := userCollection.DeleteOne(nil, bson.M{"_id": user.ID}, options.Delete())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error deleting user:", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,260 +0,0 @@
|
||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/arangodb/go-driver"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
)
|
|
||||||
|
|
||||||
type VerificationRequest struct {
|
|
||||||
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
|
|
||||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
|
|
||||||
Token string `gorm:"type:text" json:"token" bson:"token"`
|
|
||||||
Identifier string `gorm:"uniqueIndex:idx_email_identifier" json:"identifier" bson:"identifier"`
|
|
||||||
ExpiresAt int64 `json:"expires_at" bson:"expires_at"`
|
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
|
|
||||||
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
|
|
||||||
Email string `gorm:"uniqueIndex:idx_email_identifier" json:"email" bson:"email"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddVerification function to add verification record
|
|
||||||
func (mgr *manager) AddVerification(verification VerificationRequest) (VerificationRequest, error) {
|
|
||||||
if verification.ID == "" {
|
|
||||||
verification.ID = uuid.New().String()
|
|
||||||
}
|
|
||||||
if IsORMSupported {
|
|
||||||
// copy id as value for fields required for mongodb & arangodb
|
|
||||||
verification.Key = verification.ID
|
|
||||||
result := mgr.sqlDB.Clauses(clause.OnConflict{
|
|
||||||
Columns: []clause.Column{{Name: "email"}, {Name: "identifier"}},
|
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"token", "expires_at"}),
|
|
||||||
}).Create(&verification)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error saving verification record`, result.Error)
|
|
||||||
return verification, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
verification.CreatedAt = time.Now().Unix()
|
|
||||||
verification.UpdatedAt = time.Now().Unix()
|
|
||||||
verificationRequestCollection, _ := mgr.arangodb.Collection(nil, Collections.VerificationRequest)
|
|
||||||
meta, err := verificationRequestCollection.CreateDocument(nil, verification)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error saving verification record:", err)
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
verification.Key = meta.Key
|
|
||||||
verification.ID = meta.ID.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
verification.CreatedAt = time.Now().Unix()
|
|
||||||
verification.UpdatedAt = time.Now().Unix()
|
|
||||||
verification.Key = verification.ID
|
|
||||||
verificationRequestCollection := mgr.mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
_, err := verificationRequestCollection.InsertOne(nil, verification)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error saving verification record:", err)
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return verification, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVerificationRequests function to get all verification requests
|
|
||||||
func (mgr *manager) GetVerificationRequests() ([]VerificationRequest, error) {
|
|
||||||
var verificationRequests []VerificationRequest
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Find(&verificationRequests)
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println("error getting verification requests:", result.Error)
|
|
||||||
return verificationRequests, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s RETURN d", Collections.VerificationRequest)
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, nil)
|
|
||||||
if err != nil {
|
|
||||||
return verificationRequests, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
var verificationRequest VerificationRequest
|
|
||||||
meta, err := cursor.ReadDocument(nil, &verificationRequest)
|
|
||||||
|
|
||||||
if driver.IsNoMoreDocuments(err) {
|
|
||||||
break
|
|
||||||
} else if err != nil {
|
|
||||||
return verificationRequests, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if meta.Key != "" {
|
|
||||||
verificationRequests = append(verificationRequests, verificationRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
verificationRequestCollection := mgr.mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
cursor, err := verificationRequestCollection.Find(nil, bson.M{}, options.Find())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error getting verification requests:", err)
|
|
||||||
return verificationRequests, err
|
|
||||||
}
|
|
||||||
defer cursor.Close(nil)
|
|
||||||
|
|
||||||
for cursor.Next(nil) {
|
|
||||||
var verificationRequest VerificationRequest
|
|
||||||
err := cursor.Decode(&verificationRequest)
|
|
||||||
if err != nil {
|
|
||||||
return verificationRequests, err
|
|
||||||
}
|
|
||||||
verificationRequests = append(verificationRequests, verificationRequest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return verificationRequests, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mgr *manager) GetVerificationByToken(token string) (VerificationRequest, error) {
|
|
||||||
var verification VerificationRequest
|
|
||||||
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Where("token = ?", token).First(&verification)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error getting verification request:`, result.Error)
|
|
||||||
return verification, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.token == @token LIMIT 1 RETURN d", Collections.VerificationRequest)
|
|
||||||
bindVars := map[string]interface{}{
|
|
||||||
"token": token,
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, bindVars)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !cursor.HasMore() {
|
|
||||||
if verification.Key == "" {
|
|
||||||
return verification, fmt.Errorf("verification request not found")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_, err := cursor.ReadDocument(nil, &verification)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
verificationRequestCollection := mgr.mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
err := verificationRequestCollection.FindOne(nil, bson.M{"token": token}).Decode(&verification)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return verification, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mgr *manager) GetVerificationByEmail(email string, identifier string) (VerificationRequest, error) {
|
|
||||||
var verification VerificationRequest
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Where("email = ? AND identifier = ?", email, identifier).First(&verification)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error getting verification token:`, result.Error)
|
|
||||||
return verification, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email FILTER d.identifier == @identifier LIMIT 1 RETURN d", Collections.VerificationRequest)
|
|
||||||
bindVars := map[string]interface{}{
|
|
||||||
"email": email,
|
|
||||||
"identifier": identifier,
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor, err := mgr.arangodb.Query(nil, query, bindVars)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
defer cursor.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !cursor.HasMore() {
|
|
||||||
if verification.Key == "" {
|
|
||||||
return verification, fmt.Errorf("verification request not found")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_, err := cursor.ReadDocument(nil, &verification)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
verificationRequestCollection := mgr.mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
err := verificationRequestCollection.FindOne(nil, bson.M{"email": email, "identifier": identifier}).Decode(&verification)
|
|
||||||
if err != nil {
|
|
||||||
return verification, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return verification, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mgr *manager) DeleteVerificationRequest(verificationRequest VerificationRequest) error {
|
|
||||||
if IsORMSupported {
|
|
||||||
result := mgr.sqlDB.Delete(&verificationRequest)
|
|
||||||
|
|
||||||
if result.Error != nil {
|
|
||||||
log.Println(`error deleting verification request:`, result.Error)
|
|
||||||
return result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsArangoDB {
|
|
||||||
collection, _ := mgr.arangodb.Collection(nil, Collections.VerificationRequest)
|
|
||||||
_, err := collection.RemoveDocument(nil, verificationRequest.Key)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(`error deleting verification request:`, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsMongoDB {
|
|
||||||
verificationRequestCollection := mgr.mongodb.Collection(Collections.VerificationRequest, options.Collection())
|
|
||||||
_, err := verificationRequestCollection.DeleteOne(nil, bson.M{"_id": verificationRequest.ID}, options.Delete())
|
|
||||||
if err != nil {
|
|
||||||
log.Println("error deleting verification request::", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
9
server/env/persist_env.go
vendored
9
server/env/persist_env.go
vendored
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
|
|
||||||
// PersistEnv persists the environment variables to the database
|
// PersistEnv persists the environment variables to the database
|
||||||
func PersistEnv() error {
|
func PersistEnv() error {
|
||||||
env, err := db.Mgr.GetEnv()
|
env, err := db.Provider.GetEnv()
|
||||||
// config not found in db
|
// config not found in db
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
||||||
|
@ -34,12 +35,12 @@ func PersistEnv() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
env = db.Env{
|
env = models.Env{
|
||||||
Hash: encodedHash,
|
Hash: encodedHash,
|
||||||
EnvData: encryptedConfig,
|
EnvData: encryptedConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Mgr.AddEnv(env)
|
db.Provider.AddEnv(env)
|
||||||
} else {
|
} else {
|
||||||
// decrypt the config data from db
|
// decrypt the config data from db
|
||||||
// decryption can be done using the hash stored in db
|
// decryption can be done using the hash stored in db
|
||||||
|
@ -131,7 +132,7 @@ func PersistEnv() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
env.EnvData = encryptedConfig
|
env.EnvData = encryptedConfig
|
||||||
_, err = db.Mgr.UpdateEnv(env)
|
_, err = db.Provider.UpdateEnv(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error updating config:", err)
|
log.Println("error updating config:", err)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/oauth"
|
"github.com/authorizerdev/authorizer/server/oauth"
|
||||||
"github.com/authorizerdev/authorizer/server/session"
|
"github.com/authorizerdev/authorizer/server/session"
|
||||||
|
@ -45,7 +46,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
redirectURL := sessionSplit[1]
|
redirectURL := sessionSplit[1]
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
user := db.User{}
|
user := models.User{}
|
||||||
code := c.Request.FormValue("code")
|
code := c.Request.FormValue("code")
|
||||||
switch provider {
|
switch provider {
|
||||||
case constants.SignupMethodGoogle:
|
case constants.SignupMethodGoogle:
|
||||||
|
@ -63,7 +64,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
existingUser, err := db.Mgr.GetUserByEmail(user.Email)
|
existingUser, err := db.Provider.GetUserByEmail(user.Email)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// user not registered, register user and generate session token
|
// user not registered, register user and generate session token
|
||||||
|
@ -84,7 +85,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
user.Roles = strings.Join(inputRoles, ",")
|
user.Roles = strings.Join(inputRoles, ",")
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
user.EmailVerifiedAt = &now
|
user.EmailVerifiedAt = &now
|
||||||
user, _ = db.Mgr.AddUser(user)
|
user, _ = db.Provider.AddUser(user)
|
||||||
} else {
|
} else {
|
||||||
// user exists in db, check if method was google
|
// user exists in db, check if method was google
|
||||||
// if not append google to existing signup method and save it
|
// if not append google to existing signup method and save it
|
||||||
|
@ -130,10 +131,10 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
user.Key = existingUser.Key
|
user.Key = existingUser.Key
|
||||||
user.ID = existingUser.ID
|
user.ID = existingUser.ID
|
||||||
user, err = db.Mgr.UpdateUser(user)
|
user, err = db.Provider.UpdateUser(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
user, _ = db.Mgr.GetUserByEmail(user.Email)
|
user, _ = db.Provider.GetUserByEmail(user.Email)
|
||||||
userIdStr := fmt.Sprintf("%v", user.ID)
|
userIdStr := fmt.Sprintf("%v", user.ID)
|
||||||
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, inputRoles)
|
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, inputRoles)
|
||||||
|
|
||||||
|
@ -146,8 +147,8 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGoogleUserInfo(code string) (db.User, error) {
|
func processGoogleUserInfo(code string) (models.User, error) {
|
||||||
user := db.User{}
|
user := models.User{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
oauth2Token, err := oauth.OAuthProviders.GoogleConfig.Exchange(ctx, code)
|
oauth2Token, err := oauth.OAuthProviders.GoogleConfig.Exchange(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -175,8 +176,8 @@ func processGoogleUserInfo(code string) (db.User, error) {
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGithubUserInfo(code string) (db.User, error) {
|
func processGithubUserInfo(code string) (models.User, error) {
|
||||||
user := db.User{}
|
user := models.User{}
|
||||||
token, err := oauth.OAuthProviders.GithubConfig.Exchange(oauth2.NoContext, code)
|
token, err := oauth.OAuthProviders.GithubConfig.Exchange(oauth2.NoContext, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, fmt.Errorf("invalid github exchange code: %s", err.Error())
|
return user, fmt.Errorf("invalid github exchange code: %s", err.Error())
|
||||||
|
@ -216,7 +217,7 @@ func processGithubUserInfo(code string) (db.User, error) {
|
||||||
|
|
||||||
picture := userRawData["avatar_url"]
|
picture := userRawData["avatar_url"]
|
||||||
|
|
||||||
user = db.User{
|
user = models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &picture,
|
Picture: &picture,
|
||||||
|
@ -226,8 +227,8 @@ func processGithubUserInfo(code string) (db.User, error) {
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processFacebookUserInfo(code string) (db.User, error) {
|
func processFacebookUserInfo(code string) (models.User, error) {
|
||||||
user := db.User{}
|
user := models.User{}
|
||||||
token, err := oauth.OAuthProviders.FacebookConfig.Exchange(oauth2.NoContext, code)
|
token, err := oauth.OAuthProviders.FacebookConfig.Exchange(oauth2.NoContext, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, fmt.Errorf("invalid facebook exchange code: %s", err.Error())
|
return user, fmt.Errorf("invalid facebook exchange code: %s", err.Error())
|
||||||
|
@ -261,7 +262,7 @@ func processFacebookUserInfo(code string) (db.User, error) {
|
||||||
lastName := fmt.Sprintf("%v", userRawData["last_name"])
|
lastName := fmt.Sprintf("%v", userRawData["last_name"])
|
||||||
picture := fmt.Sprintf("%v", picDataObject["url"])
|
picture := fmt.Sprintf("%v", picDataObject["url"])
|
||||||
|
|
||||||
user = db.User{
|
user = models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &picture,
|
Picture: &picture,
|
||||||
|
|
|
@ -25,7 +25,7 @@ func VerifyEmailHandler() gin.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByToken(token)
|
verificationRequest, err := db.Provider.GetVerificationRequestByToken(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, errorRes)
|
c.JSON(400, errorRes)
|
||||||
return
|
return
|
||||||
|
@ -38,7 +38,7 @@ func VerifyEmailHandler() gin.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(claim.Email)
|
user, err := db.Provider.GetUserByEmail(claim.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, gin.H{
|
c.JSON(400, gin.H{
|
||||||
"message": err.Error(),
|
"message": err.Error(),
|
||||||
|
@ -50,10 +50,10 @@ func VerifyEmailHandler() gin.HandlerFunc {
|
||||||
if user.EmailVerifiedAt == nil {
|
if user.EmailVerifiedAt == nil {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
user.EmailVerifiedAt = &now
|
user.EmailVerifiedAt = &now
|
||||||
db.Mgr.UpdateUser(user)
|
db.Provider.UpdateUser(user)
|
||||||
}
|
}
|
||||||
// delete from verification table
|
// delete from verification table
|
||||||
db.Mgr.DeleteVerificationRequest(verificationRequest)
|
db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
|
|
||||||
roles := strings.Split(user.Roles, ",")
|
roles := strings.Split(user.Roles, ",")
|
||||||
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, roles)
|
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, roles)
|
||||||
|
|
|
@ -52,7 +52,7 @@ func AdminSignupResolver(ctx context.Context, params model.AdminSignupInput) (*m
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
env, err := db.Mgr.GetEnv()
|
env, err := db.Provider.GetEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func AdminSignupResolver(ctx context.Context, params model.AdminSignupInput) (*m
|
||||||
}
|
}
|
||||||
|
|
||||||
env.EnvData = envData
|
env.EnvData = envData
|
||||||
if _, err := db.Mgr.UpdateEnv(env); err != nil {
|
if _, err := db.Provider.UpdateEnv(env); err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ func DeleteUserResolver(ctx context.Context, params model.DeleteUserInput) (*mod
|
||||||
return res, fmt.Errorf("unauthorized")
|
return res, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(params.Email)
|
user, err := db.Provider.GetUserByEmail(params.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
session.DeleteAllUserSession(fmt.Sprintf("%x", user.ID))
|
session.DeleteAllUserSession(fmt.Sprintf("%x", user.ID))
|
||||||
|
|
||||||
err = db.Mgr.DeleteUser(user)
|
err = db.Provider.DeleteUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error deleting user:", err)
|
log.Println("error deleting user:", err)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -32,7 +33,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
|
||||||
return res, fmt.Errorf("invalid email")
|
return res, fmt.Errorf("invalid email")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Mgr.GetUserByEmail(params.Email)
|
_, err = db.Provider.GetUserByEmail(params.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`user with this email not found`)
|
return res, fmt.Errorf(`user with this email not found`)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +42,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: constants.VerificationTypeForgotPassword,
|
Identifier: constants.VerificationTypeForgotPassword,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
|
|
@ -28,7 +28,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
||||||
}
|
}
|
||||||
|
|
||||||
params.Email = strings.ToLower(params.Email)
|
params.Email = strings.ToLower(params.Email)
|
||||||
user, err := db.Mgr.GetUserByEmail(params.Email)
|
user, err := db.Provider.GetUserByEmail(params.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`user with this email not found`)
|
return res, fmt.Errorf(`user with this email not found`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -31,12 +32,12 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||||
|
|
||||||
inputRoles := []string{}
|
inputRoles := []string{}
|
||||||
|
|
||||||
user := db.User{
|
user := models.User{
|
||||||
Email: params.Email,
|
Email: params.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
// find user with email
|
// find user with email
|
||||||
existingUser, err := db.Mgr.GetUserByEmail(params.Email)
|
existingUser, err := db.Provider.GetUserByEmail(params.Email)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.SignupMethods = constants.SignupMethodMagicLinkLogin
|
user.SignupMethods = constants.SignupMethodMagicLinkLogin
|
||||||
|
@ -53,7 +54,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Roles = strings.Join(inputRoles, ",")
|
user.Roles = strings.Join(inputRoles, ",")
|
||||||
user, _ = db.Mgr.AddUser(user)
|
user, _ = db.Provider.AddUser(user)
|
||||||
} else {
|
} else {
|
||||||
user = existingUser
|
user = existingUser
|
||||||
// There multiple scenarios with roles here in magic link login
|
// There multiple scenarios with roles here in magic link login
|
||||||
|
@ -94,7 +95,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||||
}
|
}
|
||||||
|
|
||||||
user.SignupMethods = signupMethod
|
user.SignupMethods = signupMethod
|
||||||
user, _ = db.Mgr.UpdateUser(user)
|
user, _ = db.Provider.UpdateUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error updating user:", err)
|
log.Println("error updating user:", err)
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
|
|
@ -36,7 +36,7 @@ func ProfileResolver(ctx context.Context) (*model.User, error) {
|
||||||
return res, fmt.Errorf(`unauthorized`)
|
return res, fmt.Errorf(`unauthorized`)
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(email)
|
user, err := db.Provider.GetUserByEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
|
@ -26,13 +27,13 @@ func ResendVerifyEmailResolver(ctx context.Context, params model.ResendVerifyEma
|
||||||
return res, fmt.Errorf("invalid identifier")
|
return res, fmt.Errorf("invalid identifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(params.Email, params.Identifier)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(params.Email, params.Identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`verification request not found`)
|
return res, fmt.Errorf(`verification request not found`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete current verification and create new one
|
// delete current verification and create new one
|
||||||
err = db.Mgr.DeleteVerificationRequest(verificationRequest)
|
err = db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error deleting verification request:", err)
|
log.Println("error deleting verification request:", err)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +42,7 @@ func ResendVerifyEmailResolver(ctx context.Context, params model.ResendVerifyEma
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: params.Identifier,
|
Identifier: params.Identifier,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
|
|
@ -20,7 +20,7 @@ func ResetPasswordResolver(ctx context.Context, params model.ResetPasswordInput)
|
||||||
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByToken(params.Token)
|
verificationRequest, err := db.Provider.GetVerificationRequestByToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`invalid token`)
|
return res, fmt.Errorf(`invalid token`)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func ResetPasswordResolver(ctx context.Context, params model.ResetPasswordInput)
|
||||||
return res, fmt.Errorf(`invalid token`)
|
return res, fmt.Errorf(`invalid token`)
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(claim.Email)
|
user, err := db.Provider.GetUserByEmail(claim.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ func ResetPasswordResolver(ctx context.Context, params model.ResetPasswordInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete from verification table
|
// delete from verification table
|
||||||
db.Mgr.DeleteVerificationRequest(verificationRequest)
|
db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
db.Mgr.UpdateUser(user)
|
db.Provider.UpdateUser(user)
|
||||||
|
|
||||||
res = &model.Response{
|
res = &model.Response{
|
||||||
Message: `Password updated successfully.`,
|
Message: `Password updated successfully.`,
|
||||||
|
|
|
@ -30,7 +30,7 @@ func SessionResolver(ctx context.Context, roles []string) (*model.AuthResponse,
|
||||||
expiresAt := claim["exp"].(int64)
|
expiresAt := claim["exp"].(int64)
|
||||||
email := fmt.Sprintf("%v", claim["email"])
|
email := fmt.Sprintf("%v", claim["email"])
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(email)
|
user, err := db.Provider.GetUserByEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -38,7 +39,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||||
}
|
}
|
||||||
|
|
||||||
// find user with email
|
// find user with email
|
||||||
existingUser, err := db.Mgr.GetUserByEmail(params.Email)
|
existingUser, err := db.Provider.GetUserByEmail(params.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("user with email " + params.Email + " not found")
|
log.Println("user with email " + params.Email + " not found")
|
||||||
}
|
}
|
||||||
|
@ -63,7 +64,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||||
inputRoles = envstore.EnvInMemoryStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
inputRoles = envstore.EnvInMemoryStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||||
}
|
}
|
||||||
|
|
||||||
user := db.User{
|
user := models.User{
|
||||||
Email: params.Email,
|
Email: params.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
user.EmailVerifiedAt = &now
|
user.EmailVerifiedAt = &now
|
||||||
}
|
}
|
||||||
user, err = db.Mgr.AddUser(user)
|
user, err = db.Provider.AddUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -124,7 +125,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
|
|
@ -78,7 +78,7 @@ func UpdateEnvResolver(ctx context.Context, params model.UpdateEnvInput) (*model
|
||||||
envstore.EnvInMemoryStoreObj.UpdateEnvStore(updatedData)
|
envstore.EnvInMemoryStoreObj.UpdateEnvStore(updatedData)
|
||||||
|
|
||||||
// Fetch the current db store and update it
|
// Fetch the current db store and update it
|
||||||
env, err := db.Mgr.GetEnv()
|
env, err := db.Provider.GetEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func UpdateEnvResolver(ctx context.Context, params model.UpdateEnvInput) (*model
|
||||||
}
|
}
|
||||||
|
|
||||||
env.EnvData = encryptedConfig
|
env.EnvData = encryptedConfig
|
||||||
_, err = db.Mgr.UpdateEnv(env)
|
_, err = db.Provider.UpdateEnv(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error updating config:", err)
|
log.Println("error updating config:", err)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
"github.com/authorizerdev/authorizer/server/session"
|
"github.com/authorizerdev/authorizer/server/session"
|
||||||
|
@ -47,7 +48,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
userEmail := fmt.Sprintf("%v", claim["email"])
|
userEmail := fmt.Sprintf("%v", claim["email"])
|
||||||
user, err := db.Mgr.GetUserByEmail(userEmail)
|
user, err := db.Provider.GetUserByEmail(userEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -115,7 +116,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||||
}
|
}
|
||||||
newEmail := strings.ToLower(*params.Email)
|
newEmail := strings.ToLower(*params.Email)
|
||||||
// check if user with new email exists
|
// check if user with new email exists
|
||||||
_, err := db.Mgr.GetUserByEmail(newEmail)
|
_, err := db.Provider.GetUserByEmail(newEmail)
|
||||||
|
|
||||||
// err = nil means user exists
|
// err = nil means user exists
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -134,7 +135,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@ -147,7 +148,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Mgr.UpdateUser(user)
|
_, err = db.Provider.UpdateUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error updating user:", err)
|
log.Println("error updating user:", err)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/email"
|
"github.com/authorizerdev/authorizer/server/email"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -33,7 +34,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||||
return res, fmt.Errorf("please enter atleast one param to update")
|
return res, fmt.Errorf("please enter atleast one param to update")
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByID(params.ID)
|
user, err := db.Provider.GetUserByID(params.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`User not found`)
|
return res, fmt.Errorf(`User not found`)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||||
}
|
}
|
||||||
newEmail := strings.ToLower(*params.Email)
|
newEmail := strings.ToLower(*params.Email)
|
||||||
// check if user with new email exists
|
// check if user with new email exists
|
||||||
_, err = db.Mgr.GetUserByEmail(newEmail)
|
_, err = db.Provider.GetUserByEmail(newEmail)
|
||||||
// err = nil means user exists
|
// err = nil means user exists
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return res, fmt.Errorf("user with this email address already exists")
|
return res, fmt.Errorf("user with this email address already exists")
|
||||||
|
@ -103,7 +104,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`error generating token`, err)
|
log.Println(`error generating token`, err)
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
db.Provider.AddVerificationRequest(models.VerificationRequest{
|
||||||
Token: token,
|
Token: token,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@ -140,7 +141,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
||||||
user.Roles = rolesToSave
|
user.Roles = rolesToSave
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err = db.Mgr.UpdateUser(user)
|
user, err = db.Provider.UpdateUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error updating user:", err)
|
log.Println("error updating user:", err)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
@ -22,7 +22,7 @@ func UsersResolver(ctx context.Context) ([]*model.User, error) {
|
||||||
return res, fmt.Errorf("unauthorized")
|
return res, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
users, err := db.Mgr.GetUsers()
|
users, err := db.Provider.ListUsers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func VerificationRequestsResolver(ctx context.Context) ([]*model.VerificationReq
|
||||||
return res, fmt.Errorf("unauthorized")
|
return res, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequests, err := db.Mgr.GetVerificationRequests()
|
verificationRequests, err := db.Provider.ListVerificationRequests()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func VerifyEmailResolver(ctx context.Context, params model.VerifyEmailInput) (*m
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByToken(params.Token)
|
verificationRequest, err := db.Provider.GetVerificationRequestByToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`invalid token`)
|
return res, fmt.Errorf(`invalid token`)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func VerifyEmailResolver(ctx context.Context, params model.VerifyEmailInput) (*m
|
||||||
return res, fmt.Errorf(`invalid token`)
|
return res, fmt.Errorf(`invalid token`)
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := db.Mgr.GetUserByEmail(claim.Email)
|
user, err := db.Provider.GetUserByEmail(claim.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ func VerifyEmailResolver(ctx context.Context, params model.VerifyEmailInput) (*m
|
||||||
// update email_verified_at in users table
|
// update email_verified_at in users table
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
user.EmailVerifiedAt = &now
|
user.EmailVerifiedAt = &now
|
||||||
db.Mgr.UpdateUser(user)
|
db.Provider.UpdateUser(user)
|
||||||
// delete from verification table
|
// delete from verification table
|
||||||
db.Mgr.DeleteVerificationRequest(verificationRequest)
|
db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
|
|
||||||
roles := strings.Split(user.Roles, ",")
|
roles := strings.Split(user.Roles, ",")
|
||||||
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, roles)
|
refreshToken, _, _ := utils.CreateAuthToken(user, constants.TokenTypeRefreshToken, roles)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
@ -17,7 +16,6 @@ func adminSessionTests(t *testing.T, s TestSetup) {
|
||||||
t.Run(`should get admin session`, func(t *testing.T) {
|
t.Run(`should get admin session`, func(t *testing.T) {
|
||||||
req, ctx := createContext(s)
|
req, ctx := createContext(s)
|
||||||
_, err := resolvers.AdminSessionResolver(ctx)
|
_, err := resolvers.AdminSessionResolver(ctx)
|
||||||
log.Println("error:", err)
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
||||||
|
|
|
@ -2,7 +2,6 @@ package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
@ -17,7 +16,6 @@ func envTests(t *testing.T, s TestSetup) {
|
||||||
t.Run(`should get envs`, func(t *testing.T) {
|
t.Run(`should get envs`, func(t *testing.T) {
|
||||||
req, ctx := createContext(s)
|
req, ctx := createContext(s)
|
||||||
_, err := resolvers.EnvResolver(ctx)
|
_, err := resolvers.EnvResolver(ctx)
|
||||||
log.Println("error:", err)
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
||||||
|
|
|
@ -26,7 +26,7 @@ func forgotPasswordTest(t *testing.T, s TestSetup) {
|
||||||
})
|
})
|
||||||
assert.Nil(t, err, "no errors for forgot password")
|
assert.Nil(t, err, "no errors for forgot password")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeForgotPassword)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeForgotPassword)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
assert.Equal(t, verificationRequest.Identifier, constants.VerificationTypeForgotPassword)
|
assert.Equal(t, verificationRequest.Identifier, constants.VerificationTypeForgotPassword)
|
||||||
|
|
|
@ -28,7 +28,7 @@ func loginTests(t *testing.T, s TestSetup) {
|
||||||
|
|
||||||
assert.NotNil(t, err, "should fail because email is not verified")
|
assert.NotNil(t, err, "should fail because email is not verified")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,7 @@ func logoutTests(t *testing.T, s TestSetup) {
|
||||||
Email: email,
|
Email: email,
|
||||||
})
|
})
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeMagicLinkLogin)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeMagicLinkLogin)
|
||||||
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,7 +23,7 @@ func magicLinkLoginTests(t *testing.T, s TestSetup) {
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeMagicLinkLogin)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeMagicLinkLogin)
|
||||||
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,7 +27,7 @@ func profileTests(t *testing.T, s TestSetup) {
|
||||||
_, err := resolvers.ProfileResolver(ctx)
|
_, err := resolvers.ProfileResolver(ctx)
|
||||||
assert.NotNil(t, err, "unauthorized")
|
assert.NotNil(t, err, "unauthorized")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,7 +26,7 @@ func resetPasswordTest(t *testing.T, s TestSetup) {
|
||||||
})
|
})
|
||||||
assert.Nil(t, err, "no errors for forgot password")
|
assert.Nil(t, err, "no errors for forgot password")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeForgotPassword)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeForgotPassword)
|
||||||
assert.Nil(t, err, "should get forgot password request")
|
assert.Nil(t, err, "should get forgot password request")
|
||||||
|
|
||||||
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
|
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
func TestResolvers(t *testing.T) {
|
func TestResolvers(t *testing.T) {
|
||||||
databases := map[string]string{
|
databases := map[string]string{
|
||||||
constants.DbTypeSqlite: "../../data.db",
|
constants.DbTypeSqlite: "../../data.db",
|
||||||
// constants.DbTypeArangodb: "http://localhost:8529",
|
constants.DbTypeArangodb: "http://localhost:8529",
|
||||||
// constants.DbTypeMongodb: "mongodb://localhost:27017",
|
constants.DbTypeMongodb: "mongodb://localhost:27017",
|
||||||
}
|
}
|
||||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyVersion, "test")
|
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyVersion, "test")
|
||||||
for dbType, dbURL := range databases {
|
for dbType, dbURL := range databases {
|
||||||
|
@ -24,10 +24,10 @@ func TestResolvers(t *testing.T) {
|
||||||
db.InitDB()
|
db.InitDB()
|
||||||
|
|
||||||
// clean the persisted config for test to use fresh config
|
// clean the persisted config for test to use fresh config
|
||||||
envData, err := db.Mgr.GetEnv()
|
envData, err := db.Provider.GetEnv()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
envData.EnvData = []byte{}
|
envData.EnvData = []byte{}
|
||||||
db.Mgr.UpdateEnv(envData)
|
db.Provider.UpdateEnv(envData)
|
||||||
}
|
}
|
||||||
env.PersistEnv()
|
env.PersistEnv()
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ func sessionTests(t *testing.T, s TestSetup) {
|
||||||
_, err := resolvers.SessionResolver(ctx, []string{})
|
_, err := resolvers.SessionResolver(ctx, []string{})
|
||||||
assert.NotNil(t, err, "unauthorized")
|
assert.NotNil(t, err, "unauthorized")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,7 +40,7 @@ func signupTests(t *testing.T, s TestSetup) {
|
||||||
|
|
||||||
assert.NotNil(t, err, "should throw duplicate email error")
|
assert.NotNil(t, err, "should throw duplicate email error")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, email, verificationRequest.Email)
|
assert.Equal(t, email, verificationRequest.Email)
|
||||||
cleanData(email)
|
cleanData(email)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"time"
|
"time"
|
||||||
|
@ -33,26 +32,26 @@ type TestSetup struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanData(email string) {
|
func cleanData(email string) {
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = db.Mgr.DeleteVerificationRequest(verificationRequest)
|
err = db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err = db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeForgotPassword)
|
verificationRequest, err = db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeForgotPassword)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = db.Mgr.DeleteVerificationRequest(verificationRequest)
|
err = db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest, err = db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeUpdateEmail)
|
verificationRequest, err = db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeUpdateEmail)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = db.Mgr.DeleteVerificationRequest(verificationRequest)
|
err = db.Provider.DeleteVerificationRequest(verificationRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbUser, err := db.Mgr.GetUserByEmail(email)
|
// dbUser, err := db.Provider.GetUserByEmail(email)
|
||||||
if err == nil {
|
// if err == nil {
|
||||||
db.Mgr.DeleteUser(dbUser)
|
// db.Provider.DeleteUser(dbUser)
|
||||||
db.Mgr.DeleteUserSession(dbUser.ID)
|
// db.Provider.DeleteSession(dbUser.ID)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
func createContext(s TestSetup) (*http.Request, context.Context) {
|
func createContext(s TestSetup) (*http.Request, context.Context) {
|
||||||
|
@ -74,7 +73,7 @@ func testSetup() TestSetup {
|
||||||
}
|
}
|
||||||
|
|
||||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyEnvPath, "../../.env.sample")
|
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyEnvPath, "../../.env.sample")
|
||||||
log.Println("envstore", envstore.EnvInMemoryStoreObj.GetEnvStoreClone())
|
|
||||||
env.InitEnv()
|
env.InitEnv()
|
||||||
session.InitSession()
|
session.InitSession()
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
@ -21,7 +20,7 @@ func updateEnvTests(t *testing.T, s TestSetup) {
|
||||||
|
|
||||||
data := model.UpdateEnvInput{}
|
data := model.UpdateEnvInput{}
|
||||||
_, err := resolvers.UpdateEnvResolver(ctx, data)
|
_, err := resolvers.UpdateEnvResolver(ctx, data)
|
||||||
log.Println("error:", err)
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
|
||||||
|
|
|
@ -30,7 +30,7 @@ func updateProfileTests(t *testing.T, s TestSetup) {
|
||||||
})
|
})
|
||||||
assert.NotNil(t, err, "unauthorized")
|
assert.NotNil(t, err, "unauthorized")
|
||||||
|
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
verifyRes, err := resolvers.VerifyEmailResolver(ctx, model.VerifyEmailInput{
|
||||||
Token: verificationRequest.Token,
|
Token: verificationRequest.Token,
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,7 +24,7 @@ func verifyEmailTest(t *testing.T, s TestSetup) {
|
||||||
user := *res.User
|
user := *res.User
|
||||||
assert.Equal(t, email, user.Email)
|
assert.Equal(t, email, user.Email)
|
||||||
assert.Nil(t, res.AccessToken, "access token should be nil")
|
assert.Nil(t, res.AccessToken, "access token should be nil")
|
||||||
verificationRequest, err := db.Mgr.GetVerificationByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(email, constants.VerificationTypeBasicAuthSignup)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, email, verificationRequest.Email)
|
assert.Equal(t, email, verificationRequest.Email)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/envstore"
|
"github.com/authorizerdev/authorizer/server/envstore"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
|
@ -20,7 +20,7 @@ import (
|
||||||
|
|
||||||
// CreateAuthToken util to create JWT token, based on
|
// CreateAuthToken util to create JWT token, based on
|
||||||
// user information, roles config and CUSTOM_ACCESS_TOKEN_SCRIPT
|
// user information, roles config and CUSTOM_ACCESS_TOKEN_SCRIPT
|
||||||
func CreateAuthToken(user db.User, tokenType string, roles []string) (string, int64, error) {
|
func CreateAuthToken(user models.User, tokenType string, roles []string) (string, int64, error) {
|
||||||
t := jwt.New(jwt.GetSigningMethod(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyJwtType)))
|
t := jwt.New(jwt.GetSigningMethod(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyJwtType)))
|
||||||
expiryBound := time.Hour
|
expiryBound := time.Hour
|
||||||
if tokenType == constants.TokenTypeRefreshToken {
|
if tokenType == constants.TokenTypeRefreshToken {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func SaveSessionInDB(userId string, c *gin.Context) {
|
||||||
IP: GetIP(c.Request),
|
IP: GetIP(c.Request),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.Provider.AddSession(&sessionData)
|
err := db.Provider.AddSession(sessionData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("=> error saving session in db:", err)
|
log.Println("=> error saving session in db:", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,14 +3,14 @@ package utils
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO move this to provider
|
// TODO move this to provider
|
||||||
// rename it to AsAPIUser
|
// rename it to AsAPIUser
|
||||||
|
|
||||||
func GetResponseUserData(user db.User) *model.User {
|
func GetResponseUserData(user models.User) *model.User {
|
||||||
isEmailVerified := user.EmailVerifiedAt != nil
|
isEmailVerified := user.EmailVerifiedAt != nil
|
||||||
isPhoneVerified := user.PhoneNumberVerifiedAt != nil
|
isPhoneVerified := user.PhoneNumberVerifiedAt != nil
|
||||||
return &model.User{
|
return &model.User{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user