Align .editorconfig files Move Controller logic to DMO classes GlobalVars.AppSettings = Models.AppSettings.GetFromConfigurationManager(); Question EditorConfig Project level editorconfig Format White Spaces AppSetting when EnvironmentVariable not set Corrective Actions Tests Schedule Actions Tests DMO Tests Controller Tests Get ready to use VSCode IDE
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using Fab2ApprovalSystem.Models;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Fab2ApprovalSystem.DMO;
|
|
|
|
public class AccountDMO {
|
|
|
|
public static async Task<LoginResult> LoginAsync(HttpClient httpClient, LoginModel loginModel) {
|
|
LoginResult result;
|
|
|
|
HttpRequestMessage request = new(HttpMethod.Post, "auth/login");
|
|
|
|
AuthAttempt authAttempt = loginModel is null ? null : new AuthAttempt() {
|
|
LoginID = loginModel.LoginID,
|
|
Password = loginModel.Password
|
|
};
|
|
|
|
string json = authAttempt is null ? "{}" : JsonConvert.SerializeObject(authAttempt);
|
|
|
|
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(request);
|
|
|
|
if (!httpResponseMessage.IsSuccessStatusCode)
|
|
throw new Exception($"The authentication API failed, because {httpResponseMessage.ReasonPhrase}");
|
|
|
|
string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
|
result = JsonConvert.DeserializeObject<LoginResult>(responseContent);
|
|
return result;
|
|
}
|
|
|
|
public static async Task<LoginResult> ExternalAuthSetupAsync(HttpClient httpClient, AuthAttempt authAttempt) {
|
|
LoginResult result;
|
|
|
|
HttpRequestMessage request = new(HttpMethod.Post, "auth/refresh");
|
|
|
|
string json = authAttempt is null ? "{}" : JsonConvert.SerializeObject(authAttempt);
|
|
|
|
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(request);
|
|
|
|
if (!httpResponseMessage.IsSuccessStatusCode)
|
|
throw new Exception($"The authentication API failed, because {httpResponseMessage.ReasonPhrase}");
|
|
|
|
string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
|
result = JsonConvert.DeserializeObject<LoginResult>(responseContent);
|
|
return result;
|
|
}
|
|
|
|
} |