Exemplo n.º 1
0
        public IActionResult Login(LoginModel loginModel)
        {
            // TODO: Validations

            LoginUserRequest request = new LoginUserRequest()
            {
                User = new HomeInv.Common.Entities.HIUser()
                {
                    Email    = loginModel.Email,
                    Password = loginModel.Password
                }
            };

            var response = userService.LogIn(request);

            if (response.IsSuccessful)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, response.User.Email),
                    //new Claim("FullName", user.FullName),
                    //new Claim(ClaimTypes.Role, "Administrator"),
                };

                var claimsIdentity = new ClaimsIdentity(
                    claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                    AllowRefresh = true,

                    //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                    // The time at which the authentication ticket expires. A
                    // value set here overrides the ExpireTimeSpan option of
                    // CookieAuthenticationOptions set with AddCookie.

                    IsPersistent = loginModel.RememberMe,
                    // Whether the authentication session is persisted across
                    // multiple requests. When used with cookies, controls
                    // whether the cookie's lifetime is absolute (matching the
                    // lifetime of the authentication ticket) or session-based.

                    IssuedUtc = DateTimeOffset.UtcNow,
                    // The time at which the authentication ticket was issued.

                    //RedirectUri = <string>
                    // The full path or absolute URI to be used as an http
                    // redirect response value.
                };

                HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(claimsIdentity),
                    authProperties);

                //_logger.LogInformation("User {Email} logged in at {Time}.", user.Email, DateTime.UtcNow);

                return(RedirectToAction("Index", "Home"));
            }

            string errorMessage = "";

            response.Result.Messages.ForEach(m =>
            {
                errorMessage += m.Text + "\n";
            });
            ModelState.AddModelError(string.Empty, errorMessage);

            return(View(loginModel));
        }
 public ApiResponse Login( LoginModel model)
 {
     return CheckLogin(model);
 }
Exemplo n.º 3
0
        public IActionResult Login()
        {
            LoginModel loginModel = new LoginModel();

            return(View(loginModel));
        }