/// <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(); }