示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")
                                                         options.UseInMemoryDatabase("Default")
                                                         );

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

            // Add application services.
            services.AddTransient <IEmailSender>((iServiceProvider) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey")));
            services.AddTransient <IBraintreeGateway>((IServiceProvider) => new BraintreeGateway(
                                                          Configuration.GetValue <string>("Braintree.Environment"),
                                                          Configuration.GetValue <string>("Braintree.MerchantID"),
                                                          Configuration.GetValue <string>("Braintree.PublicKey"),
                                                          Configuration.GetValue <string>("Braintree.PrivateKey")
                                                          ));

            services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) =>
            {
                SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets.AuthId"),
                    Configuration.GetValue <string>("SmartyStreets.AuthToken")
                    );
                return(clientBuilder.BuildUsStreetApiClient());
            });

            services.AddMvc();
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string DonutStoreConnectionString = Configuration.GetConnectionString("DonutStore");

            services.AddDbContext <DonutStoreDbContext>(opt => opt.UseSqlServer(DonutStoreConnectionString));

            services.AddIdentity <DonutStoreUser, IdentityRole>()
            .AddEntityFrameworkStores <DonutStoreDbContext>()
            .AddDefaultTokenProviders();


            services.AddMvc();

            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });
            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });



            //smartystreets
            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]);
                return(builder.BuildUsStreetApiClient());
            });
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddAntiforgery();
            services.AddSession();

            services.Configure <Models.ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
            services.AddOptions();



            //for Identity Framework stuff



            //Old HArdcoded way to handle Identity Framework EF
            services.AddDbContext <JimTestContext>(opt =>
                                                   opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                    sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName)));
            //opt.UseInMemoryDatabase("Identities"));
            //opt.UseSqlServer("Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = JimTest; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False",
            //sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName))
            //);


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


            //add smarty streets stuff here and put tokens in secrets file
            services.AddTransient <SmartyStreets.USStreetApi.Client>((x) =>
            {
                var client = new SmartyStreets.ClientBuilder(
                    Configuration["smartystreets.authid"],
                    Configuration["smartystreets.authtoken"])

                             .BuildUsStreetApiClient();

                return(client);
            });

            services.AddTransient <SendGrid.SendGridClient>((x) =>
            {
                return(new SendGrid.SendGridClient(Configuration["sendgrid"]));
            });

            services.AddTransient <Braintree.BraintreeGateway>((x) =>
            {
                return(new Braintree.BraintreeGateway(
                           Configuration["braintree.environment"],
                           Configuration["braintree.merchantid"],
                           Configuration["braintree.publickey"],
                           Configuration["braintree.privatekey"]
                           ));
            });
        }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Configuration.GetConnectionString("AdventureWorks2016");
            //Configuration.GetConnectionString("FinalProjDB");

            string organicFarmStoreConnectionString = Configuration.GetConnectionString("OrganicFarmStore");

            //Singleton:Creates one service when the app starts then it will be the same for every request
            //Transient:Constructed and destructed every single request
            //services.AddTransient<SampleService>();

            //These are not part of .NET Core... they are seperate libraries that must be installed via a program called NuGet.
            //Right click on your Project -> Manage NuGet Packages and brwose and install each of the following

            //using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
            //using Microsoft.EntityFrameworkCore;
            //using Microsoft.AspNetCore.Identity;

            // services.AddDbContext<IdentityDbContext>(opt => opt.UseInMemoryDatabase("Identities"));

            services.AddDbContext <OrganicStoreDbContext>(opt => opt.UseSqlServer(organicFarmStoreConnectionString));

            services.AddIdentity <OrganicStoreUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
            })
            .AddEntityFrameworkStores <OrganicStoreDbContext>()    // Will store Identity user info
            .AddDefaultTokenProviders();

            services.AddMvc();

            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });
            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });

            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreestsAuthToken"]);
                return(builder.BuildUsStreetApiClient());

                //SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"],
                //    Configuration["SmartyStreetsAuthToken"]);
                //return builder.BuildUsStreetApiClient();
            });
        }
示例#5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)

        {
            //These are not part of .NET Core... they are seperate libraries that must be installed via a program called NuGet.
            //Right click on your Project -> Manage NuGet Packages

            Configuration.GetConnectionString("Boats");

            string boatChartersConnectionString = Configuration.GetConnectionString("Boats");

            //using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
            //using Microsoft.EntityFrameworkCore;
            //using Microsoft.AspNetCore.Identity;


            services.AddDbContext <BoatChartersDbContext>(opt => opt.UseSqlServer(boatChartersConnectionString));

            services.AddIdentity <BoatChartesUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
            })
            .AddEntityFrameworkStores <BoatChartersDbContext>()
            .AddDefaultTokenProviders();

            services
            .AddMvc()
            .AddJsonOptions(
                o =>
            {
                o.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });
            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });
            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder =
                    new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]);
                return(builder.BuildUsStreetApiClient());
            });
        }
示例#6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddAntiforgery();
            services.AddSession();

            //This will read the appsettings.json into an object which I can use throughout my app
            //services.Configure<ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
            //services.AddOptions();

            //services.AddDbContext<IdentityDbContext>(opt =>
            //opt.UseInMemoryDatabase("Identities")
            //opt.UseSqlServer("Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = BobTest; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"
            //, sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName))
            //);
            //opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            //Added the configuration settings as "ConfigureServices" method through using the sql server context:
            services.AddDbContext <BobTestContext>(
                opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                        sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName)));

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

            //Configure the service for dependency injection
            services.AddTransient <SendGrid.SendGridClient>((x) =>
            {
                return(new SendGrid.SendGridClient(Configuration["sendgrid"]));
            });

            services.AddTransient <Braintree.BraintreeGateway>((x) =>
            {
                return(new Braintree.BraintreeGateway(
                           Configuration["braintree.environment"],
                           Configuration["braintree.merchantid"],
                           Configuration["braintree.publickey"],
                           Configuration["braintree.privatekey"]
                           ));
            });

            services.AddTransient <SmartyStreets.USStreetApi.Client>((x) =>
            {
                var client = new SmartyStreets.ClientBuilder(
                    Configuration["smartystreets.authid"],
                    Configuration["smartystreets.authtoken"])
                             .BuildUsStreetApiClient();

                return(client);
            });
        }
示例#7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string ThisSiteConnectionString = Configuration.GetConnectionString("ThisSite");

            services.AddDbContext <ThisSiteDbContext>(opt => opt.UseSqlServer(ThisSiteConnectionString));

            services.AddIdentity <ThisSiteUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;

                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(30);
                options.Lockout.MaxFailedAccessAttempts = 10;
                options.Lockout.AllowedForNewUsers      = true;

                //for testing only, else true
                options.User.RequireUniqueEmail = false;
            })
            .AddEntityFrameworkStores <ThisSiteDbContext>()
            .AddDefaultTokenProviders();

            services
            .AddMvc()
            .AddJsonOptions(
                options =>
            {
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });

            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });

            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(
                    Configuration["SmartyStreetsAuthID"],
                    Configuration["SmartStreetsAuthToken"]);
                return(builder.BuildUsStreetApiClient());
            });
        }
示例#8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseMySql(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            //services.AddDefaultIdentity<StoreUser>()
            //    .AddEntityFrameworkStores<ApplicationDbContext>();

            services.AddIdentity <StoreUser, IdentityRole>()
            .AddDefaultUI()
            .AddRoles <IdentityRole>()
            .AddRoleManager <RoleManager <IdentityRole> >()
            .AddDefaultTokenProviders()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddTransient((s) => {
                return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGridApiKey")));
            });

            services.AddTransient <Microsoft.AspNetCore.Identity.UI.Services.IEmailSender>((s) =>
            {
                return(new store.Services.EmailSender(s.GetService <SendGrid.SendGridClient>()));
            });

            services.AddTransient <Braintree.IBraintreeGateway>((s) => {
                return(new Braintree.BraintreeGateway(
                           Configuration.GetValue <string>("Braintree:Environment"),
                           Configuration.GetValue <string>("Braintree:MerchantId"),
                           Configuration.GetValue <string>("Braintree:PublicKey"),
                           Configuration.GetValue <string>("Braintree:PrivateKey")
                           ));
            });

            services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets:AuthId"),
                    Configuration.GetValue <string>("SmartyStreets:AuthToken")
                    );
                return(builder.BuildUsStreetApiClient());
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
        public ActionResult ValidateAddress(string street, string city, string state, string zip)
        {
            string authId    = ConfigurationManager.AppSettings["SmartyStreets.AuthID"];
            string authToken = ConfigurationManager.AppSettings["SmartyStreets.AuthToken"];

            SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder(authId, authToken);
            var client = clientBuilder.BuildUsStreetApiClient();

            SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup();
            lookup.City    = city;
            lookup.ZipCode = zip;
            lookup.Street  = street;
            lookup.State   = state;
            client.Send(lookup);

            return(Json(lookup.Result.Select(x => new { street = x.DeliveryLine1, city = x.Components.CityName, state = x.Components.State, zip = x.Components.ZipCode + "-" + x.Components.Plus4Code })));
        }
示例#10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Use this for the mysql database:
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));

            ////Use this for in memory database like for publishing to azure for demos
            //services.AddDbContext<ApplicationDbContext>(options =>
            //options.UseInMemoryDatabase("Default"));


            services.AddIdentity <ApplicationUser, ApplicationRole>(
                identity =>
            {
                // whatever identity options you want
                identity.User.RequireUniqueEmail = true;
                identity.Password.RequiredLength = 8;
            }).AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            // Add application services.
            services.AddTransient <IEmailSender>((iSP) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey")));

            services.AddTransient <Braintree.IBraintreeGateway>((iServiceProvider) => new Braintree.BraintreeGateway(
                                                                    Configuration.GetValue <string>("Environment"),
                                                                    Configuration.GetValue <string>("MerchantId"),
                                                                    Configuration.GetValue <string>("PublicKey"),
                                                                    Configuration.GetValue <string>("PrivateKey")
                                                                    ));

            services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) =>
            {
                SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets.AuthId"),
                    Configuration.GetValue <string>("SmartyStreets.AuthToken")
                    );
                return(clientBuilder.BuildUsStreetApiClient());
            });
            services.AddSingleton <SettingsService>();

            //services.AddMvc(options =>
            //{
            //    options.Filters.Add(new Microsoft.AspNetCore.Mvc.RequireHttpsAttribute());
            //});
            services.AddMvc();
        }
示例#11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddAntiforgery();
            services.AddSession();
            services.Configure <Models.ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
            services.AddOptions();
            services.AddTransient <SendGrid.SendGridClient>((x) =>
            {
                return(new SendGrid.SendGridClient(Configuration["sendgrid"]));
            });

            services.AddTransient <Braintree.BraintreeGateway>((x) =>
            {
                return(new Braintree.BraintreeGateway(
                           Configuration["braintree.environment"],
                           Configuration["braintree.merchantid"],
                           Configuration["braintree.publickey"],
                           Configuration["braintree.privatekey"]
                           ));
            });


            //services.AddDbContext<Models.AmonTestContext>(opt =>
            //opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <Models.AmonTestContext>(
                opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                        sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName))
                );

            services.AddTransient <SmartyStreets.USStreetApi.Client>((x) =>
            {
                var client = new SmartyStreets.ClientBuilder(
                    Configuration["smartystreets.authtoken"],
                    Configuration["smartystreets.authid"])
                             .BuildUsStreetApiClient();

                return(client);
            });

            //services.AddIdentity<IdentityUser, IdentityRole>()
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <Models.AmonTestContext>()
            .AddDefaultTokenProviders();
        }
示例#12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSession();
            services.AddMvc();
            services.AddDbContext <AlejandroTestContext>(opt =>
                                                         opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
                                                                          sqlOptions => sqlOptions.MigrationsAssembly(this.GetType().Assembly.FullName)));
            //UseInMemoryDatabase("Identities"));

            services.AddAntiforgery(); //for security!
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AlejandroTestContext>()
            .AddDefaultTokenProviders();

            //setting up connectioString
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            // SERVICE TO READ THE secretAPI key
            services.AddTransient <SendGrid.SendGridClient>((x) =>
            {
                return(new SendGrid.SendGridClient(Configuration["myKey"]));
            });



            //Adding Trasient services for BRAINTREE
            services.AddTransient <Braintree.BraintreeGateway>((x) =>
            {
                return(new Braintree.BraintreeGateway(
                           Configuration["braintree.environment"],
                           Configuration["braintree.merchantid"],
                           Configuration["braintree.publickey"],
                           Configuration["braintree.privatekey"]
                           ));
            });

            // Adding Transient service for SMARTYSTREETS
            services.AddTransient <SmartyStreets.USStreetApi.Client>((x) =>
            {
                var client = new SmartyStreets.ClientBuilder(
                    Configuration["smartystreets.authid"],
                    Configuration["smartystreets.authtoken"])
                             .BuildUsStreetApiClient();
                return(client);
            });
        }
示例#13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddAntiforgery();
            services.AddSession();

            services.AddDbContext <DanielTestContext>(
                opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

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

            services.AddTransient <SendGrid.SendGridClient>((x) =>
            {
                return(new SendGrid.SendGridClient(Configuration["sendGrid"]));
            });


            services.AddTransient <Braintree.BraintreeGateway>((x) =>
            {
                return(new Braintree.BraintreeGateway(
                           Configuration["braintree.environment"],
                           Configuration["braintree.merchantid"],
                           Configuration["braintree.publickey"],
                           Configuration["braintree.privatekey"]
                           ));
            });

            services.AddTransient <SmartyStreets.USStreetApi.Client>((x) =>
            {
                var client = new SmartyStreets.ClientBuilder(
                    Configuration["smartystreets.authid"],
                    Configuration["smartystreets.authtoken"])
                             .BuildUsStreetApiClient();

                return(client);
            });
        }
示例#14
0
        public ActionResult ValidateAddress(string street1, string street2, string city, string state, string postalCode)
        {
            if (!string.IsNullOrEmpty(street1) && !string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(state)
                //&& (Request.UrlReferrer.Host == Request.Url.Host)     //Uncommenting this will make sure your validate function only works on your site
                )
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(
                    ConfigurationManager.AppSettings["SmartyStreets.AuthId"],
                    ConfigurationManager.AppSettings["SmartyStreets.AuthToken"]);
                var client = builder.BuildUsStreetApiClient();

                SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup();
                lookup.Street  = street1;
                lookup.Street2 = street2;
                lookup.City    = city;
                lookup.State   = state;
                lookup.ZipCode = postalCode;
                client.Send(lookup);
                return(Json(lookup.Result.Select(x => new { Street1 = x.DeliveryLine1, Street2 = x.DeliveryLine2, City = x.Components.CityName, State = x.Components.State, PostalCode = x.Components.ZipCode }), JsonRequestBehavior.AllowGet));
            }
            return(Json(new object[0], JsonRequestBehavior.AllowGet));
        }
示例#15
0
文件: Startup.cs 项目: koms122/Corked
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
                                                         //Use this when publishing to Azure
                                                         options.UseInMemoryDatabase("Default"));

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



            // Add application services.
            services.AddTransient <IEmailSender>((iServiceProvider) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey")));

            //environment, merchantid, publickey, privatekey has to be in the same order!!!
            services.AddTransient <Braintree.IBraintreeGateway>((iServiceProvider) => new Braintree.BraintreeGateway(
                                                                    Configuration.GetValue <string>("Braintree.Environment"),
                                                                    Configuration.GetValue <string>("Braintree.MerchantId"),
                                                                    Configuration.GetValue <string>("Braintree.PublicKey"),
                                                                    Configuration.GetValue <string>("Braintree.PrivateKey")
                                                                    ));

            services.AddTransient <System.Data.SqlClient.SqlConnection>((x) => new System.Data.SqlClient.SqlConnection(Configuration.GetConnectionString("DefaultConnection")));

            services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) =>
            {
                SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets.AuthId"),
                    Configuration.GetValue <string>("SmartyStreets.Token")
                    );
                return(clientBuilder.BuildUsStreetApiClient());
            });

            services.AddMvc();
        }
        public ActionResult ValidateAddress(Address a)
        {
            if (ModelState.IsValid)
            {
                string smartyStreetsAuthID          = ConfigurationManager.AppSettings["SmartyStreets.AuthID"];
                string smartyStreetsAuthToken       = ConfigurationManager.AppSettings["SmartyStreets.AuthToken"];
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(smartyStreetsAuthID, smartyStreetsAuthToken);
                var smartyClient = builder.BuildUsStreetApiClient();

                SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup();
                lookup.City    = a.Locality ?? "";
                lookup.State   = a.Region ?? "";
                lookup.Street  = a.Street1 ?? "";
                lookup.Street2 = a.Street2 ?? "";
                lookup.ZipCode = a.PostalCode ?? "";

                smartyClient.Send(lookup);
                return(Json(lookup.Result.Select(x => new
                {
                    City = x.Components.CityName,
                    Street = x.DeliveryLine1,
                    Street2 = x.DeliveryLine2,
                    State = x.Components.State,
                    ZipCode = x.Components.ZipCode + "-" + x.Components.Plus4Code
                }), JsonRequestBehavior.AllowGet));
            }
            else
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                return(Json(new
                {
                    Message = ModelState.FirstOrDefault(x => x.Value.Errors.Any()).Value.Errors
                              .FirstOrDefault()
                }, JsonRequestBehavior.AllowGet));
            }
        }
示例#17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Configuration.GetConnectionString("burgerStore");
            string burgerStoreConnectionString = Configuration.GetConnectionString("burgerStore");


            services.AddDbContext <BurgerStoreDbContext>(opt => opt.UseSqlServer(burgerStoreConnectionString));



            services.AddIdentity <BurgerStoreUser, IdentityRole>()
            .AddEntityFrameworkStores <BurgerStoreDbContext>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = true;
                options.Password.RequiredLength         = 8;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequireLowercase       = false;
                options.Password.RequiredUniqueChars    = 6;

                // Lockout settings
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(30);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings
                options.User.RequireUniqueEmail = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromMinutes(30);
                // If the LoginPath isn't set, ASP.NET Core defaults
                // the path to /Account/Login.
                options.LoginPath = "/Account/Login";
                // If the AccessDeniedPath isn't set, ASP.NET Core defaults
                // the path to /Account/AccessDenied.
                options.AccessDeniedPath  = "/Account/AccessDenied";
                options.SlidingExpiration = true;
            });


            services.AddMvc();
            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });
            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });

            //remember to add keys to secrets file
            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]);
                return(builder.BuildUsStreetApiClient());
            });
        }
示例#18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string tcpConnectionString = Configuration.GetConnectionString("TCP");

            services.AddDbContext <Models.TCPDbContext>(opt => opt.UseSqlServer(tcpConnectionString));


            services.AddIdentity <TCPUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
            })
            .AddEntityFrameworkStores <Models.TCPDbContext>()
            .AddDefaultTokenProviders();



            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromMinutes(30);
                // If the LoginPath isn't set, ASP.NET Core defaults
                // the path to /Account/Login.
                options.LoginPath = "/Account/Login";
                // If the AccessDeniedPath isn't set, ASP.NET Core defaults
                // the path to /Account/AccessDenied.
                options.AccessDeniedPath  = "/Account/AccessDenied";
                options.SlidingExpiration = true;
            });

            /*
             * services.AddTransient<SendGrid.SendGridClient>((x) =>
             * {
             *  return new SendGrid.SendGridClient("api_key_here");
             * });
             *
             * services.AddTransient<SendGrid.SendGridClient>((x) =>
             * {
             *  return new SendGrid.SendGridClient(Configuration["sendgrid"]);
             * });
             */
            services
            .AddMvc()
            .AddJsonOptions(
                o =>
            {
                o.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); });


            services.AddTransient((x) => {
                return(new Braintree.BraintreeGateway(
                           Configuration["BraintreeEnvironment"],
                           Configuration["BraintreeMerchantId"],
                           Configuration["BraintreePublicKey"],
                           Configuration["BraintreePrivateKey"]));
            });

            services.AddTransient((x) =>
            {
                SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]);
                return(builder.BuildUsStreetApiClient());
            });
        }
        public SmartyStreetsService(string authId, string authToken)
        {
            SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(authId, authToken);

            _client = builder.BuildUsStreetApiClient();
        }