Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IConfigurationSection DBConf           = Configuration.GetSection("DBConfigurationOffline");
            ConnectionSetting     connectionString = new ConnectionSetting(
                DBConf.GetValue <string>("ServerName"),
                DBConf.GetValue <string>("DatabaseName"),
                DBConf.GetValue <string>("Port"),
                DBConf.GetValue <string>("Username"),
                DBConf.GetValue <string>("Password")
                );

            // Add framework services.
            MovieDbContext.Setting = connectionString;
            services.AddDbContext <MovieDbContext>(options => options.UseSqlServer(connectionString.ToString()));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <MovieDbContext>()
            .AddDefaultTokenProviders();

            services.AddMvc();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IConfigurationSection DBConf           = Configuration.GetSection("DBOnline2");
            IConfigurationSection DBLogConf        = Configuration.GetSection("DBLogOnline");
            ConnectionSetting     connectionString = new ConnectionSetting(
                DBConf.GetValue <string>("ServerName"),
                DBConf.GetValue <string>("DatabaseName"),
                DBConf.GetValue <string>("Port"),
                DBConf.GetValue <string>("Username"),
                DBConf.GetValue <string>("Password")
                );
            ConnectionSetting logConnectionString = new ConnectionSetting(
                DBLogConf.GetValue <string>("ServerName"),
                DBLogConf.GetValue <string>("DatabaseName"),
                DBLogConf.GetValue <string>("Port"),
                DBLogConf.GetValue <string>("Username"),
                DBLogConf.GetValue <string>("Password")
                );

            services.AddDbContext <NavaraDbContext>(options => options.UseSqlServer(connectionString.ToString()));
            //services.AddDbContext<BaseDbContext>(options => options.UseSqlServer(connectionString.ToString()));
            services.AddDbContext <LogDbContext>(options => options.UseSqlServer(logConnectionString.ToString()));
            NavaraDbContext.DEFAULT_CONNECTION_STRING = connectionString.ToString();

            services.AddScoped <IUsersService, UsersService <Account, NavaraDbContext> >();
            // AddIdentity adds cookie based authentication
            // Adds scoped classes for things like UserManager, SignInManager, PasswordHashers etc..
            services.AddIdentity <ApplicationUser, IdentityRole <Guid> >(optoins =>
            {
                //Onyl unique emails
                optoins.User.RequireUniqueEmail         = false;
                optoins.Password.RequireDigit           = false;
                optoins.Password.RequiredLength         = 6;
                optoins.Password.RequiredUniqueChars    = 0;
                optoins.Password.RequireLowercase       = false;
                optoins.Password.RequireNonAlphanumeric = false;
                optoins.Password.RequireUppercase       = false;
            })
            // Adds UserStore and RoleStore from this context
            // That are consumed by the UserManager and RoleManager
            .AddEntityFrameworkStores <NavaraDbContext>()
            // Adds a provider that generates unique keys and hashes for things like
            // forgot password links, phone number verification codes etc...
            .AddDefaultTokenProviders();

            //Configure IoC values
            JwtService.Audience  = Configuration["Jwt:Audience"];
            JwtService.Issuer    = Configuration["Jwt:Issuer"];
            JwtService.SecretKey = Configuration["Jwt:SecretKey"];


            //Add the token based authentication
            services.AddAuthentication().AddJwtBearer(options =>
            {
                //Set the parameters
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateAudience         = true,
                    ValidateIssuer           = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = JwtService.Issuer,
                    ValidAudience    = JwtService.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(
                        Encoding.UTF8.GetBytes(JwtService.SecretKey))
                };
            }).AddFacebook(options =>
            {
                options.AppId     = "298734884211109";
                options.AppSecret = "d01d4721a2113bf6f623981653503ccc";
            }).AddGoogle(options =>
            {
                options.ClientId     = "876550715606-pi1lhpd3856q7l63c9ado274950dm676.apps.googleusercontent.com";
                options.ClientSecret = "xDiz4sz_LTqhObJ2E8fRrLxN";
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.Cookie.Expiration = TimeSpan.FromHours(2.0);
                options.LoginPath         = "/Home/SignIn";
                options.AccessDeniedPath  = "/Home";
                options.SlidingExpiration = true;
            });

            services.AddMvc();
            services.AddSignalR();

            #region PDF Generator
            var context = new CustomAssemblyLoadContext();
            context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));
            services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
            #endregion

            #region Configure Email
            EmailService.AppName         = "Navara Store";
            EmailService.SenderName      = "Navara Store Team";
            EmailService.ConfirmationURL = "http://navarastore.com/Users/ConfirmAccount?token={0}&userid={1}";
            EmailService.ResetURL        = "http://navarastore.com/Users/ResetPassword?token={0}&userid={1}";
            EmailService.SenderEmail     = "*****@*****.**";
            EmailService.Password        = "******";
            EmailService.SupportEmail    = "*****@*****.**";
            EmailService.SupportPassword = "******";
            EmailService.ServerMailHost  = "mi3-wts6.a2hosting.com";
            EmailService.ServerPort      = 25;
            EmailService.SSLNeed         = false;
            #endregion
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IConfigurationSection DBConf           = Configuration.GetSection("DBOnline");
            IConfigurationSection DBLogConf        = Configuration.GetSection("DBLogOnline");
            ConnectionSetting     connectionString = new ConnectionSetting(
                DBConf.GetValue <string>("ServerName"),
                DBConf.GetValue <string>("DatabaseName"),
                DBConf.GetValue <string>("Port"),
                DBConf.GetValue <string>("Username"),
                DBConf.GetValue <string>("Password")
                );
            ConnectionSetting logConnectionString = new ConnectionSetting(
                DBLogConf.GetValue <string>("ServerName"),
                DBLogConf.GetValue <string>("DatabaseName"),
                DBLogConf.GetValue <string>("Port"),
                DBLogConf.GetValue <string>("Username"),
                DBLogConf.GetValue <string>("Password")
                );

            services.AddDbContext <OmniDbContext>(options =>
                                                  options.UseSqlServer(connectionString.ToString()));
            //services.AddDbContext<BaseDbContext>(options => options.UseSqlServer(connectionString.ToString()));
            services.AddDbContext <LogDbContext>(options => options.UseSqlServer(logConnectionString.ToString()));
            OmniDbContext.DEFAULT_CONNECTION_STRING = connectionString.ToString();

            services.AddScoped <IUsersService, UsersService <Account, OmniDbContext> >();
            // AddIdentity adds cookie based authentication
            // Adds scoped classes for things like UserManager, SignInManager, PasswordHashers etc..
            services.AddIdentity <ApplicationUser, IdentityRole>(optoins =>
            {
                //Onyl unique emails
                optoins.User.RequireUniqueEmail         = true;
                optoins.Password.RequireDigit           = false;
                optoins.Password.RequiredLength         = 6;
                optoins.Password.RequiredUniqueChars    = 0;
                optoins.Password.RequireLowercase       = false;
                optoins.Password.RequireNonAlphanumeric = false;
                optoins.Password.RequireUppercase       = false;
            })
            // Adds UserStore and RoleStore from this context
            // That are consumed by the UserManager and RoleManager
            .AddEntityFrameworkStores <OmniDbContext>()
            // Adds a provider that generates unique keys and hashes for things like
            // forgot password links, phone number verification codes etc...
            .AddDefaultTokenProviders();

            //Configure IoC values
            JwtService.Audience  = Configuration["Jwt:Audience"];
            JwtService.Issuer    = Configuration["Jwt:Issuer"];
            JwtService.SecretKey = Configuration["Jwt:SecretKey"];


            //Add the token based authentication
            services.AddAuthentication().AddJwtBearer(options =>
            {
                //Set the parameters
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateAudience         = true,
                    ValidateIssuer           = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = JwtService.Issuer,
                    ValidAudience    = JwtService.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(
                        Encoding.UTF8.GetBytes(JwtService.SecretKey))
                };
            }).AddFacebook(options =>
            {
                options.AppId     = "298734884211109";
                options.AppSecret = "d01d4721a2113bf6f623981653503ccc";
            }).AddGoogle(options =>
            {
                options.ClientId     = "876550715606-pi1lhpd3856q7l63c9ado274950dm676.apps.googleusercontent.com";
                options.ClientSecret = "xDiz4sz_LTqhObJ2E8fRrLxN";
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.Cookie.Expiration = TimeSpan.FromHours(2.0);
                options.LoginPath         = "/Home/SignIn";
                options.AccessDeniedPath  = "/Home";
                options.SlidingExpiration = true;
            });

            services.AddMvc();

            services.AddCors(options =>
            {
                options.AddPolicy("AnyOrigin", builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod();
                });
            });

            #region Configure Email
            EmailService.AppName         = "OMNI Application";
            EmailService.SenderName      = "OMNI Team";
            EmailService.ConfirmationURL = "http://OMNIAPI.Smartlife-solutions.com/Users/Confirm?token={0}&UserID={1}";
            EmailService.ResetURL        = "http://OMNIAPI.Smartlife-solutions.com/Users/ResetPassword?token={0}&UserID={1}";
            #endregion
        }