public async Task <JwtView> Login(LoginAccountView view) { User user = _mapper.Map <LoginAccountView, User>(view); JwtView token = _jwtProvider.CreateToken(user); return(token); }
public async Task <JwtView> LogIn(LogInRequest logInRequest) { User user = await UserValidation(logInRequest); if (user != null) { JwtView view = _jwtHelper.CreateToken(user); return(view); } throw new UserNotFoundException("Не правильные данные"); }
public JwtView CreateToken(User user) { ClaimsIdentity claims = GetClaimsIdentity(user); JwtSecurityToken jwt = GetToken(claims); string stringToken = new JwtSecurityTokenHandler().WriteToken(jwt); JwtView result = new JwtView() { AccessToken = stringToken }; return(result); }
public async Task <JwtView> Login(LoginViewModel model) { SignInResult result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (result.Succeeded) { User appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email); JwtView jwtModel = await GenerateJwtToken(model.Email, appUser); return(jwtModel); } throw new ApplicationException("Incorrect login or password. User : " + model.Email); }
public async Task <IActionResult> Login([FromBody] LoginAccountView view) { JwtView token = await _accountService.Login(view); return(Ok(token)); }