Exemplo n.º 1
0
        protected void bt_parear_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tb_token.Text))
            {
                pairResponse = instanciaLatch.Pair(tb_token.Text);

                if (pairResponse.Error == null && pairResponse.Data.ContainsKey("accountId"))
                {
                    var accountId = pairResponse.Data["accountId"] as string;
                    ConfigurationManager.AppSettings["latchAccountId"] = accountId;
                    respChangePassword = instanciaLatch.CreateOperation(accountId, "ChangePassword", LatchSDK.Latch.FeatureMode.DISABLED, LatchSDK.Latch.FeatureMode.DISABLED);
                    respLogin          = instanciaLatch.CreateOperation(accountId, "Login", LatchSDK.Latch.FeatureMode.DISABLED, LatchSDK.Latch.FeatureMode.DISABLED);
                    //storaremanager.saveaccount(User.Identity.Name, accountId);
                    //return RedirectToAction("Manage", "LatchPairSuccess");
                    //bt_parear.Visible = false;
                    lb_error_account_id.Text = "";
                    lb_account_id.Text       = Environment.NewLine + DateTime.Now.ToString() + " Emparejamiento: " + accountId + Environment.NewLine;
                }
                else
                {
                    //ModelState.AddModelError("", pairResponse.Error.Message);
                    //return View("Manage");
                    lb_error_account_id.Text = "Error al parear la aplicación.";
                }
            }
        }
Exemplo n.º 2
0
        private bool IsLatchOperationOpen(string username, string operationId)
        {
            bool isOpen = true;

            try
            {
                if (string.IsNullOrEmpty(lb_account_id.Text))
                {
                    lb_account_id.Text = ConfigurationManager.AppSettings["latchAccountId"];
                    LatchSDK.Latch         latchComm = new LatchSDK.Latch(ConfigurationManager.AppSettings["latchAppId"], ConfigurationManager.AppSettings["latchAppSecret"]);
                    LatchSDK.LatchResponse response  = latchComm.OperationStatus(lb_account_id.Text, operationId);
                    //isOpen = response.Error == null && ((string)(((Dictionary<string, object>)((Dictionary<string, object>)response.Data["operations"])[operationId])["status"])).Equals("on", StringComparison.InvariantCultureIgnoreCase);

                    if (response.Error == null && response.Data["operations"] is Dictionary <string, object> )
                    {
                        Dictionary <string, object> operations = response.Data["operations"] as Dictionary <string, object>;
                        if (operations[operationId] is Dictionary <string, object> )
                        {
                            Dictionary <string, object> currentOperation = operations[operationId] as Dictionary <string, object>;
                            isOpen = (currentOperation["status"] as string).Equals("on", StringComparison.InvariantCultureIgnoreCase);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(isOpen);
        }
Exemplo n.º 3
0
        protected void bt_desparear_Click(object sender, EventArgs e)
        {
            string     cookieName = FormsAuthentication.FormsCookieName;
            HttpCookie authCookie = Context.Request.Cookies[cookieName];

            if (authCookie == null)
            {
                return;
            }
            FormsAuthenticationTicket authTicket = null;

            try
            {
                authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            }
            catch
            {
                return;
            }
            if (authTicket == null)
            {
                return;
            }
            string[]         roles     = authTicket.UserData.Split(new char[] { '|' });
            FormsIdentity    id        = new FormsIdentity(authTicket);
            GenericPrincipal principal = new GenericPrincipal(id, roles);


            //LatchSDK.LatchResponse unpairResponse = instanciaLatch.Unpair(HttpContext.Current.User.Identity.Name);

            LatchSDK.LatchResponse unpairResponse = instanciaLatch.Unpair(ConfigurationManager.AppSettings["latchAccountId"]);
            if (unpairResponse.Error == null)
            {
                lb_error_account_id.Text = "La aplicación se ha despareado.";
            }
            else
            {
                lb_error_account_id.Text = "Se ha producido un error en el proceso de despareado.";
            }
        }
Exemplo n.º 4
0
        private void buttonDeleteUser_Click(object sender, EventArgs e)
        {
            string captionE = "Delete user";
            string messageE = "Are you sure you want to delet this user ?";

            if (MessageBox.Show(messageE, captionE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                LatchSDK.LatchResponse unpair = null;

                Form wait = new Forms.Wait();
                wait.Show();

                try
                {
                    unpair = grandparent.latch.Unpair(current_user.accountId);
                }
                catch
                {
                    wait.Close();
                    string       message = "You do not have internet connection";
                    string       caption = "Problem with internet connection";
                    DialogResult result  = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                if (unpair.Error != null && unpair.Error.Message != "")
                {
                    wait.Close();
                    string       message = unpair.Error.Message;
                    string       caption = "Latch connection: " + unpair.Error.Code;
                    DialogResult result  = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    grandparent.users.Remove(current_user);
                    wait.Close();
                    this.Close();
                }
            }
        }