public async Task<AuthenticationReport> Login(string username, string password)
 {
     var report = new AuthenticationReport();
     try
     {
         var message = await ExecuteLoginRequest(username, password);
         var content = await message.Content.ReadAsStringAsync();
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(content);
         var invalidCredentials = doc.DocumentElement.GetElementsByTagName("InvalidCredentialsFault").Count > 0;
         if (invalidCredentials)
         {
             report.Error = WebError.InvalidCredentials;
             return report;
         }
         var userData = GetUserDataFromXml(doc);
         report = new AuthenticationReport(true) { UserData = userData };
     }
     catch (Exception exception)
     {
         var webErrorStatus = Windows.Web.WebError.GetStatus(exception.HResult);
         if (webErrorStatus == WebErrorStatus.HostNameNotResolved)
             report.ErrorMessage = "Please check your internet connection and try again";
         else report.ErrorMessage = "Unknown error. Please try again!";
         return report;
     }
     return report;
 }
Ejemplo n.º 2
0
 private async Task HandleAuthenticationResult(AuthenticationReport authenticationReport)
 {
     if (authenticationReport.Successful)
     {
         var userData = authenticationReport.UserData;
         _appSettings.Set(StorageKey.SessionId, userData.SessionId);
         _appSettings.Set(StorageKey.UserDisplayName, userData.DisplayName);
         _appSettings.Set(StorageKey.City, userData.City);
         _appSettings.Set(StorageKey.UserStatus, userData.Status);
         _appSettings.Set(StorageKey.Country, userData.Country);
         _appSettings.Set(StorageKey.SessionExpiration, userData.Expiration);
         if (RememberMe)
         {
             _appSettings.Set(StorageKey.Username, Username);
             _appSettings.Set(StorageKey.Password, Password);
         }
         NavigationService.Navigate(typeof(HomeView));
         _statisticsService.RegisterEvent(EventCategory.UserEvent, "logged in", userData.DisplayName);
     }
     else
     {
         switch (authenticationReport.Error)
         {
             case WebError.InvalidCredentials:
                 await
                     _dialogService.ShowMessageDialog(
                         "The credentials are invalid. Please check your username and password.");
                 break;
             case WebError.Unknown:
                 await _dialogService.ShowMessageDialog(authenticationReport.ErrorMessage);
                 break;
         }
     }
 }