async void OnLoginClicked(object sender, EventArgs e) { string email = Entry_Mail.Text; string password = Entry_Password.Text; HttpClientRequests requests = new HttpClientRequests(email, password); Login(requests); }
async public void Register(object sender, EventArgs e) { //check whether all data have been saved or not if (checkServiceArea()) { //delete the current pop up //go to the reactions pop up var userAccountsProperty = Application.Current.Properties["UserAccounts"] as UserAccounts; //send data to API here HttpClientRequests requests = new HttpClientRequests(Application.Current.Properties["Email"].ToString(), Application.Current.Properties["Password"].ToString()); System.Net.HttpStatusCode response; if (_displayedData.IsItGeneral) { string actionServiceName = _currentService.name; int actionId = 0; string actionAccessToken = userAccountsProperty.UserServices[_currentService.name].accessToken; string reactionServiceName = userAccountsProperty.UserServices[_currentService.name].serviceReaction; string reactionAccessToken = userAccountsProperty.UserServices[_currentService.name].reactionAccessToken; HttpClientRequests.GenericArea packet = new HttpClientRequests.GenericArea(actionServiceName, actionId, actionAccessToken, reactionServiceName, reactionAccessToken); response = await requests.RegisterGenericArea(packet); } else { string serviceName = userAccountsProperty.UserServices[_currentService.name].serviceReaction; int areaId = 0; string actionAccessToken = userAccountsProperty.UserServices[_currentService.name].reactionAccessToken; HttpClientRequests.SpecificArea packet = new HttpClientRequests.SpecificArea(serviceName, areaId, actionAccessToken); response = await requests.RegisterSpecificArea(packet); } if (response == System.Net.HttpStatusCode.OK) { await DisplayAlert("AREA", "Saved", "OK"); await PopupNavigation.Instance.PopAsync(); } else { await DisplayAlert("CODE", response.ToString(), "OK"); await DisplayAlert("FAILED", "Area not Saved", "OK"); } } else { await DisplayAlert("Warning", "Data can't be saved, pick your area !", "OK"); } }
async private void Login(HttpClientRequests requests) { var response = await requests.SignIn(); //check if account already created if (response == System.Net.HttpStatusCode.OK) { SaveUserInfo(requests._email, requests._password, true); await DisplayAlert("Login", "Success", "OK"); await Navigation.PushAsync(new DashBoard()); Navigation.RemovePage(Navigation.NavigationStack[0]); // remove the root page } else { await DisplayAlert("Login", "Failed", "Ko"); } }
async void CreateAccountGoogleAuth(GoogleUserInfo googleUser) { User user = new User(googleUser.given_name, googleUser.family_name, googleUser.email); HttpClientRequests requests = new HttpClientRequests(googleUser.email, "LOLILOL12"); //todo check how to deal with password //I try to login to check if the account is already sign up Login(requests); //if I'm not signed up I sign up var response = await requests.SignUp(user); if (response == System.Net.HttpStatusCode.OK) { // I login as soon as i have created the account on the server Login(requests); } else { await DisplayAlert("Sign up failed", response.ToString(), "KO"); } }
async void SignUp(object sender, EventArgs e) { string firstName = Entry_FirstName.Text; string lastName = Entry_lastName.Text; string password = Entry_Password.Text; string email = Entry_Email.Text; HttpClientRequests requests = new HttpClientRequests(email, password); User user = new User(firstName, lastName, email); var response = await requests.SignUp(user); //if sign up success redirect to login page if (response == System.Net.HttpStatusCode.OK) { await DisplayAlert("Sign up", "Account created !", "OK"); await Navigation.PopAsync(); //remove the current screen } else { await DisplayAlert("Sign up failed", response.ToString(), "KO"); } }
async public void DeleteAccount(object sender, EventArgs e) { string email = Application.Current.Properties["Email"].ToString(); string password = Application.Current.Properties["Password"].ToString(); HttpClientRequests requests = new HttpClientRequests(email, password); var response = await requests.DeleteUser(); if (response == System.Net.HttpStatusCode.OK) { if (Application.Current.Properties.ContainsKey("UserAccounts")) { Application.Current.Properties["UserAccounts"] = new UserAccounts(); } await DisplayAlert("Account deleted", "Success", "OK"); await Navigation.PushAsync(new LoginPage()); Navigation.RemovePage(Navigation.NavigationStack[0]); // remove the root page } else { await DisplayAlert("Account deleted", response.ToString(), "KO"); } }