/// <summary> /// Login by UserName and Password and return ClaimsIdentity representing the logged in user. /// </summary> /// <param name="request">Instance of LoginRequest</param> /// <returns>Instance of LoginResponse</returns> public async Task <LoginResponse> LoginAsync(LoginRequest request) { LoginResponse response = new LoginResponse(); try { AspNetUser user = await this.UserManager.FindAsync(request.UserName, request.Password); IdentityResult validation = await this.UserManager.PasswordValidator.ValidateAsync(request.Password); if (validation.Succeeded) { ClaimsIdentity identity = await this.UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); response.ClaimIdentity = identity.ConvertToClaimIdentityView(); response.Success = true; } else { response.AddErrors(validation.Errors); } } catch (Exception e) { response.Success = false; response.Errors.Add(e.Message); } return(response); }
/// <summary> /// Login by UserName and Password and return ClaimsIdentity representing the logged in user. /// </summary> /// <param name="request">Instance of LoginRequest</param> /// <returns>Instance of LoginResponse</returns> public async Task<LoginResponse> LoginAsync(LoginRequest request) { LoginResponse response = new LoginResponse(); try { AspNetUser user = await this.UserManager.FindAsync(request.UserName, request.Password); IdentityResult validation = await this.UserManager.PasswordValidator.ValidateAsync(request.Password); if (validation.Succeeded) { ClaimsIdentity identity = await this.UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); response.ClaimIdentity = identity.ConvertToClaimIdentityView(); response.Success = true; } else { response.AddErrors(validation.Errors); } } catch (Exception e) { response.Success = false; response.Errors.Add(e.Message); } return response; }