private void Login(object view)
        {
            try
            {
                User user = _authenticationService.AuthenticateUser(UserName, Password);
                Logger.Log($"User:{UserName} Password:{Password}", Category.Debug, Priority.Medium);
                //Get the current principal object
                SystemPrincipal customPrincipal = Thread.CurrentPrincipal as SystemPrincipal;
                if (customPrincipal == null)
                {
                    Logger.Log(
                        $"The application\'s default thread principal must be set to a CustomPrincipal object on startup",
                        Category.Exception, Priority.High);
                    throw new ArgumentException("The application's default thread principal must be set to a CustomPrincipal object on startup.");
                }

                //Authenticate the user
                customPrincipal.Identity = new SystemIdentity(user.Id, user.Username, user.Email, user.Roles);

                _loginCommand.RaiseCanExecuteChanged();
                IView loginView = view as IView;
                loginView.Close();
            }
            catch (UnauthorizedAccessException)
            {
                Logger.Log($"Login failed! Please provide some valid credentials", Category.Exception, Priority.High);
            }
            catch (Exception ex)
            {
                Logger.Log($"ERROR: {ex.Message}", Category.Exception, Priority.High);
            }
        }
예제 #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            SystemPrincipal customPrincipal = new SystemPrincipal();

            AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal);

            base.OnStartup(e);

            Smart365OperationsBootstrapper bootStrapper = new Smart365OperationsBootstrapper();

            bootStrapper.Run();

            ShutdownMode = ShutdownMode.OnExplicitShutdown;

            LoginScreen loginWindow = bootStrapper.Container.Resolve <LoginScreen>();
            //AuthenticationViewModel viewModel =
            //    new AuthenticationViewModel(bootStrapper.Container.Resolve<IAuthenticationService>());
            //loginWindow.DataContext = viewModel;
            bool?logonResult = loginWindow.ShowDialog();
            var  viewModel   = loginWindow.ViewModel as AuthenticationViewModel;

            if (logonResult.HasValue && viewModel != null && viewModel.IsAuthenticated)
            {
                bootStrapper.Show();
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            }
            else
            {
                Application.Current.Shutdown(1);
            }
        }
예제 #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            bool can_execute = true;

            try
            {
                mutex = new System.Threading.Mutex(false, "SMART365CLIENT", out can_execute);
            }
            catch (Exception ex)
            {
            }
            if (can_execute)
            {
                SystemPrincipal customPrincipal = new SystemPrincipal();
                AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal);

                base.OnStartup(e);

                Smart365OperationsBootstrapper bootStrapper = new Smart365OperationsBootstrapper();
                bootStrapper.Run();

                ShutdownMode = ShutdownMode.OnExplicitShutdown;

                LoginScreen loginWindow = bootStrapper.Container.Resolve <LoginScreen>();
                //AuthenticationViewModel viewModel =
                //    new AuthenticationViewModel(bootStrapper.Container.Resolve<IAuthenticationService>());
                //loginWindow.DataContext = viewModel;
                bool?logonResult = loginWindow.ShowDialog();
                var  viewModel   = loginWindow.ViewModel as AuthenticationViewModel;
                if (logonResult.HasValue && viewModel != null && viewModel.IsAuthenticated)
                {
                    bootStrapper.Show(viewModel.DisplayName);
                    Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
                }
                else
                {
                    Application.Current.Shutdown(1);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("SMART365CLIENT already running!");
                Application.Current.Shutdown(1);
            }
        }