public IActionResult SignIn(SignInViewState?state)
        {
            var viewModel = new SignInUserVM
            {
                State = state == null ? null : state
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> SignIn(SignInUserVM signInUserModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(signInUserModel));
            }

            if (!_userRepo.ValidateCredentials(signInUserModel.Email, signInUserModel.Password, out UserModel userModel))
            {
                return(RedirectToAction(nameof(SignIn), new { state = SignInViewState.Failed }));
            }

            if (!userModel.IsActivated)
            {
                return(RedirectToAction(nameof(SignIn), new { state = SignInViewState.NotActive }));
            }

            var claims = new List <Claim>
            {
                new Claim(nameof(UserModel.Id), Convert.ToString(userModel.Id)),
                new Claim(ClaimTypes.Name, userModel.Name),
                new Claim(ClaimTypes.NameIdentifier, userModel.Email)
            };

            var userIdentity  = new ClaimsIdentity(claims, Constants.ReaderAuth);
            var userPrincipal = new ClaimsPrincipal(userIdentity);

            var authProps = new AuthenticationProperties();

            if (signInUserModel.RememberMe)
            {
                // it should expire after 14 days
                authProps.IsPersistent = true;
            }
            else
            {
                authProps.IsPersistent = false;
            }

            // default authentication scheme shall be used here to signin
            await HttpContext.SignInAsync(userPrincipal, authProps);

            return(RedirectToAction(
                       nameof(HomeController.Index),
                       nameof(HomeController).ControllerName()
                       ));
        }