Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.AuthButton.Content = "Authenticating...";
            this.AuthButton.Refresh();
            if (this.role == null)
            {
                MessageBox.Show("Error: ROLE NOT SELECTED");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            if (this.Username.Text == "")
            {
                MessageBox.Show("Error: BLANK USERNAME");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            if (this.Password.Password == "")
            {
                MessageBox.Show("Error: BLANK PASSWORD");
                this.AuthButton.Content = "Authenticate";
                return;
            }
            string user_id = this.Username.Text;
            string pwd     = this.Password.Password;
            Random RND     = new Random();

            System.ValueTuple <string, string, string, CookieContainer> expr_D1 = this.Authenticate(user_id, pwd);
            string          result  = expr_D1.Item1;
            string          value   = expr_D1.Item3;
            CookieContainer cookies = expr_D1.Item4;

            if (result == "FAIL")
            {
                MessageBox.Show("Error: " + value);
                this.AuthButton.Content = "Authenticate";
                return;
            }
            this.Lawnet_Cookies = cookies;
            string session_id = RND.Next(1, 999999999).ToString();

            MessageBox.Show(string.Concat(new string[]
            {
                "Success! Welcome ",
                this.Username.Text,
                "!\n\nCookie ID: ",
                value,
                "\nSession ID: ",
                session_id
            }));
            if (this.NUSRememberMeState())
            {
                Settings.Default.NUSUsername   = ExtensionMethods.Encrypt(this.Username.Text, "");
                Settings.Default.NUSPassword   = ExtensionMethods.Encrypt(this.Password.Password, "");
                Settings.Default.NUSRole       = this.role;
                Settings.Default.NUSRememberMe = true;
                Settings.Default.Save();
            }
            else
            {
                Settings.Default.NUSUsername   = "";
                Settings.Default.NUSPassword   = "";
                Settings.Default.NUSRole       = "";
                Settings.Default.NUSRememberMe = false;
                Settings.Default.Save();
            }
            base.NavigationService.Navigate(new NUSDownloader(this.Lawnet_Cookies, user_id, session_id));
        }