Пример #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            SetCertificatePolicy();

            Server = serverSelect.SelectedItem.ToString();

            if (Server == ""){
                MessageBox.Show("Please select a server");
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            //Form Validation
            if (txtUser.Text == "")
            {
                MessageBox.Show("Please Enter Your Username");
                return;
            }
            if (txtPassword.Text == "")
            {
                MessageBox.Show("Please Enter Your Password");
                return;
            }

            //Set the User for the Session Manager
            sessionManager.UserName = txtUser.Text;

            string pass = CalculateMD5Hash(txtPassword.Text);
            StringBuilder data = new StringBuilder();
            data.Append(Server);
            data.Append("authenticateREST.php");
            data.Append("?u=" + WebUtility.HtmlEncode(txtUser.Text.Replace("'","''")));
            data.Append("&p=" + WebUtility.HtmlEncode(pass.Replace("'","''")));

            string url = data.ToString();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";

            Debug.WriteLine("Connection Request: ");
            Debug.WriteLine(request.RequestUri.OriginalString.ToString());

            request.Timeout = (50000);

            try
            {
                WebResponse response = request.GetResponse();

                /*
                StreamReader reader = new StreamReader(response.GetResponseStream());
                Debug.WriteLine("");
                Debug.WriteLine("LOGIN XML:");
                Debug.WriteLine(reader.ReadToEnd());

                response = request.GetResponse();
                //*/

                XmlTextReader xmlReader = new XmlTextReader(response.GetResponseStream());

                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (xmlReader.Name == "errNum")
                            {
                                if (xmlReader.ReadElementContentAsInt() > 0)
                                {
                                    MessageBox.Show("Login failure.  Please check your login information and try again.");
                                }
                            }
                            else if (xmlReader.Name == "key")
                            {
                                xmlReader.Read();
                                sessionManager.Key = xmlReader.Value;
                            }

                            else if (xmlReader.Name == "PersonalID")
                            {
                                xmlReader.Read();
                                sessionManager.UserID = int.Parse(xmlReader.Value);
                            }
                            else if (xmlReader.Name == "Type")
                            {
                                xmlReader.Read();
                                sessionManager.UserPermissionLevel = int.Parse(xmlReader.Value);
                            }
                            else if (xmlReader.Name == "FirstName")
                            {
                                xmlReader.Read();
                                sessionManager.FirstName = xmlReader.Value;
                            }
                            else if (xmlReader.Name == "LastName")
                            {
                                xmlReader.Read();
                                sessionManager.LastName = xmlReader.Value;
                            }

                            break;
                        default:
                            break;
                    }
                }

            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
                MessageBox.Show("Program encountered an error.  Please try again later", "Yeah...we didn't plan for this", MessageBoxButtons.OK);
                Application.Exit();
            }

            Cursor.Current = Cursors.Default;

            LoginEventArgs eventArgs = new LoginEventArgs(sessionManager);
            eventArgs.Server = Server;
            OnLoginEvent(eventArgs);
        }
Пример #2
0
        private void login_LoginEvent(object sender, LoginEventArgs e)
        {
            sessionManager = e.Session;
            activeServer = e.Server;

            if (sessionManager.Key == "MEMBER PROFILE LOCKED")
            {
                MessageBox.Show("Your account has been locked.\nPlease contact an administrator.");
                return;
            }

            if(sessionManager.IsLoggedIn)
                tabViewer.TabPages.RemoveByKey("Login");
            this.Text = "Welcome to EMIS " + sessionManager.FirstName;
            updateNavTree();
        }
Пример #3
0
 protected virtual void OnLoginEvent(LoginEventArgs e)
 {
     if(LoginEvent != null)
     LoginEvent(this, e);
 }