Ejemplo n.º 1
0
        public void CreateUsers(Container container)
        {
            var userRep = new OrmLiteAuthRepository(container.Resolve <IDbConnectionFactory>());

            userRep.DropAndReCreateTables();
            container.Register <IUserAuthRepository>(userRep);
            var appSettings    = container.Resolve <PlacesToVisitAppSettings>();
            var dataRepository = container.Resolve <IPlacesToVisitRepository>();

            userRep.DropAndReCreateTables();
            string pwHash;
            string pwSalt;

            new SaltedHash().GetHashAndSaltString(
                appSettings.Get("Salt", "debugSalt"),
                out pwHash,
                out pwSalt);

            var userAuth1 = userRep.CreateUserAuth(new UserAuth
            {
                Email        = "*****@*****.**",
                DisplayName  = "Darren",
                UserName     = "******",
                FirstName    = "Darren",
                LastName     = "Reid",
                PasswordHash = pwHash,
                Salt         = pwSalt,
                Roles        = { "Admin" }
            }, "abc123");

            var user1 = userAuth1.ConvertTo <User>();

            dataRepository.CreateUserIfNotExists(user1);

            var userAuth2 = userRep.CreateUserAuth(new UserAuth
            {
                Email        = "*****@*****.**",
                DisplayName  = "Kyle",
                UserName     = "******",
                FirstName    = "Kyle",
                LastName     = "Hodgson",
                PasswordHash = pwHash,
                Salt         = pwSalt,
                Roles        = { "Admin" }
            }, "123abc");

            var user2 = userAuth2.ConvertTo <User>();

            dataRepository.CreateUserIfNotExists(user2);
        }
Ejemplo n.º 2
0
 private static void ResetAll(Container container, OrmLiteAuthRepository authRepo)
 {
     authRepo.DropAndReCreateTables();
     container.Resolve <IDbConnectionFactory>().Run(db => {
         db.DropAndCreateTable <EmailRegistration>();
         db.DropAndCreateTable <SMessageReceipt>();
     });
     container.Resolve <IRedisClientsManager>().Exec(r => r.FlushAll());
 }
        public static void ResetUsers(OrmLiteAuthRepository authRepo)
        {
            authRepo.DropAndReCreateTables();

            CreateUser(authRepo, 1, "test", "test", new List <string> {
                "TheRole"
            }, new List <string> {
                "ThePermission"
            });
            CreateUser(authRepo, 2, "test2", "test2");
        }
        public void SetUp()
        {
            try
            {
                tests = new OAuthUserSessionTests();
                var inMemoryRepo = new InMemoryAuthRepository();
                inMemoryRepo.Clear();
                userAuthRepositorys.Add(inMemoryRepo);

                var appSettings = new AppSettings();
                var redisRepo   = new RedisAuthRepository(new BasicRedisClientManager(new string[] { appSettings.GetString("Redis.Host") ?? "localhost" }));
                redisRepo.Clear();
                userAuthRepositorys.Add(redisRepo);

                if (OAuthUserSessionTestsBase.UseSqlServer)
                {
                    var connStr          = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\auth.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                    var sqlServerFactory = new OrmLiteConnectionFactory(connStr, SqlServerOrmLiteDialectProvider.Instance);
                    var sqlServerRepo    = new OrmLiteAuthRepository(sqlServerFactory);
                    sqlServerRepo.DropAndReCreateTables();
                }
                else
                {
                    var sqliteInMemoryRepo = new OrmLiteAuthRepository(dbFactory);
                    using (var db = dbFactory.Open())
                    {
                        db.DropAndCreateTable <UserAuth>();
                        db.DropAndCreateTable <UserAuthDetails>();
                    }
                    sqliteInMemoryRepo.Clear();
                    userAuthRepositorys.Add(sqliteInMemoryRepo);

                    var sqliteDbFactory = new OrmLiteConnectionFactory(
                        "~/App_Data/auth.sqlite".MapProjectPath());
                    var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
                    sqliteDbRepo.CreateMissingTables();
                    userAuthRepositorys.Add(sqliteDbRepo);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Ejemplo n.º 5
0
        private static void InitialDbTables(Funq.Container container, OrmLiteAuthRepository <UserAccount, UserAccountDetail> userRepository)
        {
            string hash, salt;

            new SaltedHash().GetHashAndSaltString("password1", out hash, out salt);

            userRepository.DropAndReCreateTables();
            using (var dbConnection = container.Resolve <IDbConnectionFactory>().OpenDbConnection())
            {
                dbConnection.CreateTable <Bill>(true);
                dbConnection.CreateTable <Invoice>(true);
                dbConnection.CreateTable <AddressBranching>(true);
                dbConnection.CreateTable <Address>(true);
                dbConnection.CreateTable <Company>(true);
                dbConnection.CreateTable <Category>(true);
            }
            userRepository.CreateUserAuth(new UserAccount
            {
                UserName = "******",
                Password = hash,
                FullName = "Cheng Zhang",
                Email    = "*****@*****.**",
                Salt     = salt,
                Roles    = new List <string> {
                    RoleNames.Admin
                },
                Permissions = new List <string> {
                    "Get"
                },
                CreatedDate     = DateTime.Now,
                Create_On       = DateTime.Now,
                LastLoginTime   = DateTime.Now,
                Last_Updated_By = 0,
                Last_Updated_On = DateTime.Now
            }, "password1");
        }
Ejemplo n.º 6
0
        public static void Settup_Test_Database(IDbConnectionFactory dbFactory = null)
        {
            var dbConnectionFactory = dbFactory;


            if (dbConnectionFactory == null)
            {
                var connectionString = ConfigurationManager.ConnectionStrings["Auth202Db"].ConnectionString;
                dbConnectionFactory = new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider);
            }


            using (var db = dbConnectionFactory.OpenDbConnection())
            {
                if (db.TableExists("Transaction"))
                {
                    db.DropTable <Transaction>();
                }
                if (db.TableExists("CurrencyType"))
                {
                    db.DropTable <CurrencyType>();
                }
                if (db.TableExists("TransactionStatusType"))
                {
                    db.DropTable <TransactionStatusType>();
                }
                if (db.TableExists("TransactionNotificationStatusType"))
                {
                    db.DropTable <TransactionNotificationStatusType>();
                }
                if (db.TableExists("TransactionType"))
                {
                    db.DropTable <TransactionType>();
                }

                db.CreateTable <TransactionType>();
                db.CreateTable <TransactionNotificationStatusType>();
                db.CreateTable <TransactionStatusType>();
                db.CreateTable <CurrencyType>();
                db.CreateTable <Transaction>();

                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.AuthorizeAndCapture, Description = "Authorize and Capture"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.AuthorizeOnly, Description = "Authorize Only"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.CapturePrior, Description = "Capture Prior Authorization"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.Refund, Description = "Refund"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.Void, Description = "Void"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.ZeroDollar, Description = "An internal zero dollar transaction"
                });
                db.Insert(new TransactionType {
                    Id = (long)TRANSACTION_TYPE.Unknown, Description = "The transaction type is unknown"
                });

                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.None, Status = "Processing"
                });
                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.DeclinedNotification, Status = "Declined Notification Sent"
                });
                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.ErrorNotification, Status = "Error Notifications Sent"
                });
                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.SettledNotification, Status = "Settled Notifications Sent"
                });
                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.RefundedNotification, Status = "Refunded Notifications Sent"
                });
                db.Insert(new TransactionNotificationStatusType {
                    Id = (long)TRANSACTION_NOTIFICATION_STATUS.VoidedNotification, Status = "Voided Notifications Sent"
                });

                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Pending, Status = "Transaction Approved but pending completion"
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Settled, Status = "Transaction completed.  Funds received."
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Refunded, Status = "Transaction completed.  Customer refunded."
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Voided, Status = "Transaction voided."
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Expired, Status = "Transaction has expired."
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Declined, Status = "Transaction Declinded.", IsErrorStatus = true
                });
                db.Insert(new TransactionStatusType {
                    Id = (long)TRANSACTION_STATUS.Error, Status = "Transaction Error.", IsErrorStatus = true
                });

                db.Insert(new CurrencyType {
                    Id = (long)CURRENCY_TYPE.USDollar, Description = "US Dollar", Code = "USD", Symbol = "$"
                });
                db.Insert(new CurrencyType {
                    Id = (long)CURRENCY_TYPE.CandianDollar, Description = "Canadian Dollar", Code = "CAD", Symbol = "$"
                });
                db.Insert(new CurrencyType {
                    Id = (long)CURRENCY_TYPE.Peso, Description = "Mexican Peso", Code = "MXN", Symbol = "$"
                });
            }

            var userRepo = new OrmLiteAuthRepository(dbConnectionFactory);

            userRepo.DropAndReCreateTables();

            var user = new UserAuth
            {
                Id          = DefaultAdmin.Id,
                DisplayName = DefaultAdmin.Username,
                Email       = DefaultAdmin.Email,
                UserName    = DefaultAdmin.Username,
                FirstName   = DefaultAdmin.Username,
                Roles       = DefaultAdmin.Roles,
                Permissions = DefaultAdmin.Permissions
            };

            CreateUser(userRepo, user, DefaultAdmin.Password);
        }
Ejemplo n.º 7
0
        // Configure your AppHost with the necessary configuration and dependencies your App needs
        public override void Configure(Container container)
        {
            #region Metadata
            SetConfig(new HostConfig
            {
                DefaultRedirectPath = "/metadata",
                DebugMode           = AppSettings.Get(nameof(HostConfig.DebugMode), false)
            });
            #endregion

            #region Plugins
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(
                typeof(CreatePlaceValidator).Assembly);

            Plugins.Add(new CorsFeature());

            Plugins.Add(new PostmanFeature());
            #endregion

            #region App
            container.RegisterAutoWiredAs <BasicOrmMessageRepository, IMessageRepository>();
            container.RegisterAutoWired <MyAppSettings>();
            var appSettings = container.Resolve <MyAppSettings>();
            #endregion

            #region Database
            var dbFactory = new OrmLiteConnectionFactory(
                appSettings.Get("sqlLiteConnectionString", "").MapHostAbsolutePath(),
                SqliteDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);

            using (var db = dbFactory.OpenDbConnection())
            {
                //db.DropAndCreateTable<UserGreeting>();
                db.DropAndCreateTable <UserLanguage>();
                db.DropAndCreateTable <GreetingUsage>();
            }

            using (var db = dbFactory.OpenDbConnection())
            {
                db.Insert(new UserLanguage {
                    Language = "English"
                });
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "Hello, {0}",
                //    UserLanguageId = 1
                //});
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "G'day, {0}"
                //});
                //db.Insert(new UserGreeting
                //{
                //    Greeting = "Howdy, {0}!"
                //});
            }
            OrmLiteConfig.StringFilter = s => s.Trim();
            #endregion

            #region Auth
            var authProviders = new List <IAuthProvider>();
            authProviders.Add(new CredentialsAuthProvider());

            var authFeature = new AuthFeature(SessionFactory, authProviders.ToArray());
            Plugins.Add(authFeature);

            var authRepo = new OrmLiteAuthRepository(dbFactory);
            container.Register <IUserAuthRepository>(authRepo);
            container.Register <ICacheClient>(new MemoryCacheClient());
            authRepo.DropAndReCreateTables();
            authRepo.InitSchema();

            Plugins.Add(new RegistrationFeature());
            //CreateUsers(userRep);

            authRepo.CreateUserAuth(new UserAuth
            {
                UserName = "******",
                Roles    = new List <string> {
                    RoleNames.Admin
                }
            }, "admin");
            #endregion

            //Plugins.Add(new OpenApiFeature());

            //TODO:
            //Logging.
            //Cache.
            //Global Response Filter: CommonResponse.
            //Batched requests.
            //transactions.
            //attachments
            //Profiler.
            //Versioning.
            //Compression.
            //Autoquery.
            //stripe.com
        }