Last active
December 14, 2015 12:57
-
-
Save BrianJVarley/a36c9ad49541f62d431e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class App : Application | |
{ | |
private static IDialogService dialogService = new DialogService(); | |
private static IAuthenticationService authoService = new AuthenticationService(); | |
private LoginViewModel loginViewModel { get; set; } | |
protected override void OnStartup(StartupEventArgs e) | |
{ | |
base.OnStartup(e); | |
// Login | |
var login = new LoginView(); | |
var loginVM = new LoginViewModel(dialogService, authoService); | |
login.DataContext = loginVM; | |
login.ShowDialog(); | |
if (!login.DialogResult.GetValueOrDefault()) | |
{ | |
Environment.Exit(0); | |
} | |
// If login is successful, show main application | |
var app = new ApplicationView(); | |
var appVM = new ApplicationViewModel(); | |
app.DataContext = appVM; | |
app.Show(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ImplementPropertyChanged] | |
class LoginViewModel : IPageViewModel | |
{ | |
public string Name { get; set; } | |
public bool IsEnabled { get; set; } | |
public ICommand LoginCommand { get; set; } | |
private IDialogService _dialogService; | |
private IAuthenticationService _authService; | |
public LoginViewModel(IDialogService dialogService, IAuthenticationService authService) | |
{ | |
this._dialogService = dialogService; | |
this._authService = authService; | |
LoadCommands(); | |
} | |
public string UserName { get; set; } | |
public SecureString Password { get; set; } | |
private void LoadCommands() | |
{ | |
LoginCommand = new RelayCommand(OnLogin); | |
} | |
private async void OnLogin(object obj) | |
{ | |
var result = await _authService.LoginAsync(UserName, Password); | |
if (result) | |
{ | |
Messenger.Default.Send<string>(UserName); | |
System.Windows.MessageBox.Show("You are logged in"); | |
} | |
else | |
{ | |
System.Windows.MessageBox.Show("Unknown username or password."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment