public async Task <LoginAccountResponseView> Login(LoginAccountView model) { var user = await _userManager.FindByNameAsync(model.UserName); if (user == null) { throw new CustomServiceException("Player does not exist."); } var isValidPassword = await _userManager.CheckPasswordAsync(user, model.Password); if (!isValidPassword) { throw new CustomServiceException("Invalid username or password."); } var email = (!string.IsNullOrEmpty(model.Email)) ? model.Email : ""; string token = await _jwtProvider.GenerateJwtToken(email, user); var result = new LoginAccountResponseView() { AccessToken = token, UserName = user.UserName, PlayerId = user.Id }; return(result); }
public async Task <IActionResult> Login(LoginAccountView model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.Email); if (user != null) { // проверяем, подтвержден ли email if (!await _userManager.IsEmailConfirmedAsync(user)) { ModelState.AddModelError(string.Empty, "Вы не подтвердили свой email"); return(Ok(model)); } } var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Неправильный логин и (или) пароль"); } } return(Ok(model)); }
public async Task <JwtView> Login(LoginAccountView view) { User user = _mapper.Map <LoginAccountView, User>(view); JwtView token = _jwtProvider.CreateToken(user); return(token); }
public async Task <GenericResponseView <LoginAccountResponseView> > Login([FromBody] LoginAccountView model) { var response = new GenericResponseView <LoginAccountResponseView>(); response.Model = await _accountService.Login(model); return(response); }
public async Task <object> Login([FromBody] LoginAccountView model) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (result.Succeeded) { var appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email); return(GenerateJwtToken(model.Email, appUser)); } throw new ApplicationException("Invalid_Login_Attemp"); }
public async Task <LoginAccountResponseView> Login(LoginAccountView model) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (!result.Succeeded) { throw new CustomServiceException("Invalid Login or password"); } var user = await _userManager.FindByEmailAsync(model.Email); var encodedJwt = await _jwtProvider.GenerateJwtToken(user); var response = new LoginAccountResponseView() { Token = encodedJwt }; return(response); }
public async Task <LoginAccountResponseView> Login(LoginAccountView model) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (!result.Succeeded) { throw new CustomServiceException("Invalid login attempt"); } var user = await _userManager.FindByEmailAsync(model.Email); var token = _jwtTokentHelper.GenerateJwtToken(model.Email, user); var response = new LoginAccountResponseView() { Token = token }; return(response); }
public async Task <LoginAccountResponseView> Login(LoginAccountView model) { var result = await _userManager.FindByNameAsync(model.Name); var identityResult = await _signInManager.UserManager.CheckPasswordAsync(result, model.Password); if (!identityResult) { throw new ValidationException("Wrong login or password!"); } var token = _jwtTokentHelper.GenerateJwtToken(result); var response = new LoginAccountResponseView() { UserId = result.Id, Token = token }; return(response); }
public async Task <IActionResult> Login([FromBody] LoginAccountView model) { var response = await _accountService.Login(model); return(Ok(response)); }
public async Task <IActionResult> Login([FromBody] LoginAccountView model) { return(await Execute(() => _accountService.Login(model))); }
public async Task <IActionResult> Login([FromBody] LoginAccountView view) { JwtView token = await _accountService.Login(view); return(Ok(token)); }