Last active
September 30, 2019 11:55
-
-
Save hamid-shaikh/0774fe04cf7121c0d596925c93fc1809 to your computer and use it in GitHub Desktop.
Refit + Prism Forms + Fusillade + ModernHttpClient (LoginPageViewModel)
This file contains 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
//Constructer Creation | |
public partial class LoginPageViewModel | |
{ | |
public LoginPageViewModel(INavigationService navigationService, | |
IApiService<IAuthenticationService> authenticationService) | |
{ | |
NavigationService = authenticationService; | |
AuthenticationService = authenticationService;//Here you will get AuthenticationService object injected | |
} | |
} | |
//Variables Declaration | |
public partial class LoginPageViewModel | |
{ | |
IApiService<IAuthenticationService> AuthenticationService { get; set; } | |
INavigationService NavigationService { get; set; } | |
} | |
//Bindable Properties | |
public partial class LoginPageViewModel | |
{ | |
private string userName; | |
public string UserName | |
{ | |
get { return userName; } | |
set { SetProperty(ref userName, value); } | |
} | |
private string password; | |
public string Password | |
{ | |
get { return password; } | |
set { SetProperty(ref password, value); } | |
} | |
} | |
//Commands Creations | |
public partial class LoginPageViewModel | |
{ | |
public DelegateCommand LoginCommand => new DelegateCommand(OnLoginCommandExecuted); | |
} | |
//Private Methods | |
public partial class LoginPageViewModel | |
{ | |
async void OnLoginCommandExecuted() | |
{ | |
try | |
{ | |
IsLoading = IsBusy = true; | |
//Calling IAuth Service, AuthenticateUser method to check user credentials are valid/not. | |
string userCredential = "Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{UserName}:{Password}")); | |
var response = await AuthenticationService? | |
.UserInitiated? | |
.AuthenticateUserAsync<AuthenticationModel>(userCredential); | |
if (response?.Status == System.Net.HttpStatusCode.OK) | |
{ | |
await NavigationService.NavigateAsync("../" + nameof(DashboardPage)); | |
} | |
else | |
{ | |
throw new UnauthorizedAccessException(); | |
} | |
} | |
finally | |
{ | |
IsLoading = IsBusy = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Step 1 : - https://gist.github.com/hamid-shaikh/24d93419f9b5313685c4dfc40f4b59dc
Step 2 : - https://gist.github.com/hamid-shaikh/7a766529e79cea8e108d53c657ca1594
Step 3 : - https://gist.github.com/hamid-shaikh/803e88151281e24bc07fba2a4903cc49
Step 4 : - https://gist.github.com/hamid-shaikh/082fea0c0bb3accc7c1db180d81a9884
Step 5 : - https://gist.github.com/hamid-shaikh/0774fe04cf7121c0d596925c93fc1809