// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // AspNetLib による設定を追加
            AspNetLib.ConfigureServices(StartupHelper, services);

            // 基本的な設定を追加
            StartupHelper.ConfigureServices(services);

            // リクエスト数制限機能を追加
            services.AddHttpRequestRateLimiter <HttpRequestRateLimiterHashKeys.SrcIPAddress>(_ => { });

            //// Cookie 認証機能を追加
            EasyCookieAuth.LoginFormMessage.TrySet("ログインが必要です。");
            EasyCookieAuth.AuthenticationPasswordValidator = StartupHelper.SimpleBasicAuthenticationPasswordValidator;
            EasyCookieAuth.ConfigureServices(services, !StartupHelper.ServerOptions.AutomaticRedirectToHttpsIfPossible);

            // LogBrowesr 機能を設定
            AspNetLib.SetupLogBrowser(services, new LogBrowserOptions(PP.Combine(Env.AppRootDir, "Log"), "DaemonCenter Server 本体ログブラウザ"));

            // MVC 機能を追加
            services.AddControllersWithViews()
            .ConfigureMvcWithAspNetLib(AspNetLib);

            this.DaemonCenterServer = new Server();

            // シングルトンサービスの注入
            services.AddSingleton(this.DaemonCenterServer);

            // Daemon Center RPC 独立ポートサーバーの作成
            this.DaemonCenterRpcHost = new DaemonCenterServerRpcHttpHost(this.DaemonCenterServer);

            // 全ページ共通コンテキストの注入
            services.AddScoped <PageContext>();
        }
Example #2
0
    public async Task <IActionResult> Index(EasyCookieAuthModel model)
    {
        model.Username = model.Username._NonNullTrim();
        model.Password = model.Password._NonNullTrim();

        if (model.Username._IsEmpty() || model.Password._IsEmpty())
        {
            model.ErrorStr = "ユーザー名とパスワードを入力してください。";
            return(View(model));
        }

        if (EasyCookieAuth.AuthenticationPasswordValidator == null || (await EasyCookieAuth.AuthenticationPasswordValidator(model.Username, model.Password)) == false)
        {
            model.ErrorStr = "ユーザー名またはパスワードが間違っています。確認をして再度入力をしてください。";
            Con.WriteError($"EasyCookieAuthController: Login failed. Username = {model.Username}");
            return(View(model));
        }

        Claim[] claims = new[]
        {
            new Claim(ClaimTypes.Name, model.Username),
        };

        ClaimsIdentity  identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
        ClaimsPrincipal principal = new ClaimsPrincipal(identity);

        AuthenticationProperties authProperties = new AuthenticationProperties
        {
            AllowRefresh = true,
            ExpiresUtc   = DateTimeOffset.UtcNow.Add(EasyCookieAuth.CookieLifetime),
            IsPersistent = true,
        };

        await HttpContext.SignInAsync(principal, authProperties);

        Con.WriteError($"EasyCookieAuthController: Logged in. Username = {model.Username}");

        if (model.ReturnUrl._IsEmpty())
        {
            return(Redirect("/"));
        }
        else
        {
            return(Redirect(model.ReturnUrl));
        }
    }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // AspNetLib による設定を追加
            AspNetLib.ConfigureServices(StartupHelper, services);

            // 基本的な設定を追加
            StartupHelper.ConfigureServices(services);

            // リクエスト数制限機能を追加
            services.AddHttpRequestRateLimiter <HttpRequestRateLimiterHashKeys.SrcIPAddress>(_ => { });

            //// Cookie 認証機能を追加
            EasyCookieAuth.LoginFormMessage.TrySet("ログインが必要です。");
            EasyCookieAuth.AuthenticationPasswordValidator = StartupHelper.SimpleBasicAuthenticationPasswordValidator;
            EasyCookieAuth.ConfigureServices(services, !StartupHelper.ServerOptions.AutomaticRedirectToHttpsIfPossible);

            // MVC 機能を追加
            services.AddControllersWithViews()
            .ConfigureMvcWithAspNetLib(AspNetLib);

            //// シングルトンサービスの注入
            services.AddSingleton(new FastReader());
        }