public Boolean getLatchStatus(Latch latch) { LatchResponse statusResponse = null; try { statusResponse = latch.Status(accountId); } catch (Exception es) { string message = "You do not have internet connection"; string caption = "Problem with internet connection"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (statusResponse.Error != null && statusResponse.Error.Message != "") { string message = statusResponse.Error.Message; string caption = "Latch connection: " + statusResponse.Error.Code; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { Dictionary<string, object> op = (Dictionary<string, object>)statusResponse.Data["operations"]; Dictionary<string, object> st = (Dictionary<string, object>)op[global::LockifiApp.Properties.Settings.Default.latch_appid]; return st["status"].ToString() == "on"; } }
private void btnCheckStatus_Click(object sender, EventArgs e) { Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text); LatchResponse response = latch.Status(tbAccountID.Text); if (response.Data != null) { Dictionary<string, object> operations = ((Dictionary<string, object>)response.Data["operations"]); Dictionary<string, object> appSettings = ((Dictionary<string, object>)operations[(tbApplicationID.Text)]); string status = ((string)appSettings["status"]); lblLog.Text = "Latch account status is " + status; } }
private void btnCheckLatchConf_Click(object sender, EventArgs e) { lblLog.Text = ""; if (tbApplicationID.Text == null || tbSecret.Text == null) { lblLog.Text = "Application ID and Secret must be set"; return; } // This is the simpliest way I found to check if the details are correct. Hope they add a Validate() method to the API Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text); LatchResponse response = latch.Status("TestingUserDoNotHateMePalako"); if (response.Error.Code == 202) { lblLog.Text = "Application ID and Secret are valid."; } else MessageBox.Show(response.Error.Message + " (" + response.Error.Code + ")"); }
public BooleanResult AuthorizeUser(SessionProperties properties) { UserInformation userInfo = properties.GetTrackedSingle<UserInformation>(); if (!ReferenceEquals(null, Settings.ApplicationID) && !ReferenceEquals(null, Settings.Secret)) { string applicationID = Util.GetSettingsString((string)Settings.ApplicationID); string secret = Util.GetSettingsString((string)Settings.Secret); string accountID = Util.GetSettingsString((string)Settings.AccountID); //m_logger.InfoFormat("ApplicationID: {0}", applicationID); //m_logger.InfoFormat("Secret: {0}", secret); //m_logger.InfoFormat("AccountID: {0}", accountID); Latch latch = new Latch(applicationID, secret); LatchResponse response = latch.Status(accountID); // One of the ugliest lines of codes I ever wrote, but quickest way to access the object without using json serialization try { Dictionary<string, object> operations = ((Dictionary<string, object>)response.Data["operations"]); Dictionary<string, object> appSettings = ((Dictionary<string, object>)operations[(applicationID)]); string status = ((string)appSettings["status"]); m_logger.InfoFormat("Latch status is {0}", status); if (status == "on") return new BooleanResult() { Success = true, Message = "Ready to go!" }; else return new BooleanResult() { Success = false, Message = "Latch is protecting this account!" }; } catch (Exception) { return new BooleanResult() { Success = true, Message = "Something went wrong, letting you in because I don't want to lock you out!" }; } } else { return new BooleanResult() { Success = false, Message = "Latch is not correctly configured." }; } }
protected override void ProcessRecord() { try { if (String.IsNullOrEmpty(AppId)) { AppId = InputHelper.GetUserInput(this, "AppId"); } if (String.IsNullOrEmpty(SecretKey)) { SecretKey = InputHelper.GetUserInput(this, "SecretKey"); } if (String.IsNullOrEmpty(AccountId)) { AccountId = InputHelper.GetUserInput(this, "AccountId"); } Latch latch = new Latch(AppId, SecretKey); WriteObject(latch.Status(AccountId), true); } catch (Exception ex) { InvokeCommand.InvokeScript(String.Format("Write-Host Error: \"{0}\"", ex.Message)); } }