public async Task <IActionResult> Register(RegisterViewModel registerViewModel) { var user = _userService.FindUser( _mapper.Map <FindUserDto>(registerViewModel)); var resultVm = new UserViewModel(); if (user == null) { user = _userService.CreateUser( _mapper.Map <CreateUserDto>(registerViewModel)); await HttpContext.Authenticate(user); _mapper.Map(user, resultVm); resultVm.IsLoggedIn = true; await _mediator.Send(new CreateDefaultCategoriesCommand { UserId = user.Id }); } else { resultVm.IsLoggedIn = false; } return(Ok(resultVm)); }
public async Task <IActionResult> Login(LoginViewModel loginViewModel) { var user = _userService.FindUser( _mapper.Map <FindUserByPasswordDto>(loginViewModel)); var resultVm = new UserViewModel(); if (user != null) { await HttpContext.Authenticate(user); _mapper.Map(user, resultVm); resultVm.IsLoggedIn = true; } else { resultVm.IsLoggedIn = false; } return(Ok(resultVm)); }
public static async Task <ClaimsIdentity> GetExternalIdentity(this HttpContext context) { return(await context.Authenticate(Microsoft.Owin.Security.Forms.FormsAuthenticationDefaults.ExternalAuthenticationType)); }