private async Task CreateBlankUserRecord() { await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); var newUser = new UsersCredentials { Email = "", Handle = "", Password = "" }; await _connection.InsertAsync(newUser); }
private async Task CreateBlankUserRecord() { var newUser = new UsersCredentials { //Email = "*****@*****.**", //Handle = "mj0nes6", //Password = "******" Email = "", Handle = "", Password = "" }; await _connection.InsertAsync(newUser); }
//Remove any records from the user credentials table, add a new blank //record and redirect back to the original login page public async Task CheckLogin() { await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); //Remove all data var newUser = new UsersCredentials { //Email = "*****@*****.**", //Handle = "mj0nes6", //Password = "******" Email = "", Handle = "", Password = "" }; await _connection.InsertAsync(newUser); //Add new data await Navigation.PushAsync(new Views.Login.LoginPage()); //Redirect to login page return; }
public async Task Logout() { var result = await DisplayAlert("Log Out?", "Are you sure you want to log out?", "Yes", "No"); //IF USER HAS SELECTED 'YES' if (result) { await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); //REMOVE ALL USER DATA var newUser = new UsersCredentials { Email = "", Handle = "", Password = "" }; await _connection.InsertAsync(newUser); //ADD NEW BLANK USER RECORD await Navigation.PushAsync(new Views.Login.LoginPage()); //REDIRECT TO LOGIN PAGE return; } }
//private async Task CreateBlankUserRecord() //{ // await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); // var newUser = new UsersCredentials // { // //Email = "*****@*****.**", // //Handle = "mj0nes6", // //Password = "******" // Email = "", // Handle = "", // Password = "" // }; // await _connection.InsertAsync(newUser); //} public async Task CheckLogin(string email, string password, string handle, string reason) { //Check to see if the details exist in the database already string k = "FAF3C5A4-D949-E811-811F-0CC47A480E0C"; LoginCheck login = new LoginCheck(); login.Active = 1; login.Email = Models.Security.Encrypt(Models.Security.Encrypt(email, k), k); login.Password = Models.Security.Encrypt(Models.Security.Encrypt(password, k), k); login.Handle = Models.Security.Encrypt(Models.Security.Encrypt(handle, k), k); //login.UserGuid = new Guid("382F42CF-51A0-4658-A1D8-177FCB74AF98");//localUserInfo.UserGuid; login.Reason = reason; //"CheckIfSqliteInAzure"; string url = "https://myapi20180503015443.azurewebsites.net/api/Login/CheckUser"; HttpClient client = new HttpClient(); var data = JsonConvert.SerializeObject(login); var content = new StringContent(data, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); var result = JsonConvert.DeserializeObject <LoginCheck>(response.Content.ReadAsStringAsync().Result); //If they match, go to home screen if (reason == "CheckIfSqliteInAzure") { if (result.Worked == true) { await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); var newUser = new UsersCredentials { Email = result.Email, Handle = result.Handle, Password = result.Password }; await _connection.InsertAsync(newUser); await Navigation.PushAsync(new Views.Home.HomePage()); } else { await DisplayAlert("Login Failed", "Please ensure your details are correct.", "Ok"); return; } } else if (reason == "CheckIfSqliteInAzureForDisclaimer") { if (result.Worked == true) { //Getting this far means that registration can take place as the details don't exist in the DB await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); var newUser = new UsersCredentials { Email = result.Email, Handle = result.Handle, Password = result.Password, UserGuid = result.UserGuid //assign new guid to user }; await _connection.InsertAsync(newUser); //Write to main DB string url2 = "https://myapi20180503015443.azurewebsites.net/api/Login/CreateUser"; HttpClient client2 = new HttpClient(); var data2 = JsonConvert.SerializeObject(login); var content2 = new StringContent(data, Encoding.UTF8, "application/json"); var response2 = await client.PostAsync(url2, content); var result2 = JsonConvert.DeserializeObject <LoginCheck>(response2.Content.ReadAsStringAsync().Result); if (result2.Reason == "User created successfully.") { await Navigation.PushAsync(new Views.Home.HomePage()); } else { await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); await DisplayAlert("Registration Failed", "There was an issue with your registration, please try again.", "Ok"); } } else { await DisplayAlert("Registration Failed", result.Reason, "Ok"); return; } } //if (result.Worked == true) // { // await Navigation.PushAsync(new Views.Home.HomePage()); // } // else // { // //await _connection.ExecuteAsync("DELETE FROM UsersCredentials"); // //await CreateBlankUserRecord(); //await Navigation.PushAsync(new LoginPage()); //} }