public AccountController(ApplicationHelper appHelper, GoogleAuthHelper googleAuthHelper,
     GetHabitsIdentity identityContext, UserManager<GetHabitsUser> userManager, ILoggerFactory loggerFactory)
 {
     _identityContext = identityContext;
     _userMng = userManager;
     _googleAuthHelper = googleAuthHelper;
     _logger = loggerFactory.CreateLogger<AccountController>();
     _appHelper = appHelper;
 }
        public HabitService(GetHabitsContext dbContext, IHttpContextAccessor httpContextAccessor, ILoggerFactory loggerFactory, ApplicationHelper appHelper)
        {
            _dbContext = dbContext;
            _httpContext = httpContextAccessor.HttpContext;
            _logger = loggerFactory.CreateLogger<HabitService>();
            _appHelper = appHelper;

            var claimUserId = _httpContext.User.FindFirst(appHelper.TypeClaimUserId);

            if (claimUserId == null)
            {
                _logger.LogCritical("HttpContext doesn't contain UserId claim");
                _userId = Guid.NewGuid().ToString();
            }
            else
            {
                _userId = claimUserId.Value;
            }
        }
Example #3
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
            GetHabitsContext context, GetHabitsIdentity identContext, GoogleAuthHelper googleAuthHelper, ApplicationHelper appHelper)
        {
            if (env.IsProduction())
            {
                loggerFactory.AddConsole(LogLevel.Verbose);
            }
            else
            {
                loggerFactory.AddConsole(LogLevel.Verbose);
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage(opt => opt.EnableAll());
            }

            app.UseStaticFiles();

            //TODO do checks
            context.Database.Migrate();
            identContext.Database.Migrate();

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
                options.AutomaticChallenge = true;
                options.LoginPath = new PathString("/account/login");
                options.LogoutPath = new PathString("/account/logoff");
                options.AuthenticationScheme = appHelper.DefaultAuthScheme;
            });

            app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = false;
                options.AuthenticationScheme = appHelper.TempAuthScheme;
            });

            var clientId = Configuration.GetSection("Authentication:Google:ClientId").Value;
            var clientSecret = Configuration.GetSection("Authentication:Google:ClientSecret").Value;

            app.UseGoogleAuthentication(options =>
            {
                options.ClientId = clientId;
                options.ClientSecret = clientSecret;
                options.AuthenticationScheme = googleAuthHelper.ProviderName;
                options.AutomaticAuthenticate = false;
                options.SignInScheme = appHelper.TempAuthScheme;

                options.Events = new OAuthEvents()
                {
                    OnRemoteError = async errorContext =>
                    {
                        var error = errorContext.Error;
                        errorContext.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.UrlEncode(errorContext.Error.Message));
                        errorContext.HandleResponse();
                        await Task.FromResult(0);
                    }
                };
            });

            var localizationOptions = new RequestLocalizationOptions()
            {
                SupportedCultures = new List<CultureInfo>
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("ru-RU")
                },
                SupportedUICultures = new List<CultureInfo>
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("ru-RU")
                }
            };

            localizationOptions.RequestCultureProviders.Insert(0, new FirstAddressSegmentCultureProvider(appHelper));

            app.UseRequestLocalization(localizationOptions, new RequestCulture("ru-RU"));

            app.UseIISPlatformHandler();

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.MapRoute("applicationRoute", "app/{*all}", new { controller = "App", action = "Index"});
                routeBuilder.MapRoute("localizedRoute", "{langname}/{controller=Home}/{action=Index}/{id?}", null, new { langname = new RequestLocalizedRouteConstraint(appHelper.LangNameAndCultureNameCorresponding.Keys) });
                routeBuilder.MapRoute("unLocalizedRoute", "{*allPath}", new { controller = "Localize", action = "UnLocalizedRequest" }, new { allPath = new RequestUnLocalizedRouteConstraint(appHelper.LangNameAndCultureNameCorresponding.Keys) });
            });
        }
 public HomeController(ApplicationHelper appHelper)
 {
     _appHelper = appHelper;
 }
 public FirstAddressSegmentCultureProvider(ApplicationHelper appHelper)
 {
     _appHelper = appHelper;
 }
 public LocalizeController(ApplicationHelper appHelper)
 {
     _appHelper = appHelper;
 }