login working
uuuuggglyyyyyyyyyyyyyy :(
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using ClientApp.ViewModels;
|
||||||
using ProftaakRH;
|
using ProftaakRH;
|
||||||
|
|
||||||
namespace ClientApp.Utils
|
namespace ClientApp.Utils
|
||||||
@@ -17,6 +18,7 @@ namespace ClientApp.Utils
|
|||||||
private EngineConnection engineConnection;
|
private EngineConnection engineConnection;
|
||||||
private bool sessionRunning = false;
|
private bool sessionRunning = false;
|
||||||
private IHandler handler = null;
|
private IHandler handler = null;
|
||||||
|
private LoginViewModel LoginViewModel;
|
||||||
|
|
||||||
|
|
||||||
public Client() : this("localhost", 5555)
|
public Client() : this("localhost", 5555)
|
||||||
@@ -120,13 +122,13 @@ namespace ClientApp.Utils
|
|||||||
if (responseStatus == "OK")
|
if (responseStatus == "OK")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Username and password correct!");
|
Console.WriteLine("Username and password correct!");
|
||||||
|
this.LoginViewModel.setLoginStatus(true);
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
initEngine();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"login failed \"{responseStatus}\"");
|
Console.WriteLine($"login failed \"{responseStatus}\"");
|
||||||
tryLogin();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
@@ -261,14 +263,8 @@ namespace ClientApp.Utils
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// tries to log in to the server by asking for a username and password
|
/// tries to log in to the server by asking for a username and password
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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 hashUser = Hashing.Hasher.HashString(username);
|
||||||
string hashPassword = Hashing.Hasher.HashString(password);
|
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
|
/// sets the handler for the client, so either the bike simulator or the bluetooth bike handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handler"></param>
|
/// <param name="handler"></param>
|
||||||
public void setHandler(IHandler handler)
|
public void SetHandler(IHandler handler)
|
||||||
{
|
{
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void SetLoginViewModel(LoginViewModel loginViewModel)
|
||||||
|
{
|
||||||
|
this.LoginViewModel = loginViewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,20 @@ namespace ClientApp.ViewModels
|
|||||||
this.mainWindowViewModel = mainWindowViewModel;
|
this.mainWindowViewModel = mainWindowViewModel;
|
||||||
LoginCommand = new RelayCommand<object>((parameter) =>
|
LoginCommand = new RelayCommand<object>((parameter) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"username {Username} password {((PasswordBox)parameter).Password}");
|
|
||||||
//TODO send username and password to server
|
//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; }
|
public ICommand LoginCommand { get; set; }
|
||||||
|
|
||||||
|
internal void setLoginStatus(bool status)
|
||||||
|
{
|
||||||
|
this.mainWindowViewModel.infoModel.ConnectedToServer = true;
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
this.mainWindowViewModel.SelectedViewModel = new MainViewModel(mainWindowViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,23 @@ namespace ClientApp.ViewModels
|
|||||||
{
|
{
|
||||||
class MainViewModel : ObservableObject
|
class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public Info infoModel { get; set; }
|
|
||||||
public ICommand RetryServerCommand { get; set; }
|
public ICommand RetryServerCommand { get; set; }
|
||||||
public ICommand RetryVREngineCommand { 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(() =>
|
this.RetryServerCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
//try connect server
|
//try connect server
|
||||||
this.infoModel.ConnectedToServer = true;
|
this.MainWindowViewModel.infoModel.ConnectedToServer = true;
|
||||||
});
|
});
|
||||||
this.RetryVREngineCommand = new RelayCommand(() =>
|
this.RetryVREngineCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
//try connect vr-engine
|
//try connect vr-engine
|
||||||
this.infoModel.ConnectedToVREngine = true;
|
this.MainWindowViewModel.infoModel.ConnectedToVREngine = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using ClientApp.Utils;
|
using ClientApp.Models;
|
||||||
|
using ClientApp.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -7,12 +8,19 @@ namespace ClientApp.ViewModels
|
|||||||
{
|
{
|
||||||
class MainWindowViewModel : ObservableObject
|
class MainWindowViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
|
public Info infoModel { get; set; }
|
||||||
|
|
||||||
public ObservableObject SelectedViewModel { 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,17 +21,17 @@
|
|||||||
|
|
||||||
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Connected to server:"/>
|
<Label Content="Connected to server:"/>
|
||||||
<Label Content="{Binding Path=infoModel.ConnectedToServer}"/>
|
<Label Content="{Binding Path=MainWindowViewModel.infoModel.ConnectToServer}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Connected to VR-Engine:"/>
|
<Label Content="Connected to VR-Engine:"/>
|
||||||
<Label Content="{Binding Path=infoModel.ConnectedToVREngine}"/>
|
<Label Content="{Binding Path=MainWindowViewModel.infoModel.ConnectedToVREngine}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
<StackPanel Grid.Column="2" Grid.Row="0" Orientation="Horizontal" Margin="10">
|
||||||
<Label Content="Doctor connected:"/>
|
<Label Content="Doctor connected:"/>
|
||||||
<Label Content="{Binding Path=infoModel.DoctorConnected}"/>
|
<Label Content="{Binding Path=MainWindowViewModel.infoModel.DoctorConnected}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<Button Grid.Column="0" Grid.Row="1" Command="{Binding RetryServerCommand}" Width="50" Height="20">
|
<Button Grid.Column="0" Grid.Row="1" Command="{Binding RetryServerCommand}" Width="50" Height="20">
|
||||||
|
|||||||
@@ -25,17 +25,12 @@ namespace ClientApp
|
|||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
|
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("derp1");
|
|
||||||
|
|
||||||
Client client = new Client();
|
Client client = new Client();
|
||||||
System.Diagnostics.Debug.WriteLine("derp2");
|
|
||||||
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new MainWindowViewModel();
|
DataContext = new MainWindowViewModel(client);
|
||||||
System.Diagnostics.Debug.WriteLine("derp3");
|
|
||||||
|
|
||||||
|
|
||||||
//BLEHandler bLEHandler = new BLEHandler(client);
|
//BLEHandler bLEHandler = new BLEHandler(client);
|
||||||
@@ -46,16 +41,12 @@ namespace ClientApp
|
|||||||
|
|
||||||
|
|
||||||
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||||
System.Diagnostics.Debug.WriteLine("derp4");
|
|
||||||
|
|
||||||
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
|
Thread newThread = new Thread(new ThreadStart(bikeSimulator.StartSimulation));
|
||||||
newThread.Start();
|
newThread.Start();
|
||||||
//bikeSimulator.StartSimulation();
|
|
||||||
System.Diagnostics.Debug.WriteLine("derp5");
|
|
||||||
|
|
||||||
|
|
||||||
client.setHandler(bikeSimulator);
|
client.SetHandler(bikeSimulator);
|
||||||
System.Diagnostics.Debug.WriteLine("derp6");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user