This commit is contained in:
@@ -55,7 +55,7 @@ namespace AyaNovaQBI
|
|||||||
var res = await util.AuthenticateAsync(edUserName.Text, edPassword.Text);
|
var res = await util.AuthenticateAsync(edUserName.Text, edPassword.Text);
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
MessageBox.Show("AyaNova 8 SuperUser account login failed");
|
MessageBox.Show("Login failed");
|
||||||
btnLogin.Enabled = btnTest.Enabled = true;
|
btnLogin.Enabled = btnTest.Enabled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,27 +79,32 @@ namespace AyaNovaQBI
|
|||||||
dynamic creds = new JObject();
|
dynamic creds = new JObject();
|
||||||
creds.login = login;
|
creds.login = login;
|
||||||
creds.password = password;
|
creds.password = password;
|
||||||
|
var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + "auth");
|
||||||
ApiResponse a = await PostAsync("auth", creds.ToString());
|
requestMessage.Content = new StringContent(creds.ToString(), System.Text.Encoding.UTF8, "application/json");
|
||||||
|
HttpResponseMessage response = null;
|
||||||
if (a.HttpResponse.IsSuccessStatusCode)
|
try
|
||||||
{
|
{
|
||||||
JWT = a.ObjectResponse["data"]["token"].Value<string>();
|
response = await client.SendAsync(requestMessage);
|
||||||
//Must be *the* SuperUser to continue:
|
}
|
||||||
a = await GetAsync("user/amsu");
|
catch (HttpRequestException ex)
|
||||||
var IsSuperUser = a.ObjectResponse["data"].Value<bool>();
|
|
||||||
if (!IsSuperUser)
|
|
||||||
{
|
{
|
||||||
JWT = string.Empty;
|
var Err = ex.Message;
|
||||||
|
var InnerErr = "";
|
||||||
|
if (ex.InnerException != null)
|
||||||
|
InnerErr = ex.InnerException.Message;
|
||||||
return false;
|
return false;
|
||||||
|
// throw new Exception("POST error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace + "\r\nPOSTED OBJECT:\r\n" + postJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ApiResponse a = await PostAsync("auth", creds.ToString());
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var a= new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) };
|
||||||
|
JWT = a.ObjectResponse["data"]["token"].Value<string>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +212,7 @@ namespace AyaNovaQBI
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async static Task<ApiResponse> TryPostAsync(string route, string postJson = null)
|
internal async static Task<ApiResponse> TryPostAsync(string route, string postJson = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route);
|
var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route);
|
||||||
@@ -244,9 +249,30 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="jsonString"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static JObject Parse(string jsonString)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(jsonString))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JObject.Parse(jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static long IdFromResponse(ApiResponse a)
|
||||||
|
{
|
||||||
|
return a.ObjectResponse["data"]["id"].Value<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint CTokenFromResponse(ApiResponse a)
|
||||||
|
{
|
||||||
|
return a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user