Esempio n. 1
0
        private async Task AutoLoginAsync()
        {
            if (File.Exists(FileSystem.UserInformationFilePath))
            {
                string email      = fileDealer.ReadLine(FileSystem.UserInformationFilePath);
                string password   = fileDealer.ReadLine(FileSystem.UserInformationFilePath);
                string requestUrl = Route.User.UrlLogin;
                apiCaller.SetProperties(HttpMethod.Post, requestUrl, new UserLoginVM {
                    Email = email, Password = password
                });
                HttpResponseMessage httpResponseMessage = await apiCaller.SendRequestAsync();

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    string result = await httpResponseMessage.Content.ReadAsStringAsync();

                    User currentUser = JsonConvert.DeserializeObject <User>(result);
                    await Dispatcher.BeginInvoke((Action)(async() => {
                        Inventory.SetCurrentUser(currentUser);
                        await Program.mainWindow.BeginMainAsync();
                    }));
                }
                else
                {
                    TextBoxEmail.Text    = email;
                    PasswordBox.Password = password;
                    Program.mainWindow.MainFrame.Navigate(Program.loginPage);
                }
                fileDealer.Close();
            }
            else
            {
                Program.mainWindow.MainFrame.Navigate(Program.loginPage);
            }
        }
Esempio n. 2
0
        public static void WriteUserData(string email, string password)
        {
            FileDealer fileDealer = new FileDealer();

            fileDealer.WriteLine(UserInformationFilePath, email, true);
            fileDealer.WriteLine(UserInformationFilePath, password, true);
            fileDealer.Close();
        }