This commit is contained in:
2022-06-22 18:04:31 +00:00
parent 4102809635
commit b14b36c6e9

View File

@@ -26,7 +26,7 @@ namespace AyaNovaQBI
internal static string JWT { get; set; }
// internal static long AyaNovaUserId { get; set; } //probably don't need this, if I do then some code will need to be added to decode the JWT or at the server to get my currently logged in USER ID
// internal static long AyaNovaUserId { get; set; } //probably don't need this, if I do then some code will need to be added to decode the JWT or at the server to get my currently logged in USER ID
internal static string AyaNovaUserName { get; set; }
internal static AuthorizationRoles AyaNovaUserRoles { get; set; }
internal static UserType AyaNovaUserType { get; set; }
@@ -104,11 +104,10 @@ namespace AyaNovaQBI
throw new Exception("Authentication error, route: AUTH\r\nError:" + Err + "\r\nInner error:" + InnerErr);
}
//ApiResponse a = await PostAsync("auth", creds.ToString());
var a = new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) };
if (response.IsSuccessStatusCode)
{
var a = new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) };
bool tfa = a.ObjectResponse["data"]["tfa"].Value<bool>();
if (tfa == true)
{
@@ -131,7 +130,7 @@ namespace AyaNovaQBI
var tfaResponse = await TryPostAsync("auth/tfa-authenticate", tfaCreds.ToString(Newtonsoft.Json.Formatting.None));//trypost is no delay
if (ProcessLoginResponse(tfaResponse)) return true;
}
catch(Exception ex)
catch (Exception ex)
{
if (!ex.Message.Contains("2003"))//if not an authentication error (bad pin) then throw it back up for display
throw ex;
@@ -148,8 +147,27 @@ namespace AyaNovaQBI
return ProcessLoginResponse(a);
}
}
else
{
/*
"error": {
"code": "2001",
"message": "\"E1020 - License key expired 2022-06-20 5:00 PM\r\nLogin as SuperUser to start evaluation / install license\""
}
*/
if (a.ObjectResponse != null && a.ObjectResponse.ContainsKey("error"))
{
var errCode = a.ObjectResponse["error"]["code"].Value<string>();
if (errCode.Contains("2003")) return false;//simple authentication error
var errMessage = a.ObjectResponse["error"]["message"].Value<string>();
throw new Exception($"Code: {errCode} - {errMessage}");
}
return false;
}
return false;
}
private static bool ProcessLoginResponse(ApiResponse a)
@@ -159,7 +177,7 @@ namespace AyaNovaQBI
{
return false;
}
if(a.ObjectResponse["data"]["l"].Value<bool>())//license lockout
if (a.ObjectResponse["data"]["l"].Value<bool>())//license lockout
{
throw new Exception("Server login from QBI is disabled due to AyaNova license issue");
}
@@ -463,11 +481,15 @@ namespace AyaNovaQBI
//Get license
var r = await GetAsync("license");
ALicense = r.ObjectResponse["data"]["license"].ToObject < AyaNovaLicense>();
ALicense = r.ObjectResponse["data"]["license"].ToObject<AyaNovaLicense>();
//UNEXPIRED AYANOVA LICENSE?
todo check this
if (ALicense.licenseWillExpire && ALicense.licenseExpiration < DateTime.UtcNow)
{
initErrors.AppendLine($"AyaNova license has expired {ALicense.licenseExpiration.ToLocalTime().ToString("g")}");
return false;
}
//QBI LICENSED?