public async Task <ApiResponseDto> ConfirmEmail(ConfirmEmailViewModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.ConfirmEmail(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto <LoginResponseModel> > Login(LoginInputModel parameters) { ApiResponseDto <LoginResponseModel> apiResponse = await _accountApiClient.Login(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> UpdateUser(UserInfoDto userInfo) { ApiResponseDto apiResponse = await _authorizeApi.UpdateUser(userInfo); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> UpdatePassword(UpdatePasswordViewModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.UpdatePassword(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public ApiResponseDto <LoginRequestDto> Login(LoginRequestDto requestDto) { try { var user = BUser.LoginResponse(requestDto); if (user != null) { LoginRequestDto loginResponse = new LoginRequestDto() { UserName = user.UserName, Password = user.Password }; return(ApiResponseDto <LoginRequestDto> .SuccessResponse(loginResponse, "basarili")); } return(ApiResponseDto <LoginRequestDto> .FailedResponse("basarisiz")); } catch { return(ApiResponseDto <LoginRequestDto> .FailedResponse("basarisiz")); } }
public async Task <ApiResponseDto> Logout(string returnUrl = null) { ApiResponseDto apiResponse = await _accountApiClient.Logout(returnUrl); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
/// <summary> /// Process the API response by updating this form with the appropriate values. /// </summary> /// <param name="response">DTO representing the API response data.</param> public void ProcessResponse(ApiResponseDto response) { lblResponseCode.Text = $"{(int)response.StatusCode} - {response.StatusCode}"; lblMediaType.Text = response.MediaType; switch (response.MediaType) { case "application/zip": { txtResponseData.Text = $"Binary file {response.FileName}"; break; } case "application/xml": case "text/html": { txtResponseData.Text = response.Xml; break; } default: { txtResponseData.Text = Resources.ResponseForm_ProcessResponse_Unexpected_Media_Type; break; } } }
public async Task <ApiResponseDto <LoginResponseModel> > Register(RegisterViewModel parameters) { ApiResponseDto <LoginResponseModel> apiResponse = await _authorizeApi.Register(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> Logout() { ApiResponseDto apiResponse = await _authorizeApi.Logout(); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> LoginWithRecoveryCode(LoginWithRecoveryCodeInputModel parameters) { ApiResponseDto apiResponse = await _accountApiClient.LoginWithRecoveryCode(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
/// <summary> /// Creates the response based on the request method. /// </summary> /// <remarks> /// Based on http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/09/implementing-requirehttps-with-asp-net-web-api.aspx /// </remarks> /// <param name="request">The request.</param> /// <returns>The response based on the request method.</returns> private HttpResponseMessage CreateResponse(HttpRequestMessage request) { var uriBuilder = new UriBuilder(request.RequestUri); uriBuilder.Scheme = Uri.UriSchemeHttps; uriBuilder.Port = _httpsPort; // Create errorDto var errorDto = new ErrorDto { Title = $"HTTPS is required. The resource can be found at {uriBuilder.Uri.AbsoluteUri}", ErrorReference = Guid.Empty.ToString(), }; // Create api response var apiResponseDto = new ApiResponseDto <object> { Error = errorDto, Result = null, }; // Create http response HttpResponseMessage response = request.CreateResponse(HttpStatusCode.Forbidden, apiResponseDto); return(response); }
public async Task <ApiResponseDto> Logout() { #if ServerSideBlazor List <string> cookies = null; if (_httpClient.DefaultRequestHeaders.TryGetValues("Cookie", out IEnumerable <string> cookieEntries)) { cookies = cookieEntries.ToList(); } #endif HttpResponseMessage response = await _httpClient.GetAsync("api/Account/Logout"); ApiResponseDto apiResponse = JsonConvert.DeserializeObject <ApiResponseDto>(await response.Content.ReadAsStringAsync()); #if ServerSideBlazor if (apiResponse.StatusCode == Status200OK && cookies != null && cookies.Any()) { _httpClient.DefaultRequestHeaders.Remove("Cookie"); foreach (var cookie in cookies[0].Split(';')) { var cookieParts = cookie.Split('='); await _jsRuntime.InvokeVoidAsync("jsInterops.removeCookie", cookieParts[0]); } } #endif return(apiResponse); }
public ApiResponseDto <List <BookAuthorDto> > GetBook() { var book = _bookService.GetBook(); List <BookAuthorDto> bookAuthorDtoList = new List <BookAuthorDto>(); BookAuthorDto bookAuthorDtos; if (book != null) { foreach (var item in book) { var author = BAuthor.GetAuthorByID(item.FK_AuthorID); bookAuthorDtos = new BookAuthorDto() { ID = item.ID, BookName = item.Name, PublishedYear = item.PublishedYear, Cover = item.Cover, AuthorName = author.Name }; bookAuthorDtoList.Add(bookAuthorDtos); } return(ApiResponseDto <List <BookAuthorDto> > .SuccessResponse(bookAuthorDtoList, "basarili")); } return(ApiResponseDto <List <BookAuthorDto> > .FailedResponse("basarisiz")); }
public async Task <ApiResponseDto> ConfirmEmail(ConfirmEmailDto confirmEmailParameters) { ApiResponseDto apiResponse = await _authorizeApi.ConfirmEmail(confirmEmailParameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> LoginWith2fa(LoginWith2faInputModel parameters) { ApiResponseDto apiResponse = await _authorizeApi.LoginWith2fa(parameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> ResetPassword(ResetPasswordDto resetPasswordParameters) { ApiResponseDto apiResponse = await _authorizeApi.ResetPassword(resetPasswordParameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <ApiResponseDto> Login(LoginDto loginParameters) { ApiResponseDto apiResponse = await _authorizeApi.Login(loginParameters); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
/// <summary> /// Processes an API response by populating an API response data object. /// </summary> /// <param name="response">The HTTP response message received from the API.</param> /// <returns> /// An API response data object. /// </returns> private static async Task <ApiResponseDto> ProcessApiResponse(HttpResponseMessage response) { var apiResponseDto = new ApiResponseDto { MediaType = response.Content.Headers.ContentType.MediaType, StatusCode = response.StatusCode }; switch (apiResponseDto.MediaType) { case "application/zip": { apiResponseDto.BinaryData = await response.Content.ReadAsByteArrayAsync(); apiResponseDto.FileName = response.Content.Headers.ContentDisposition.FileName; break; } default: { apiResponseDto.Xml = await response.Content.ReadAsStringAsync(); break; } } return(apiResponseDto); }
async Task PostLoginProcess(ApiResponseDto response) { if (response.IsSuccessStatusCode) { if (navigationManager.IsWebAssembly()) { if (string.IsNullOrEmpty(ReturnUrl)) { var userProfile = await appState.GetUserProfile(); navigateTo = navigationManager.BaseUri + (!string.IsNullOrEmpty(userProfile?.LastPageVisited) ? userProfile?.LastPageVisited : "/dashboard"); } else { navigateTo = ReturnUrl; } navigationManager.NavigateTo(navigateTo); } else { RedirectInProgress = true; } LoginSuccess = true; } else { viewNotifier.Show(response.Message, ViewNotifierType.Error, L["LoginFailed"]); } }
public async Task <ApiResponseDto> UpdateUser(UserViewModel userViewModel) { ApiResponseDto apiResponse = await _accountApiClient.UpdateUser(userViewModel); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public async Task <UserInfoDto> GetUser() { ApiResponseDto apiResponse = await _httpClient.GetJsonAsync <ApiResponseDto>("api/Account/GetUser"); UserInfoDto user = JsonConvert.DeserializeObject <UserInfoDto>(apiResponse.Result.ToString()); return(user); }
private static HttpResponseMessage WrapApiResponse(HttpRequestMessage request, HttpResponseMessage response) { object content; ErrorDto errorDto = null; // Extract content object. Check if it contains an HttpError, if yes populate the errorDto object. // In case of IdentityResult errors returned by BaseApiController.GetResultWithErrors(), content is HttpError if (response.TryGetContentValue(out content) && !response.IsSuccessStatusCode) { var httpError = content as HttpError; if (httpError != null) { content = null; // Since have an error, no need to return any content. var errors = httpError.Message.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .ToList(); errorDto = new ErrorDto { Title = Errors.ValidationErrorMessage, Messages = errors, ErrorReference = Guid.Empty.ToString(), }; } else if ((int)response.StatusCode == 429 && // Too many requests. HttpStatusCode enum is unavailable at the moment content is string && ((string)content).StartsWith("API calls quota exceeded!")) { errorDto = new ErrorDto { Title = Errors.TooManyRequestErrorTitle, Messages = new List <string> { (string)content }, ErrorReference = Guid.Empty.ToString(), }; content = null; } } // Check if the response contains ErrorDto, if yes populate the errorDto object. // In case of ModelValidation errors, content is ErrorDto. if (content is ErrorDto) { errorDto = content as ErrorDto; content = null; } // Wrap the response/result var apiResponseDto = new ApiResponseDto <object> { Error = errorDto, Result = content, }; // Create Http response with the wrapped result HttpResponseMessage wrappedResponse = CreateHttpResponseMessage(request, response, apiResponseDto); return(wrappedResponse); }
public async Task <ApiResponseDto> Logout() { _appState.UserProfile = null; ApiResponseDto apiResponse = await _authorizeApi.Logout(); _userInfoCache = null; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); return(apiResponse); }
public override void OnException(HttpActionExecutedContext context) { var responseMessage = new HttpResponseMessage(HttpStatusCode.OK); var model = new ApiResponseDto() { Success = false, Error = context.Exception.Message }) responseMessage.Content = new JsonContent(model); context.Response = responseMessage; }
public async Task <UserInfoDto> GetUser() { HttpResponseMessage response = await _httpClient.GetAsync("api/Account/GetUser"); ApiResponseDto apiResponse = JsonConvert.DeserializeObject <ApiResponseDto>(await response.Content.ReadAsStringAsync()); UserInfoDto user = JsonConvert.DeserializeObject <UserInfoDto>(apiResponse.Result.ToString()); return(user); }
private static Task DefaultContextResponseSend(HttpContext context, ApiResponseDto apiResponseDto) { context.Response.ContentType = "application/json"; var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); string result = JsonConvert.SerializeObject(apiResponseDto, serializerSettings); return(context.Response.WriteAsync(result)); }
public ApiResponseDto <List <UserDto> > GetUser() { var user = BUser.GetUserInfo(); if (user != null) { return(ApiResponseDto <List <UserDto> > .SuccessResponse(user, "basarili")); } return(ApiResponseDto <List <UserDto> > .FailedResponse("basarisiz")); }
public ApiResponseDto <List <AuthorDto> > GetAuthor() { var author = BAuthor.GetAuthor(); if (author == null) { return(ApiResponseDto <List <AuthorDto> > .FailedResponse("basarisiz")); } return(ApiResponseDto <List <AuthorDto> > .SuccessResponse(author, "basarili")); }
public ApiResponseDto <BookDto> NewBook(BookDto newBookdto) { if (newBookdto == null) { return(ApiResponseDto <BookDto> .FailedResponse("basarisiz")); } var book = _bookService.NewBook(newBookdto); return(ApiResponseDto <BookDto> .SuccessResponse(book, "basarili")); }
public ApiResponseDto <UserBookDto> AddtoMyLib(UserBookDto user) { if (user == null) { return(ApiResponseDto <UserBookDto> .FailedResponse("basarisiz")); } var book = _bookService.AddtoMyLib(user.FK_BookID, user.FK_UserID); return(ApiResponseDto <UserBookDto> .SuccessResponse(book, "basarili")); }