public void LoadApp() { string loginFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "login.txt"); bool doesFileExist = File.Exists(loginFile); if (doesFileExist == false) { File.WriteAllText(loginFile, ""); } string userLogin = File.ReadAllText(loginFile); if (userLogin == "") { App.Current.MainPage = new LoginPage(); } else { VDJAppSingletonInstance = VDJAppSingleton.Instance; int allowedToLog = VDJAppSingletonInstance.ReloadInstance(userLogin); if (allowedToLog == -1) { App.Current.MainPage = new LoginPage(); } else { App.Current.MainPage = new MainPage(); } } }
public async Task LoadInfo() { int requestsNumber = 3 - VDJAppSingletonInstance.RequestNumber; RequestsNumberInfo = "Number of song requests you can send: " + requestsNumber; try { HttpResponseMessage userNumberResponse = await VDJAppSingletonInstance.HttpClientSi.GetAsync("api/Users/number"); if (userNumberResponse.IsSuccessStatusCode) { string jsonNumber = await userNumberResponse.Content.ReadAsStringAsync(); int userNumber = JsonConvert.DeserializeObject <int>(jsonNumber); UsersNumberInfo = "There are " + userNumber + " people using app today!"; } if (VDJAppSingletonInstance.SongList.Count == 0) { await VDJAppSingletonInstance.LoadSongDatabase(); VDJAppSingletonInstance.LoadVotes(); } } catch { await Application.Current.MainPage.DisplayAlert("Unable to connect", "Check your network connection and try different page", "OK"); } }
public async Task TryLogin() { Username = Username.Trim(); if (Username.Length < 3) { NoLoginMessage = "Username too short!"; } else if (Username.Length > 20) { NoLoginMessage = "Username too long!"; } else { NoLoginMessage = ""; IsLoading = true; IsButtonNotClicked = false; try { HttpResponseMessage passwordHttpResponse = await VDJAppSingletonInstance.HttpClientSi.GetAsync("api/Users/password"); if (passwordHttpResponse.IsSuccessStatusCode) { string jsonCorrectPassword = await passwordHttpResponse.Content.ReadAsStringAsync(); string CorrectPassword = JsonConvert.DeserializeObject <string>(jsonCorrectPassword); if (Password == CorrectPassword) { HttpResponseMessage isUniqueResponse = await VDJAppSingletonInstance.HttpClientSi.PostAsJsonAsync("api/Users/adduser", Username); if (isUniqueResponse.IsSuccessStatusCode) { IsUsernameUnique = await isUniqueResponse.Content.ReadAsStringAsync(); if (IsUsernameUnique == "0") { NoLoginMessage = "Username already taken!"; } else { VDJAppSingletonInstance.Username = Username; string loginDate = DateTime.Now.ToString(); string stringToWrite = loginDate + "($||$)" + Username + "($||$)" + "0" + "($||$)"; string loginFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "login.txt"); File.WriteAllText(loginFile, stringToWrite); await VDJAppSingletonInstance.LoadSongDatabase(); App.Current.MainPage = new MainPage(); await Application.Current.MainPage.DisplayAlert("Vote for favourite songs!", "By pressing VOTE button in the top right corner you can vote for songs you like and help them get into top songs chart.", "OK"); } } else { NoLoginMessage = "Server error! Try again"; } } else { NoLoginMessage = "Wrong password!"; } } else { NoLoginMessage = "Server error! Try again"; } } catch { NoLoginMessage = "Unable to connect, check your network connection"; } IsLoading = false; IsButtonNotClicked = true; } }