コード例 #1
0
ファイル: Home.cs プロジェクト: srborines/lockifi-windows
        public Lockifi()
        {
            global::LockifiApp.Properties.Settings.Default.Reload();
            InitializeComponent();

            notifyIcon1.Text = "Lockifi";
            notifyIcon1.ContextMenuStrip = contextMenuStripNotifyIcon;

            users = new List<User>();
            routers = new List<Router>();

            listening = false;
            onNotify = false;
            router_current_status = false;
            current_script_router = "";

            FromXML();

            latch = new Latch(global::LockifiApp.Properties.Settings.Default.latch_appid, global::LockifiApp.Properties.Settings.Default.latch_seckey);

            Fill_ComboBoxRouters();
            Fill_comboBoxWifiStatus();

            this.Show();

            Fill_dataGridViewUsers();

        }
コード例 #2
0
ファイル: User.cs プロジェクト: srborines/lockifi-windows
        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";
            }
        }
コード例 #3
0
ファイル: PairUser.cs プロジェクト: srborines/lockifi-windows
        public PairUser(String usernameI,Latch latchI)
        {
            username = usernameI;
            latch = latchI;

            InitializeComponent();

            accountId = "";
            textBoxUsername.Text = username;
            textBoxUsername.Enabled = false;
            textBoxPairCode.Select();
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        private void btnPair_Click(object sender, EventArgs e)
        {
            Latch latch = new Latch(tbApplicationID.Text, tbSecret.Text);
            LatchResponse response = latch.Pair(tbToken.Text);

            if (response.Data != null)
            {
                if (response.Data["accountId"] != null)
                {
                    tbAccountID.Text = response.Data["accountId"].ToString();
                    lblLog.Text = "Pairing successful!";
                    StoreCredentials();
                }
            }
            else
            {
                MessageBox.Show(response.Error.Message + " (" + response.Error.Code + ")");
            }
        }
コード例 #6
0
        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 + ")");
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: plaguna/latch-plugin-pGina
        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." };
            }
        }
コード例 #8
0
        protected override void ProcessRecord()
        {
            try
            {
                Latch.FeatureMode twoFactor, lockOnRequest = Latch.FeatureMode.DISABLED;
                if (String.IsNullOrEmpty(AppId))
                {
                    AppId = InputHelper.GetUserInput(this, "AppId");
                }
                if (String.IsNullOrEmpty(SecretKey))
                {
                    SecretKey = InputHelper.GetUserInput(this, "SecretKey");
                }
                if (String.IsNullOrEmpty(OperationId))
                {
                    OperationId = InputHelper.GetUserInput(this, "OperationId");
                }
                if (String.IsNullOrEmpty(Name))
                {
                    Name = InputHelper.GetUserInput(this, "Name");
                }
                if (String.IsNullOrEmpty(TwoFactor))
                {
                    TwoFactor = InputHelper.GetUserInput(this, String.Format("TwoFactor \"( {0} | {1} | {2} )\"",
                        Latch.FeatureMode.DISABLED.ToString(), Latch.FeatureMode.MANDATORY.ToString(), Latch.FeatureMode.OPT_IN.ToString()));
                }
                if (String.IsNullOrEmpty(LockOnRequest))
                {
                    LockOnRequest = InputHelper.GetUserInput(this, String.Format("Name \"( {0} | {1} | {2} )\"",
                        Latch.FeatureMode.DISABLED.ToString(), Latch.FeatureMode.MANDATORY.ToString(), Latch.FeatureMode.OPT_IN.ToString()));
                }

                Enum.TryParse(TwoFactor, true, out twoFactor);
                Enum.TryParse(LockOnRequest, true, out lockOnRequest);

                Latch latch = new Latch(AppId, SecretKey);
                WriteObject(latch.UpdateOperation(OperationId, Name, twoFactor, lockOnRequest));
            }
            catch (Exception ex)
            {
                InvokeCommand.InvokeScript(String.Format("Write-Host Error: \"{0}\"", ex.Message));
            }
        }
コード例 #9
0
        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.Unpair(AccountId), true);
            }
            catch (Exception ex)
            {
                InvokeCommand.InvokeScript(String.Format("Write-Host Error: \"{0}\"", ex.Message));
            }
        }