コード例 #1
0
        public async Task <IActionResult> Login([FromBody] LoginRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.SelectMany(e => e.Value.Errors.Select(e => e.ErrorMessage))));
            }
            if (model == null)
            {
                return(BadRequest("Invalid client request"));
            }

            var loginCommand  = new LoginUser.Command(model);
            var loginResponse = await _mediator.Send(loginCommand);

            if (!loginResponse.Success)
            {
                return(BadRequest(loginResponse.ErrorMessages));
            }
            //HttpContext.Response.Cookies.Append(".AspNetCore.Application.Id", authResponse.Token,
            //  new CookieOptions
            //  {
            //      //MaxAge = TimeSpan.FromMinutes(2)
            //      //Expires = DateTime.UtcNow.AddMinutes(2)
            //  }); ;
            //HttpContext.Response.Cookies.Append(".AspNetCore.Application.Id-refresh", authResponse.RefreshToken,
            //new CookieOptions
            //{
            //    MaxAge = TimeSpan.FromHours(48)
            //});
            //HttpContext.Response.Cookies.Append("User-email", model.Email,
            //new CookieOptions
            //{
            //});
            return(Ok(new
            {
                loginResponse.Token,
                loginResponse.RefreshToken
            }));
        }
コード例 #2
0
        public async Task <IActionResult> Login([FromBody] LoginRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.SelectMany(e => e.Value.Errors.Select(e => e.ErrorMessage))));
            }
            if (model == null)
            {
                return(BadRequest("Invalid client request"));
            }

            var loginCommand  = new LoginUser.Command(model);
            var loginResponse = await _mediator.Send(loginCommand);

            if (!loginResponse.Success)
            {
                return(BadRequest(loginResponse.ErrorMessages));
            }
            return(Ok(new
            {
                loginResponse.Token,
                loginResponse.RefreshToken
            }));
        }