Beispiel #1
0
		public static void Main (string[] args)
		{
			var strCon = ConfigUtils.GetConnectionString("ApplicationDb");

			string tmp = strCon;
			Console.WriteLine("Digite la cadena de conexion  [{0}] Enter para continuar", strCon);
			strCon= Console.ReadLine();
			if(strCon.IsNullOrEmpty()) strCon=tmp;

			OrmLiteConfig.DialectProvider = MySqlDialect.Provider;

			var dbFactory = new OrmLiteConnectionFactory(strCon);
									
			OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(	dbFactory);

			AuthRepoProxy rp = new AuthRepoProxy(dbFactory, null);

			rp.CreateAuthTables(authRepo,false);

			rp.SetEngine (authRepo);

			string password = rp.CreateRandomPassword(8);

			tmp = password;
			Console.WriteLine("Digite la clave para {0} [{1}] Enter para continuar", "admin", password);
			password= Console.ReadLine();
			if(password.IsNullOrEmpty()) password=tmp;

			password= rp.CreateAdminUser(authRepo, "Admin", "App", "*****@*****.**", password);


			//

			password = rp.CreateRandomPassword(8);
			
			tmp = password;
			Console.WriteLine("Digite la clave para {0} [{1}] Enter para continuar", "user", password);
			password= Console.ReadLine();
			if(password.IsNullOrEmpty()) password=tmp;
			UserAuth user = new UserAuth{ UserName="******", Email="*****@*****.**"};

			password= rp.CreateUser (authRepo, user,password);
			Console.WriteLine(password);


			dbFactory.Run (c => {
				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Radicar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Radicar", Title = "Recepcionista"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Asignar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Asignar", Title = "Secretario General"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Solucionar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Solucionar", Title = "Abogado"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Firmar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Firmar", Title = "Abogado"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="RegistrarFirmar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "RegistrarFirmar", Title = "Recepcionista"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Alistar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Alistar", Title = "Recepcionista"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Entregar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Entregar", Title = "Mensajero"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Cerrar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Cerrar", Title = "Recepcionista"});

				if(c.FirstOrDefault<AuthRole>(f=>f.Name=="Consultar")==default(AuthRole))
					c.Insert<AuthRole>(new AuthRole{Name = "Consultar", Title = "Público"});


			});

		}
Beispiel #2
0
        void ConfigureApp(Container container)
        {
            var appSettings = new ConfigurationResourceManager();

            double se= appSettings.Get("DefaultSessionExpiry", 480);
            AuthProvider.DefaultSessionExpiry=TimeSpan.FromMinutes(se);

            string cacheHost= appSettings.Get("REDISTOGO_URL","localhost:6379").Replace("redis://redistogo:","").Replace("/","");

            var redisClientManager = new BasicRedisClientManager(new string[]{cacheHost});

            OrmLiteConfig.DialectProvider= MySqlDialectProvider.Instance;

            IDbConnectionFactory dbFactory =
                new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("ApplicationDb"));

            string smtpServer= appSettings.Get("MAILGUN_SMTP_SERVER", "localhost");
            string smtpLogin= appSettings.Get("MAILGUN_SMTP_LOGIN", "username");
            string smtpPassword= appSettings.Get("MAILGUN_SMTP_PASSWORD", "PASSWORD");
            int smtpPort= appSettings.Get("MAILGUN_SMTP_PORT", 587);
            Mailer mailer = new Mailer(smtpServer, smtpPort, smtpLogin, smtpPassword);

            var appConfig= new AppConfig(appSettings);

            RepositoryClient rc = new RepositoryClient(dbFactory, redisClientManager);
            Controller controller = new Controller(rc,mailer,appConfig);
            container.Register<Controller>( controller );

            AuthRepoProxy arp = new AuthRepoProxy(dbFactory, redisClientManager);
            container.Register<AuthRepoProxy>( arp );

            container.Register<IRedisClientsManager>(c => redisClientManager);
            //container.Register<ICacheClient>(c => redisClientManager);

            Plugins.Add(new AuthFeature( () => new AuthUserSession(), // or Use your own typed Custom AuthUserSession type
                new IAuthProvider[]
            {
                new AuthenticationProvider(){SessionExpiry=TimeSpan.FromMinutes(se)}
            })
               {
                IncludeAssignRoleServices=false
            });

            OrmLiteAuthRepository authRepo = new OrmLiteAuthRepository(dbFactory);

            container.Register<IUserAuthRepository>(c => authRepo);

            if(appSettings.Get("EnableRegistrationFeature", false))
                Plugins.Add( new  RegistrationFeature());
        }
Beispiel #3
0
		public UserManager (IRequestContext requestContex, AuthRepoProxy authRepoProxy)
		{
			RequestContext= requestContex;
			AuthRepoProxy = authRepoProxy;
		}