From a23b268dc96b83d47867d2d7a75d42f0dae41861 Mon Sep 17 00:00:00 2001 From: shinichi Date: Wed, 7 Oct 2020 19:45:20 +0200 Subject: [PATCH] login working uuuuggglyyyyyyyyyyyyyy :( --- ClientApp/Utils/Client.cs | 19 ++++++++++--------- ClientApp/ViewModels/LoginViewModel.cs | 12 ++++++++++-- ClientApp/ViewModels/MainViewModel.cs | 11 ++++++----- ClientApp/ViewModels/MainWindowViewModel.cs | 14 +++++++++++--- ClientApp/Views/MainView.xaml | 6 +++--- ClientApp/Views/MainWindow.xaml.cs | 13 ++----------- 6 files changed, 42 insertions(+), 33 deletions(-) diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index f702f2e..8dd0ad1 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Net.Sockets; using System.Text; +using ClientApp.ViewModels; using ProftaakRH; namespace ClientApp.Utils @@ -17,6 +18,7 @@ namespace ClientApp.Utils private EngineConnection engineConnection; private bool sessionRunning = false; private IHandler handler = null; + private LoginViewModel LoginViewModel; public Client() : this("localhost", 5555) @@ -120,13 +122,13 @@ namespace ClientApp.Utils if (responseStatus == "OK") { Console.WriteLine("Username and password correct!"); + this.LoginViewModel.setLoginStatus(true); this.connected = true; initEngine(); } else { Console.WriteLine($"login failed \"{responseStatus}\""); - tryLogin(); } break; case DataParser.START_SESSION: @@ -261,14 +263,8 @@ namespace ClientApp.Utils /// /// tries to log in to the server by asking for a username and password /// - private void tryLogin() + public void tryLogin(string username, string password) { - //TODO File in lezen - Console.WriteLine("enter username"); - string username = Console.ReadLine(); - Console.WriteLine("enter password"); - string password = Console.ReadLine(); - string hashUser = Hashing.Hasher.HashString(username); string hashPassword = Hashing.Hasher.HashString(password); @@ -282,9 +278,14 @@ namespace ClientApp.Utils /// sets the handler for the client, so either the bike simulator or the bluetooth bike handler /// /// - public void setHandler(IHandler handler) + public void SetHandler(IHandler handler) { this.handler = handler; } + + internal void SetLoginViewModel(LoginViewModel loginViewModel) + { + this.LoginViewModel = loginViewModel; + } } } diff --git a/ClientApp/ViewModels/LoginViewModel.cs b/ClientApp/ViewModels/LoginViewModel.cs index afeab98..d42b04d 100644 --- a/ClientApp/ViewModels/LoginViewModel.cs +++ b/ClientApp/ViewModels/LoginViewModel.cs @@ -19,12 +19,20 @@ namespace ClientApp.ViewModels this.mainWindowViewModel = mainWindowViewModel; LoginCommand = new RelayCommand((parameter) => { - Debug.WriteLine($"username {Username} password {((PasswordBox)parameter).Password}"); //TODO send username and password to server - this.mainWindowViewModel.SelectedViewModel = new MainViewModel(); + this.mainWindowViewModel.client.tryLogin(Username, ((PasswordBox)parameter).Password); }); } public ICommand LoginCommand { get; set; } + + internal void setLoginStatus(bool status) + { + this.mainWindowViewModel.infoModel.ConnectedToServer = true; + if (status) + { + this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel); + } + } } } diff --git a/ClientApp/ViewModels/MainViewModel.cs b/ClientApp/ViewModels/MainViewModel.cs index 684564c..145623e 100644 --- a/ClientApp/ViewModels/MainViewModel.cs +++ b/ClientApp/ViewModels/MainViewModel.cs @@ -7,22 +7,23 @@ namespace ClientApp.ViewModels { class MainViewModel : ObservableObject { - public Info infoModel { get; set; } public ICommand RetryServerCommand { get; set; } public ICommand RetryVREngineCommand { get; set; } + public MainWindowViewModel MainWindowViewModel; - public MainViewModel() + + public MainViewModel(MainWindowViewModel mainWindowViewModel) { - this.infoModel = new Info(); + this.MainWindowViewModel = mainWindowViewModel; this.RetryServerCommand = new RelayCommand(() => { //try connect server - this.infoModel.ConnectedToServer = true; + this.MainWindowViewModel.infoModel.ConnectedToServer = true; }); this.RetryVREngineCommand = new RelayCommand(() => { //try connect vr-engine - this.infoModel.ConnectedToVREngine = true; + this.MainWindowViewModel.infoModel.ConnectedToVREngine = true; }); } } diff --git a/ClientApp/ViewModels/MainWindowViewModel.cs b/ClientApp/ViewModels/MainWindowViewModel.cs index 1044d10..eada356 100644 --- a/ClientApp/ViewModels/MainWindowViewModel.cs +++ b/ClientApp/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ -using ClientApp.Utils; +using ClientApp.Models; +using ClientApp.Utils; using System; using System.Collections.Generic; using System.Text; @@ -7,12 +8,19 @@ namespace ClientApp.ViewModels { class MainWindowViewModel : ObservableObject { + public Info infoModel { get; set; } public ObservableObject SelectedViewModel { get; set; } + public Client client { get; } - public MainWindowViewModel() + public MainWindowViewModel(Client client) { - SelectedViewModel = new LoginViewModel(this); + this.infoModel = new Info(); + this.client = client; + LoginViewModel loginViewModel = new LoginViewModel(this); + SelectedViewModel = loginViewModel; + this.client.SetLoginViewModel(loginViewModel); } + } } diff --git a/ClientApp/Views/MainView.xaml b/ClientApp/Views/MainView.xaml index 6c1796e..2020d1b 100644 --- a/ClientApp/Views/MainView.xaml +++ b/ClientApp/Views/MainView.xaml @@ -21,17 +21,17 @@