Beispiel #1
0
        /// <summary>
        /// Le clic sur le bouton permet de se connecter pour la premiere fois
        /// </summary>
        private void ToFirstLogin()
        {
            View.LoginView           window = new View.LoginView();
            ViewModel.LoginViewModel vm     = new LoginViewModel(window);
            window.DataContext = vm;

            _ns = NavigationService.GetNavigationService(_linkedView);
            _ns.Navigate(window);
        }
        private string errorString;      //Сообщение с ошибкой

        /// <summary>
        /// Конструктор главной модели придставления
        /// </summary>
        public MainViewModel()
        {
            User      = new UserModel();
            LoginPage = new View.LoginView()
            {
                DataContext = this
            };
            RegPage = new View.RegView()
            {
                DataContext = this
            };
            OpacityLoginError = 0;
            EnabledForm       = true;
            SelectedPage      = LoginPage;
        }
        /// <summary>
        /// Initializes a new instance of the LoginViewModel class.
        /// </summary>
        public LoginViewModel()
        {
            Loading    = false;
            LoginError = false;

            //Debug hack
            Login    = "******";
            Password = "******";

            _connectionCommand = new RelayCommand(async() =>
            {
                ViewModelLocator vm = new ViewModelLocator();
                Loading             = true;
                try
                {
                    bool isConnected = await BusinessManagement.User.ConnectAsync(Login, Password);

                    if (isConnected)
                    {
                        // Set connected User
                        ServiceUser.User User = await BusinessManagement.User.GetUserAsync(Login);
                        await Application.Current.Dispatcher.InvokeAsync(() => { _userChangedEventHandler(this, User); });

                        // Reset error handling
                        LoginError = false;

                        // Switch view to home
                        vm.Window.DataContext = vm.Home;
                    }
                    else
                    {
                        // Wrong pass dude !
                        LoginError = true;
                    }
                }
                catch (Exception)
                {
                    // Server error
                }
                finally
                {
                    Loading = false;
                }
            }, () => !Loading && CanLogin);

            WindowContent             = new View.LoginView();
            WindowContent.DataContext = this;
        }
        /// <summary>
        /// Initializes a new instance of the LoginViewModel class.
        /// </summary>
        public LoginViewModel()
        {
            Loading = false;
            LoginError = false;

            //Debug hack
            Login = "******";
            Password = "******";

            _connectionCommand = new RelayCommand(async () =>
            {
                ViewModelLocator vm = new ViewModelLocator();
                Loading = true;
                try
                {
                    bool isConnected = await BusinessManagement.User.ConnectAsync(Login, Password);

                    if (isConnected)
                    {
                        // Set connected User
                        ServiceUser.User User = await BusinessManagement.User.GetUserAsync(Login);
                        await Application.Current.Dispatcher.InvokeAsync(() => { _userChangedEventHandler(this, User); });

                        // Reset error handling
                        LoginError = false;

                        // Switch view to home
                        vm.Window.DataContext = vm.Home;
                    }
                    else
                    {
                        // Wrong pass dude !
                        LoginError = true;
                    }
                }
                catch (Exception)
                {
                    // Server error
                }
                finally
                {
                    Loading = false;
                }
            }, () => !Loading && CanLogin);

            WindowContent = new View.LoginView();
            WindowContent.DataContext = this;
        }
 /// <summary>
 /// Deconnexion
 /// </summary>
 private void Disconnect()
 {
     View.LoginView window = new View.LoginView();
     ViewModel.LoginViewModel vm = new LoginViewModel();
     window.DataContext = vm;
     window.Show();
     CloseSignal = true;
 }
        private void ProcessLogin()
        {
            var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var file = Path.Combine(path, "data.dat");
            if (File.Exists(file))
            {
                var decoded = FileHelper.DecryptFromFile(file, "key1key2key3key4");
                var data = JsonConvert.DeserializeObject<Model.LoginResult>(decoded);
                ViewModelLocator.Logger.InfoFormat("Authentication info has been successfully retrieved from secure file.\n\r Acess token is {0}", data.AuthToken);
                if (data.IsAuthorized)
                {
                    WebClient client = new WebClient();
                    client.Headers.Add("uid", data.UserName);
                    client.Headers.Add("userId", data.UserId.ToString());
                    client.Headers.Add("authToken", data.AuthToken);
                    client.Headers.Add("logonType", "1");

                    byte[] bytes = client.DownloadData(ConfigurationManager.AppSettings["loginUrl"]);
                    string response = Encoding.Default.GetString(bytes);
                    if (!string.IsNullOrEmpty(response))
                    {
                        dynamic authObj = JsonConvert.DeserializeObject<dynamic>(response);
                        if (authObj.errorId == 0)
                        {
                            ViewModelLocator.Logger.WarnFormat("Authentication was succeed. {0}", authObj.error);

                            IsLogged = true;
                            data.IsAuthorized = true;
                            LoginResult = data;

                            if (LoginData == null)
                                this.LoginData = new Model.LoginModel();
                            LoginData.LoginName = data.UserName;
                            LoginData.SaveCredentials = true;
                            if (_outlookInitTask.Status == TaskStatus.Created)
                                _outlookInitTask.Start();
                            return;
                        }
                    }
                }
            }

            var loginView = new View.LoginView();
            loginView.Owner = App.Current.MainWindow;
            loginView.Show();
        }
        /// <summary>
        /// Le clic sur le bouton permet de se connecter pour la premiere fois
        /// </summary>
        private void ToFirstLogin()
        {
            View.LoginView window = new View.LoginView();
            ViewModel.LoginViewModel vm = new LoginViewModel(window);
            window.DataContext = vm;

            _ns = NavigationService.GetNavigationService(_linkedView);
            _ns.Navigate(window);
        }