public CutomerAuthContext CheckLogin(CustomerLogin loginCustomer, string token) { CutomerAuthContext authContext = new CutomerAuthContext(); try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(ConstantData.ApiURL.ToString() + "Registration/RegistrationLogin"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var myContent = JsonConvert.SerializeObject(loginCustomer); var buffer = Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = client.PostAsync(client.BaseAddress, byteContent).Result; if (response.IsSuccessStatusCode) { var responseStream = response.Content.ReadAsStringAsync().Result; authContext = JsonConvert.DeserializeObject <CutomerAuthContext>(responseStream); } } } catch (Exception ex) { throw ex; } return(authContext); }
private int ChangePassword() { CustomerLogin loginCustomer = new CustomerLogin(); loginCustomer.email = email; loginCustomer.Password = OldPassEntry.Text; loginCustomer.clientId = Constants.ClientId; loginCustomer.ClientTime = DateTime.Now; LoginController loginController = new LoginController(); cutomerAuthContext = loginController.CheckLogin(loginCustomer, token); if (cutomerAuthContext != null) { if (cutomerAuthContext.CustomerId > 0) { CustomerController customoerController = new CustomerController(); CPId = customoerController.changePassword(cutomerAuthContext.CustomerId, OldPassEntry.Text, newPassEntry.Text, token); } else { CPId = -1; } } else { CPId = -1; } return(CPId); }
private async void LoginButton_Clicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(loginEmailAddress.Text)) { errorLabel.Text = "Please enter a email address"; errorLabel.IsVisible = true; } else if (!new EmailAddressAttribute().IsValid(loginEmailAddress.Text)) { errorLabel.Text = "Email is not in a valid format.Please try again"; errorLabel.IsVisible = true; } else if (string.IsNullOrEmpty(loginPassword.Text)) { errorLabel.Text = "Please enter a valid password"; errorLabel.IsVisible = true; } else { bool busy = false; if (!busy) { try { busy = true; LoginButton.IsVisible = false; loginSpinnerFrame.IsVisible = true; loginSpinner.IsRunning = true; await Task.Run(() => { GetClientSecretTokenRequest getClientSecretTokenRequest = new GetClientSecretTokenRequest(); getClientSecretTokenRequest.ClientId = Constants.ClientId; ApiController apiController = new ApiController(); GetClientSecretTokenResponse clientSecretTokenResponse = apiController.GetClientSecretToken(getClientSecretTokenRequest); GetAccessTokenRequest tokenRequest = new GetAccessTokenRequest(); tokenRequest.client_id = clientSecretTokenResponse.apiConsumerId; tokenRequest.client_secret = clientSecretTokenResponse.apiConsumerSecret; tokenRequest.grant_type = "client_credentials"; ApiToken apiToken = apiController.GetAccessToken(tokenRequest); token = apiToken.access_token; CustomerLogin loginCustomer = new CustomerLogin(); loginCustomer.email = loginEmailAddress.Text; loginCustomer.Password = loginPassword.Text; loginCustomer.clientId = Constants.ClientId; LoginController loginController = new LoginController(); cutomerAuthContext = loginController.CheckLogin(loginCustomer, token); }); } finally { busy = false; loginSpinner.IsRunning = false; loginSpinnerFrame.IsVisible = false; LoginButton.IsVisible = true; if (cutomerAuthContext.CustomerId > 0) { Constants.IsRegisteredandNotLogin = false; Constants.cutomerAuthContext = cutomerAuthContext; if (App.Current.Properties.ContainsKey("currentToken")) { App.Current.Properties["currentToken"] = token; } else { App.Current.Properties.Add("currentToken", token); } if (App.Current.Properties.ContainsKey("CustomerId")) { App.Current.Properties["CustomerId"] = cutomerAuthContext.CustomerId; } else { App.Current.Properties.Add("CustomerId", cutomerAuthContext.CustomerId); } Type type = typeof(WelcomPage); if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 2].GetType() == type) { await Navigation.PushAsync(new HomePage()); } else if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 2].GetType() == typeof(OtherInformationPage)) { if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 3].GetType() == type) { await Navigation.PushAsync(new HomePage()); } else { Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]); await Navigation.PopAsync(); } } else { await Navigation.PopAsync(); } } else { await PopupNavigation.Instance.PushAsync(new Error_popup("Log in failed . Please try again")); loginPassword.Text = null; errorLabel.IsVisible = false; } } } } }
private async void LoginButton_Clicked(object sender, EventArgs e) { if (!string.IsNullOrEmpty(loginEmailAddress.Text)) { string emailen = loginEmailAddress.Text.Replace(" ", ""); loginEmailAddress.Text = emailen; } if (string.IsNullOrEmpty(loginEmailAddress.Text)) { errorLabel.Text = "Please enter a email address"; errorLabel.IsVisible = true; } else if (!new EmailAddressAttribute().IsValid(loginEmailAddress.Text)) { errorLabel.Text = "Email is not in a valid format.Please try again"; errorLabel.IsVisible = true; } else if (string.IsNullOrEmpty(loginPassword.Text)) { errorLabel.Text = "Please enter a valid password"; errorLabel.IsVisible = true; } else { bool busy = false; if (!busy) { try { busy = true; LoginButton.IsVisible = false; loginSpinnerFrame.IsVisible = true; loginSpinner.IsRunning = true; await Task.Run(() => { GetClientSecretTokenRequest getClientSecretTokenRequest = new GetClientSecretTokenRequest(); getClientSecretTokenRequest.ClientId = Constants.ClientId; ApiController apiController = new ApiController(); GetClientSecretTokenResponse clientSecretTokenResponse = apiController.GetClientSecretToken(getClientSecretTokenRequest); GetAccessTokenRequest tokenRequest = new GetAccessTokenRequest(); tokenRequest.client_id = clientSecretTokenResponse.apiConsumerId; tokenRequest.client_secret = clientSecretTokenResponse.apiConsumerSecret; tokenRequest.grant_type = "client_credentials"; ApiToken apiToken = apiController.GetAccessToken(tokenRequest); token = apiToken.access_token; CustomerLogin loginCustomer = new CustomerLogin(); loginCustomer.email = loginEmailAddress.Text; loginCustomer.Password = loginPassword.Text; loginCustomer.clientId = Constants.ClientId; loginCustomer.ClientTime = DateTime.Now; LoginController loginController = new LoginController(); cutomerAuthContext = loginController.CheckLogin(loginCustomer, token); if (cutomerAuthContext.CustomerId > 0) { portalDetailsMobileRequest.customerId = cutomerAuthContext.CustomerId; updateConstantCustomerDetails(portalDetailsMobileRequest); } }); } finally { busy = false; loginSpinner.IsRunning = false; loginSpinnerFrame.IsVisible = false; LoginButton.IsVisible = true; if (cutomerAuthContext.CustomerId > 0) { Constants.IsRegisteredandNotLogin = false; Constants.cutomerAuthContext = cutomerAuthContext; if (App.Current.Properties.ContainsKey("currentToken")) { App.Current.Properties["currentToken"] = token; } else { App.Current.Properties.Add("currentToken", token); } if (Constants.customerDetails != null && Constants.customerDetails.IsBlackListed) { await PopupNavigation.Instance.PushAsync(new Error_popup(" Sorry, your account has been blacklisted.")); } //if (cutomerAuthContext.IsEmailConfirmed) else if (cutomerAuthContext.IsEmailConfirmed) { if (App.Current.Properties.ContainsKey("CustomerId")) { App.Current.Properties["CustomerId"] = cutomerAuthContext.CustomerId; } else { App.Current.Properties.Add("CustomerId", cutomerAuthContext.CustomerId); } Type type = typeof(WelcomPage); //if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 2].GetType() == type) //{ // await Navigation.PushAsync(new HomePage()); //} //else if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 2].GetType() == typeof(OtherInformationPage)) //{ // if (Navigation.NavigationStack[Navigation.NavigationStack.Count - 3].GetType() == type) // { // await Navigation.PushAsync(new HomePage()); // } // else // { // Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]); // await Navigation.PushAsync(new HomePage()); // } //} //else //{ //if (Navigation.NavigationStack.Count < 3) //{ // await Navigation.PushAsync(new HomePage()); //} //else //{ // await Navigation.PopAsync(); //} if (fromVal == 1) { await Navigation.PopModalAsync(); } else { await Navigation.PushModalAsync(new HomePage()); } //} } else { if (fromVal == 1) { await Navigation.PushModalAsync(new ConfirmEmailRequest(cutomerAuthContext.CustomerId, MaxVonGrafKftMobileModel.Constants.emailConfirmationType.LogIn, fromVal)); } else { await Navigation.PushModalAsync(new ConfirmEmailRequest(cutomerAuthContext.CustomerId, MaxVonGrafKftMobileModel.Constants.emailConfirmationType.LogIn)); } //gobackAsync(); } } else { await PopupNavigation.Instance.PushAsync(new Error_popup("Login failed. Please try again.")); loginPassword.Text = null; errorLabel.IsVisible = false; } } } } }