Example #1
0
        private void LogUserIn(User us)
        {
            // Now change the connection string to have the user id in the application name...
            ConnectionHelper.CurrentConnection.ApplicationName = string.Format("HCMIS-Warehouse-V-{0}-U-{1}", Program.HCMISVersionString, us.ID);

            // Re-register the connection string manager here.

            MyGeneration.dOOdads.BusinessEntity.RegistryConnectionString = ConnectionHelper.CurrentConnection.ToString();
            ConnectionManager.ConnectionString = ConnectionHelper.CurrentConnection.ToString();

            if (BLL.Settings.UseNewUserManagement)
            {
                // Idealy, this has to work, but we don't know the kind of code that depends on the legacy new main window object.
                var        menuItems  = MenuListViewModel.GenerateMenuForUser(((UserIdentity)Thread.CurrentPrincipal.Identity).UserID);
                MainWindow mainWindow = new MainWindow(menuItems);

                //Legacy Code ... Remove this when not in use.
                CurrentContext main = new CurrentContext();
                CurrentContext.UserId           = us.ID;
                CurrentContext.LoggedInUser     = us;
                CurrentContext.LoggedInUserName = string.Format("{0} {1}", us.FirstName, us.LastName);

                if (string.IsNullOrEmpty(CurrentContext.LoggedInUserName))
                {
                    CurrentContext.LoggedInUserName = us.UserName;
                }

                mainWindow.Show();
                this.Hide();
            }

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                BLL.LogLogin newLoginLog = new LoginLog();
                newLoginLog.AddNew(us.ID, DateTimeHelper.ServerDateTime, true, Environment.MachineName, "", "",
                                   false, "", Program.HCMISVersionString);
                // Also update the last login time on the User Object
            }
        }
        private void BtnLoginClick(object sender, EventArgs e)
        {
            UserInformation userInfo = null;
            try
            {
                if (BLL.Settings.UseNewUserManagement)
                {
                   userInfo  = Auth.Authenticate(txtUsername.Text, txtPassword.Text);
                    if (userInfo == null)
                    {
                        //errorLogger.SaveError(0, 1, 1, 2, "Login Attempt", "Warehouse", new InvalidCredentialException("Invalid credentials, Username = "******"", "", true, txtUsername.Text, Program.HCMISVersionString);
                    if (XtraMessageBox.Show(@"Invalid Username or Password!", @"Login Failed", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop) == DialogResult.Cancel)
                    {
                        Application.Exit();
                    }
                    else
                    {

                    }
                }
            }
            catch
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    //ConnectionStringManager.ConnectionStringManager connMgr =
                    //    new ConnectionStringManager.ConnectionStringManager(Program.RegKey,
                    //                                                        Program.PrevConnectionStringKey);
                    //connMgr.ShowDialog();
                }
                else
                {
                    XtraMessageBox.Show("Network error.  Please make sure your network connection is working.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Clear the login form
            txtPassword.Text = "";
            txtUsername.Text = "";
            txtUsername.Focus();
        }
        private void LogUserIn(User us)
        {
            // Now change the connection string to have the user id in the application name...
            ConnectionHelper.CurrentConnection.ApplicationName = string.Format("HCMIS-Warehouse-V-{0}-U-{1}",Program.HCMISVersionString,us.ID);

            // Re-register the connection string manager here.

            MyGeneration.dOOdads.BusinessEntity.RegistryConnectionString = ConnectionHelper.CurrentConnection.ToString();
            ConnectionManager.ConnectionString = ConnectionHelper.CurrentConnection.ToString();

            if (BLL.Settings.UseNewUserManagement)
            {
                // Idealy, this has to work, but we don't know the kind of code that depends on the legacy new main window object.
                var menuItems = MenuListViewModel.GenerateMenuForUser(((UserIdentity)Thread.CurrentPrincipal.Identity).UserID);
                MainWindow mainWindow = new MainWindow(menuItems);

                //Legacy Code ... Remove this when not in use.
                CurrentContext main = new CurrentContext();
                CurrentContext.UserId = us.ID;
                CurrentContext.LoggedInUser = us;
                CurrentContext.LoggedInUserName = string.Format("{0} {1}", us.FirstName, us.LastName);

                if(string.IsNullOrEmpty(CurrentContext.LoggedInUserName) )
                {
                    CurrentContext.LoggedInUserName = us.UserName;
                }

                mainWindow.Show();
                this.Hide();

            }

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                BLL.LogLogin newLoginLog = new LoginLog();
                newLoginLog.AddNew(us.ID, DateTimeHelper.ServerDateTime, true, Environment.MachineName, "", "",
                                   false, "", Program.HCMISVersionString);
                // Also update the last login time on the User Object

            }
        }
Example #4
0
        private void BtnLoginClick(object sender, EventArgs e)
        {
            UserInformation userInfo = null;

            try
            {
                if (BLL.Settings.UseNewUserManagement)
                {
                    userInfo = Auth.Authenticate(txtUsername.Text, txtPassword.Text);
                    if (userInfo == null)
                    {
                        //errorLogger.SaveError(0, 1, 1, 2, "Login Attempt", "Warehouse", new InvalidCredentialException("Invalid credentials, Username = "******"", "", true, txtUsername.Text, Program.HCMISVersionString);
                    if (XtraMessageBox.Show(@"Invalid Username or Password!", @"Login Failed", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop) == DialogResult.Cancel)
                    {
                        Application.Exit();
                    }
                    else
                    {
                    }
                }
            }
            catch
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    //ConnectionStringManager.ConnectionStringManager connMgr =
                    //    new ConnectionStringManager.ConnectionStringManager(Program.RegKey,
                    //                                                        Program.PrevConnectionStringKey);
                    //connMgr.ShowDialog();
                }
                else
                {
                    XtraMessageBox.Show("Network error.  Please make sure your network connection is working.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Clear the login form
            txtPassword.Text = "";
            txtUsername.Text = "";
            txtUsername.Focus();
        }