Extend PostgreSQL implementation and unit tests on MongoDB storage

This commit is contained in:
2023-05-02 00:34:33 +02:00
parent 1bf02aa132
commit c6ba00b74f
18 changed files with 870 additions and 752 deletions

View File

@@ -65,20 +65,20 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
// If username, is provided (not an empty string), it will search by username only
// If username is an empty string and email is provided, it will search by email
// If both username and email are empty strings, phone_number must be provided and it will search by phone number
func (s MongoDBStorage) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) {
func (s MongoDBStorage) LocalAuthentication(namespace string, username *string, email *string, phone_number *string) (*Account, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
account := &Account{}
if username != "" {
if username != nil {
if err := collection.FindOne(context.TODO(), bson.M{"namespace": namespace, "authentication.local.username": username}).Decode(account); err != nil {
return nil, err
}
} else if email != "" {
} else if email != nil {
if err := collection.FindOne(context.TODO(), bson.M{"namespace": namespace, "authentication.local.email": email}).Decode(account); err != nil {
return nil, err
}
} else if phone_number != "" {
} else if phone_number != nil {
if err := collection.FindOne(context.TODO(), bson.M{"namespace": namespace, "authentication.local.phone_number": phone_number}).Decode(account); err != nil {
return nil, err
}
@@ -191,3 +191,8 @@ func (s MongoDBStorage) UpdateAccount(account Account) error {
return nil
}
func (s MongoDBStorage) Migrate() error {
fmt.Println("no migration")
return nil
}