public async Task <List <TimeEntry> > GetTimeEntries(MODELS.User myUser) { List <TimeEntry> allTimeEntries = null; try { HttpResponseMessage response = await client.GetAsync(client.BaseAddress + @"api/timeentries"); if (response.IsSuccessStatusCode) { allTimeEntries = await response.Content.ReadAsAsync <List <TimeEntry> >(); TimeEntry_maxIndex = allTimeEntries.Max(x => x.Id); } else { System.Windows.MessageBox.Show("ERROR: " + response.StatusCode.ToString()); Logger.Write("!ERROR occurred while getting all time entries : " + Environment.NewLine + response.ReasonPhrase.ToString()); return(allTimeEntries); } return(allTimeEntries.Where(x => x.UserID == myUser.UserID).ToList()); } catch (Exception e) { Logger.Write("!ERROR occurred while getting all time entries : " + Environment.NewLine + e.ToString()); System.Windows.MessageBox.Show("Leaving GetTimeEntries() : ERROR: " + Environment.NewLine + e.ToString()); return(allTimeEntries); } }
public async Task <bool> Logout() { try { BrowserResultType browserResult = await client.LogoutAsync(); if (browserResult != BrowserResultType.Success) { MessageBox.Show(browserResult.ToString(), "Logout error:"); return(false); } this.User = new MODELS.User(); return(true); } catch (Exception e) { Logger.Write("LOGIN | Error occurred while trying to logout : " + Environment.NewLine + e.ToString()); return(false); } }
// METHODS public async Task <bool> Login() { try { string domain = ConfigurationManager.AppSettings["Auth0:Domain"]; string clientId = ConfigurationManager.AppSettings["Auth0:ClientId"]; client = new Auth0Client(new Auth0ClientOptions { Domain = domain, ClientId = clientId }); loginResult = await client.LoginAsync(); if (!loginResult.IsError) { User = new MODELS.User(); foreach (Claim claim in loginResult.User.Claims) { switch (claim.Type) { case "sub": User.UserID = claim.Value; break; case "name": User.Name = claim.Value; break; case "email": User.Email = claim.Value; break; case "email_verified": if (claim.Value == "true") { User.EmailVerified = true; } else { User.EmailVerified = false; } break; case "picture": User.PicturePath = claim.Value; break; default: break; } } Logger.Write("LOGIN | User successfully logged in (" + User.Name + ")"); return(true); } else { this.User = null; Logger.Write("LOGIN | Error occurred while trying to login in : login service returned empty user"); return(false); } } catch (Exception e) { Logger.Write("LOGIN | Error occurred while trying to login in : " + Environment.NewLine + e.ToString()); return(false); } }