finish create module form
This commit is contained in:
@@ -6,13 +6,17 @@ using System.Threading.Tasks;
|
||||
using Server_Dashboard_Socket;
|
||||
|
||||
namespace Server_Dashboard {
|
||||
|
||||
/// <summary>
|
||||
/// View Model for the Login Window
|
||||
/// </summary>
|
||||
class LoginViewModel : BaseViewModel, IWindowHelper {
|
||||
internal class LoginViewModel : BaseViewModel, IWindowHelper {
|
||||
|
||||
#region Properties
|
||||
|
||||
//Username Property
|
||||
private string username;
|
||||
|
||||
public string Username {
|
||||
get { return username; }
|
||||
set {
|
||||
@@ -21,8 +25,10 @@ namespace Server_Dashboard {
|
||||
OnPropertyChanged(nameof(username));
|
||||
}
|
||||
}
|
||||
|
||||
//Error Text displays an error to help the user to fill the form
|
||||
private string errorText;
|
||||
|
||||
public string ErrorText {
|
||||
get { return errorText; }
|
||||
set {
|
||||
@@ -31,18 +37,22 @@ namespace Server_Dashboard {
|
||||
OnPropertyChanged(nameof(errorText));
|
||||
}
|
||||
}
|
||||
|
||||
//Remember me button
|
||||
private bool rememberUser;
|
||||
|
||||
public bool RememberUser {
|
||||
get { return rememberUser; }
|
||||
set {
|
||||
if(value != rememberUser)
|
||||
if (value != rememberUser)
|
||||
rememberUser = value;
|
||||
OnPropertyChanged(nameof(rememberUser));
|
||||
}
|
||||
}
|
||||
|
||||
//Loading circle, gets hidden and shown when logging in
|
||||
private string loading;
|
||||
|
||||
public string Loading {
|
||||
get { return loading; }
|
||||
set {
|
||||
@@ -51,16 +61,20 @@ namespace Server_Dashboard {
|
||||
OnPropertyChanged(nameof(loading));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Public Values
|
||||
|
||||
//Close action for the Window to close properly
|
||||
public Action Close { get ; set; }
|
||||
#endregion
|
||||
public Action Close { get; set; }
|
||||
|
||||
#endregion Public Values
|
||||
|
||||
#region Constructor
|
||||
|
||||
public LoginViewModel() {
|
||||
SocketClient sc = new SocketClient();
|
||||
//SocketClient sc = new SocketClient();
|
||||
//Loading circle is hidden on startup
|
||||
Loading = "Hidden";
|
||||
//Command inits
|
||||
@@ -74,13 +88,17 @@ namespace Server_Dashboard {
|
||||
//TODO: Autologin
|
||||
//AutoLoginAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region ICommands
|
||||
|
||||
public ICommand LoginCommand { get; set; }
|
||||
#endregion
|
||||
|
||||
#endregion ICommands
|
||||
|
||||
#region Commands
|
||||
|
||||
/// <summary>
|
||||
/// Async login
|
||||
/// </summary>
|
||||
@@ -105,6 +123,7 @@ namespace Server_Dashboard {
|
||||
//Sets the error text and exits function
|
||||
ErrorText = "Username or password is wrong.";
|
||||
return;
|
||||
|
||||
case 1:
|
||||
/*No idea why this is here, gonna let it be till the remember me and autologin is 100% done
|
||||
if (RememberUser && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
|
||||
@@ -133,22 +152,26 @@ namespace Server_Dashboard {
|
||||
DatabaseHandler.AddCookie(Username, cookie);
|
||||
}
|
||||
//Creates a new Dashboard window and shows it
|
||||
DashboardWindow window = new DashboardWindow();
|
||||
DashboardWindow window = new DashboardWindow() {
|
||||
DataContext = new DashboardViewModel(Username)
|
||||
};
|
||||
window.Show();
|
||||
//When closed, close it correctly
|
||||
//Close window when dashboard is shown
|
||||
Close?.Invoke();
|
||||
return;
|
||||
|
||||
case 2:
|
||||
//Sets the error text
|
||||
ErrorText = "Server unreachable, connection timeout.";
|
||||
return;
|
||||
|
||||
default:
|
||||
//Sets the error text
|
||||
ErrorText = "An unknown error has occured";
|
||||
return;
|
||||
}
|
||||
//If the Username and password is blank
|
||||
//All these IF's could be one but i made multiple for the different errors so the user knows whats wrong
|
||||
//If the Username and password is blank
|
||||
//All these IF's could be one but i made multiple for the different errors so the user knows whats wrong
|
||||
} else if (String.IsNullOrWhiteSpace(Username) && String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
|
||||
//Sets the error text
|
||||
ErrorText = "Please provide a username and password";
|
||||
@@ -169,9 +192,11 @@ namespace Server_Dashboard {
|
||||
//If there is no error, clear the error text
|
||||
ErrorText = "";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Commands
|
||||
|
||||
#region private functions
|
||||
|
||||
//TODO: Add autologin function that locks the UI untill the user hits the abort button or the login completes
|
||||
/*private async void AutoLoginAsync() {
|
||||
if (Settings.Default.RememberMe && !String.IsNullOrEmpty(Settings.Default.Username) && !String.IsNullOrEmpty(Settings.Default.Cookies)) {
|
||||
@@ -186,6 +211,7 @@ namespace Server_Dashboard {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
#endregion
|
||||
|
||||
#endregion private functions
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user