Example #1
0
        protected override void OnClick(EventArgs e)
        {
            if (UserCtrl == null || PasswordCtrl == null)
            {
                return;
            }
            if (UserCtrl.Text == string.Empty || PasswordCtrl.Text == string.Empty)
            {
                MessageBox.Show("Please Enter UserName and Password!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Enabled = false;
            SynchronizationContext mainContext = SynchronizationContext.Current;

            Task.Run(() =>
            {
                var registerResult = HttpFunctions.Get <string>($"{GlobalAM.WebAPIAddr}//user//register", UserCtrl.Text, PasswordCtrl.Text);
                if (!registerResult.Success)
                {
                    mainContext.Post(obj => { MessageBox.Show(registerResult.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }, null);
                }
            }).ContinueWith(t =>
            {
                mainContext.Post(obj =>
                {
                    Enabled           = true;
                    UserCtrl.Text     = string.Empty;
                    PasswordCtrl.Text = string.Empty;
                }, null);
            });
        }
Example #2
0
        protected override void OnClick(EventArgs e)
        {
            var result = HttpFunctions.Get <string>($"{GlobalAM.WebAPIAddr}//user//logout");

            if (LogoutEvent != null && result.Success)
            {
                LogoutEvent(this, new EventArgs());
            }
        }
Example #3
0
        protected override void OnClick(EventArgs e)
        {
            if (UserCtrl == null || PasswordCtrl == null)
            {
                return;
            }
            if (UserCtrl.Text == string.Empty || PasswordCtrl.Text == string.Empty)
            {
                MessageBox.Show("Please Enter UserName and Password!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            BtnEnable(false);
            SynchronizationContext mainContext = SynchronizationContext.Current;

            Task.Run(() =>
            {
                var loginResult = HttpFunctions.Get <string>($"{GlobalAM.WebAPIAddr}//user//login", UserCtrl.Text, PasswordCtrl.Text);
                if (!loginResult.Success)
                {
                    if (loginResult.Message != null)
                    {
                        MessageBox.Show(loginResult.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    PasswordCtrl.Text = string.Empty;
                    throw new Exception();
                }
                if (LoginSuccessEvent != null)
                {
                    // Get pages which are allowed to use
                    var getPageResult = HttpFunctions.Post <List <string> >($"{GlobalAM.WebAPIAddr}//user//pageauthority");
                    if (getPageResult.Success)
                    {
                        mainContext.Post(obj =>
                        {
                            LoginSuccessEvent(this, new LoginSuccessEventArgs
                            {
                                Pages = getPageResult.Data
                            });
                        }, null);
                    }
                }
            }).ContinueWith(t =>
            {
                mainContext.Post(obj =>
                {
                    BtnEnable(true);
                    if (t.Status == TaskStatus.RanToCompletion)
                    {
                        UserCtrl.Text = string.Empty;
                    }
                    PasswordCtrl.Text = string.Empty;
                }, null);
                CheckTimeout(mainContext);
            });
        }
Example #4
0
 private void PageCheckedListBox_SelectedValueChanged(object sender, EventArgs e)
 {
     if (!_preparing)
     {
         string selectedPage = PageCheckedListBox.SelectedItem.ToString();
         bool   changedValue = PageCheckedListBox.GetItemChecked(PageCheckedListBox.Items.IndexOf(selectedPage));
         var    result       = HttpFunctions.Get <bool>($"{GlobalAM.WebAPIAddr}//user//changepageauthority", selectedPage, changedValue);
         if (result.Success && result.Data && PageChangedEvent != null)
         {
             PageChangedEvent(this, new PageChangedEventArg
             {
                 IsOpen   = changedValue,
                 PageName = selectedPage
             });
         }
     }
 }
Example #5
0
 private void CheckTimeout(SynchronizationContext mainContext)
 {
     if (TimeoutEvent != null)
     {
         Task.Run(() =>
         {
             bool expired = false;
             while (!expired)
             {
                 expired = HttpFunctions.Post <bool>($"{GlobalAM.WebAPIAddr}//user//isexpired").Data;
                 Task.Delay(100);
             }
             mainContext.Post(obj =>
             {
                 TimeoutEvent(this, new EventArgs());
             }, null);
         });
     }
 }
Example #6
0
        public void UpdatePages()
        {
            _preparing = true;
            var pageList = HttpFunctions.Get <string[]>($"{GlobalAM.WebAPIAddr}//user//getallpages");

            PageCheckedListBox.Items.Clear();
            if (pageList.Success)
            {
                foreach (string page in pageList.Data)
                {
                    PageCheckedListBox.Items.Add(page);
                }
            }
            var allowedpageList = HttpFunctions.Get <string[]>($"{GlobalAM.WebAPIAddr}//user//getallowedpages");

            if (allowedpageList.Success)
            {
                foreach (string page in allowedpageList.Data)
                {
                    PageCheckedListBox.SetItemChecked(PageCheckedListBox.Items.IndexOf(page), true);
                }
            }
            _preparing = false;
        }