private Domain.Models.RequestModels.AuthModel ConvertUserToDomain(Mobile.ESig.User user) { Domain.Models.RequestModels.AuthModel domainUser = new Domain.Models.RequestModels.AuthModel( user.Username, user.Password ); return(domainUser); }
private Domain.Models.RequestModels.AuthModel SetCommonUserFields(Domain.Models.RequestModels.AuthModel user) { user.ApplicationId = Settings.GetApplicationId(); user.SerialNumber = Settings.GetSerialNumber(); user.Version = Settings.GetVersion(); user.AuthToken = Settings.GetAuthorizationToken(); user.DomainName = Settings.GetDomainName(); return(user); }
async void OnLoginButtonClicked(object sender, EventArgs e) { Domain.Models.RequestModels.AuthModel user = new Domain.Models.RequestModels.AuthModel { LoginName = usernameEntry.Text, Password = passwordEntry.Text }; // Authenticate the user. using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black)) { bool isValid = false; try { isValid = await ViewModel.AuthenticateUserAsync(user); } catch (Exception ex) { Debug.WriteLine($"Exception in LoginView.xaml.cs -> OnLoginButtonClicked: {ex.Message}"); await DisplayAlert(Constants.ErrorMsgTitleOops, Constants.ErrorMsgSorry, "OK").ConfigureAwait(false); } if (isValid) { App.IsUserLoggedIn = true; App.IsLoggedInFirstTime = true; if (CrossDevice.Hardware.OperatingSystem == "WINDOWS") { Application.Current.MainPage = new NavigationPage(new MainViewsMasters()); } else { await Navigation.PushAsync(new MainViewsMasters()); } // await Navigation.PopAsync().ConfigureAwait(false); } else { // login was not a successful attempt, so notify the user... vaguely messageLabel.Text = "Invalid user name or password. Please try again."; passwordEntry.Text = string.Empty; } } }
public async Task <bool> AuthenticateUserAsync(Domain.Models.RequestModels.AuthModel user) { if (string.IsNullOrWhiteSpace(user.LoginName) || string.IsNullOrWhiteSpace(user.Password)) { return(false); } Domain.Models.ResponseModels.AuthModel result = await _authService.AuthenticateUserAsync(user); // Setting access token Settings.SetAccessToken(result.AccessToken); return(result.Success); }
public async Task <bool> AreCredentialsCorrect(Mobile.ESig.User user) { var isValid = ValidateUser(user); if (!isValid) { return(false); } Domain.Models.RequestModels.AuthModel domainUser = ConvertUserToDomain(user); // TODO: Call the REST Service for authentication var res = await _authService.ValidateLoginAsync(domainUser); return(res); }
public async Task <Domain.Models.ResponseModels.AuthModel> AuthenticateUserAsync(Domain.Models.RequestModels.AuthModel user) { user = SetCommonUserFields(user); var client = new HttpClient(); client.BaseAddress = new Uri(Settings.GetBaseUrl()); var data = JsonConvert.SerializeObject(user); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(Settings.GetBaseUrl() + "/account", content); var result = JsonConvert.DeserializeObject <Domain.Models.ResponseModels.AuthModel>( response.Content.ReadAsStringAsync().Result); return(result); }