Ejemplo n.º 1
0
 public ActionResult <LoginResponseDTO> Post([FromBody] LoginRequestDTO dto)
 {
     try
     {
         User user = _userBusiness.Authenticate(dto.username, dto.password);
         return(Ok(new LoginResponseDTO {
             userId = user.Id
         }));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 2
0
        //[Route("__account/signin")]
        public async Task <ActionResult> SignIn(SigninViewModel model)
        {
            InitializeViewModel(model);

            if (!ModelState.IsValid)
            {
                model.ErrorDisplay.AddMessages(ModelState);
                model.ErrorDisplay.ShowError("Please correct the following:");
                return(View(model));
            }

            var userBus = new UserBusiness();
            var user    = await userBus.Authenticate(model.Email, model.Password,
                                                     ControllerHelper.GetCurrentDomainPrefix(HttpContext.Request),
                                                     "kavadocs.com");

            if (user == null)
            {
                model.ErrorDisplay.ShowError(userBus.ErrorMessage);
                return(View(model));
            }

            var identity = AppUser.GetClaimsIdentityFromUser(user);


            // Set cookie and attach claims
            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                          new ClaimsPrincipal(identity), new AuthenticationProperties
            {
                IsPersistent = true,
                AllowRefresh = true,
                ExpiresUtc   = DateTime.UtcNow.AddDays(2)
            });


            if (!string.IsNullOrEmpty(model.ReturnUrl))
            {
                return(Redirect(model.ReturnUrl));
            }



            return(Redirect("~/"));
        }
Ejemplo n.º 3
0
 public UserEntity Authenticate(string email, string password, AuthOrigin origin)
 {
     return(UserBusiness.Authenticate(email, password, origin));
 }