Ejemplo n.º 1
0
        private async void RegisterButton_OnClicked(object sender, EventArgs e)
        {
            var device   = Resolver.Resolve <IDevice>();
            var oNetwork = device.Network; // Create Interface to Network-functions
            var xx       = oNetwork.InternetConnectionStatus() == NetworkStatus.NotReachable;

            if (xx == true)
            {
                await DisplayAlert(AppResources.Label_Error, AppResources.Label_CheckYourInternetConnection, AppResources.Label_OK);
            }
            else
            {
                var clickresult = "true";
                if (Settings.AcceptTerms_Display)
                {
                    var result = await DisplayAlert(AppResources.Label_Terms, AppResources.Label_Terms_LongText, AppResources.Label_Accept_Terms, AppResources.Label_Dot_Agree);

                    if (result)
                    {
                        clickresult = "true";
                    }
                    else
                    {
                        clickresult = "false";
                    }
                }


                if (clickresult == "true")
                {
                    var StatusApiKey = "";
                    using (var client = new HttpClient())
                    {
                        UserDialogs.Instance.ShowLoading(AppResources.Label_Loading, MaskType.Gradient);
                        var SettingsValues = new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair <string, string>("windows_app_version", Settings.Version),
                        });

                        var responseSettings =
                            await client.PostAsync(Settings.Website + "/app_api.php?type=get_settings", SettingsValues);

                        responseSettings.EnsureSuccessStatusCode();
                        string jsonSettings = await responseSettings.Content.ReadAsStringAsync();

                        var    dataSettings      = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonSettings);
                        string apiStatusSettings = dataSettings["api_status"].ToString();
                        if (apiStatusSettings == "200")
                        {
                            JObject settings = JObject.FromObject(dataSettings["config"]);

                            if (Settings.API_ID == settings["widnows_app_api_id"].ToString() &&
                                Settings.API_KEY == settings["widnows_app_api_key"].ToString())
                            {
                                StatusApiKey = "true";
                            }
                            else
                            {
                                StatusApiKey = "false";
                            }

                            Settings.Onesignal_APP_ID = settings["push_id"].ToString();
                            OneSignalNotificationController.RegisterNotificationDevice();

                            if (settings["footer_background"].ToString() != "#aaa" || StatusApiKey == "false")
                            {
                                await DisplayAlert("FATTAL ERROR", "1- API-KEY And API-ID are incorrect or" + MimeType.Wrong + MimeType.Wrong2, "OK");

                                UserDialogs.Instance.HideLoading();
                                return;
                            }
                        }
                        if (StatusApiKey == "true")
                        {
                            string Gender = "male";


                            using (var client2 = new HttpClient())
                            {
                                Settings.Session = GetTimestamp(DateTime.Now);
                                var formContent = new FormUrlEncodedContent(new[]
                                {
                                    new KeyValuePair <string, string>("username", usernameEntry.Text),
                                    new KeyValuePair <string, string>("password", passwordEntry.Text),
                                    new KeyValuePair <string, string>("confirm_password", passwordConfirmEntry.Text),
                                    new KeyValuePair <string, string>("email", EmailEntry.Text),
                                    new KeyValuePair <string, string>("gender", Gender),
                                    new KeyValuePair <string, string>("device_id", Settings.Device_ID),
                                    new KeyValuePair <string, string>("s", Settings.Session)
                                });

                                var response =
                                    await
                                    client2.PostAsync(
                                        Settings.Website + "/app_api.php?application=phone&type=user_registration", formContent);

                                response.EnsureSuccessStatusCode();
                                string json = await response.Content.ReadAsStringAsync();

                                var    data      = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                                string apiStatus = data["api_status"].ToString();
                                if (apiStatus == "200")
                                {
                                    var successtype = data["success_type"].ToString();

                                    SQL_Commander.ClearContactTable();


                                    if (successtype == "registered")
                                    {
                                        //Settings.Cookie = data["cookie"].ToString();
                                        Settings.User_id = data["user_id"].ToString();
                                        Settings.Session = data["session_id"].ToString();

                                        LoginTableDB LoginData = new LoginTableDB();
                                        LoginData.Password = passwordEntry.Text;
                                        LoginData.Username = usernameEntry.Text;
                                        LoginData.Session  = Settings.Session;
                                        LoginData.UserID   = Settings.User_id;
                                        // LoginData.Cookie = Settings.Cookie;
                                        LoginData.Status = "Registered";
                                        SQL_Commander.InsertLoginCredentials(LoginData);


                                        UserDialogs.Instance.HideLoading();

                                        try
                                        {
                                            await Navigation.PushAsync(new UploudPicPage());
                                        }
                                        catch (Exception)
                                        {
                                            await Navigation.PushModalAsync(new UploudPicPage());
                                        }
                                    }
                                    else if (successtype == "verification")
                                    {
                                        var Message = data["message"].ToString();
                                        UserDialogs.Instance.HideLoading();
                                        await DisplayAlert(AppResources.Label_Error, Message, AppResources.Label_OK);
                                    }
                                }
                                else if (apiStatus == "400")
                                {
                                    JObject errors    = JObject.FromObject(data["errors"]);
                                    var     errortext = errors["error_text"].ToString();
                                    await DisplayAlert(AppResources.Label_Error, errortext, AppResources.Label_OK);

                                    UserDialogs.Instance.HideLoading();
                                }
                            }
                        }
                    }
                }
                else
                {
                    await DisplayAlert(AppResources.Label_Terms, AppResources.Label_Terms_notAccepted, AppResources.Label_OK);
                }
            }
        }
Ejemplo n.º 2
0
        public App()
        {
            L10n.SetLocale();
            var netLanguage = DependencyService.Get <ILocale>().GetCurrent();

            AppResources.Culture = new CultureInfo(netLanguage);

            SQL_Entity.Connect();



            //Data.ClearLoginCredentialsList();
            var CredentialStatus = SQL_Commander.GetLoginCredentialsStatus();


            InitializeComponent();


            if (CredentialStatus == "Active")
            {
                var Credential = SQL_Commander.GetLoginCredentials("Active");
                Settings.Session          = Credential.Session;
                Settings.User_id          = Credential.UserID;
                Settings.Username         = Credential.Username;
                Settings.Onesignal_APP_ID = Credential.Onesignal_APP_ID;
                if (Credential.NotificationLedColor != "")
                {
                    Settings.NotificationVibrate      = Credential.NotificationVibrate;
                    Settings.NotificationSound        = Credential.NotificationSound;
                    Settings.NotificationPopup        = Credential.NotificationPopup;
                    Settings.NotificationLedColor     = Credential.NotificationLedColor;
                    Settings.NotificationLedColorName = Credential.NotificationLedColor;
                }
                else
                {
                    Credential.NotificationVibrate      = true;
                    Credential.NotificationLedColor     = Settings.MainColor;
                    Credential.NotificationLedColorName = AppResources.Label_Led_Color;
                    Credential.NotificationSound        = true;
                    Credential.NotificationPopup        = true;
                    SQL_Commander.UpdateLoginCredentials(Credential);
                    Settings.NotificationVibrate      = true;
                    Settings.NotificationSound        = true;
                    Settings.NotificationPopup        = true;
                    Settings.NotificationLedColor     = Settings.MainColor;
                    Settings.NotificationLedColorName = AppResources.Label_Led_Color;
                }


                //Start Onesignal
                OneSignalNotificationController.RegisterNotificationDevice();
                var navigationPage = new NavigationPage(new MasterMain())
                {
                };
                navigationPage.BarBackgroundColor = Color.FromHex(Settings.MainPage_HeaderBackround_Color);
                navigationPage.BarTextColor       = Color.FromHex(Settings.MainPage_HeaderText_Color);
                navigationPage.Title   = Settings.MainPage_HeaderTextLabel;
                navigationPage.Padding = new Thickness(0, 0, 0, 0);
                MainPage = navigationPage;
            }
            else
            {
                if (CredentialStatus == "Registered")
                {
                    var Credential = SQL_Commander.GetLoginCredentials("Registered");
                    Settings.Session  = Credential.Session;
                    Settings.User_id  = Credential.UserID;
                    Settings.Username = Credential.Username;
                    MainPage          = new NavigationPage(new UploudPicPage());
                }
                else
                {
                    MainPage = new NavigationPage(new WelcomePage());
                }
            }
        }
Ejemplo n.º 3
0
        async void OnLoginClicked(object sender, EventArgs e)
        {
            try
            {
                var answer =
                    await
                    DisplayAlert(AppResources.Label_Security, AppResources.Label_WouldYouLikeToSaveYourPassword,
                                 AppResources.Label_Yes, AppResources.Label_NO);

                var device   = Resolver.Resolve <IDevice>();
                var oNetwork = device.Network; // Create Interface to Network-functions
                var xx       = oNetwork.InternetConnectionStatus() == NetworkStatus.NotReachable;
                if (xx == true)
                {
                    await DisplayAlert(AppResources.Label_Error, AppResources.Label_CheckYourInternetConnection,
                                       AppResources.Label_OK);
                }
                else
                {
                    var StatusApiKey = "";
                    using (var client = new HttpClient())
                    {
                        Settings.Session = RandomString(70);
                        UserDialogs.Instance.ShowLoading(AppResources.Label_Loading, MaskType.Gradient);
                        var SettingsValues = new FormUrlEncodedContent(new[]
                        {
                            new KeyValuePair <string, string>("windows_app_version", Settings.Version),
                        });

                        var responseSettings =
                            await client.PostAsync(Settings.Website + "/app_api.php?type=get_settings", SettingsValues);

                        responseSettings.EnsureSuccessStatusCode();
                        string jsonSettings = await responseSettings.Content.ReadAsStringAsync();

                        var    dataSettings      = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonSettings);
                        string apiStatusSettings = dataSettings["api_status"].ToString();
                        if (apiStatusSettings == "200")
                        {
                            JObject settings = JObject.FromObject(dataSettings["config"]);

                            if (Settings.API_ID == settings["widnows_app_api_id"].ToString() &&
                                Settings.API_KEY == settings["widnows_app_api_key"].ToString())
                            {
                                StatusApiKey = "true";
                            }
                            else
                            {
                                StatusApiKey = "false";
                            }

                            Settings.Onesignal_APP_ID = settings["push_id"].ToString();
                            OneSignalNotificationController.RegisterNotificationDevice();

                            if (settings["footer_background"].ToString() != "#aaa" || StatusApiKey == "false")
                            {
                                await DisplayAlert("Security", "1- API-KEY And API-ID are incorrect or" + MimeType.Wrong + MimeType.Wrong2, "Yes");

                                UserDialogs.Instance.HideLoading();
                                return;
                            }
                        }
                        if (StatusApiKey == "true")
                        {
                            var TimeZoneContry = "UTC";
                            try
                            {
                                var formContenst = new FormUrlEncodedContent(new[]
                                                                             { new KeyValuePair <string, string>("username", usernameEntry.Text), });

                                var responseTime = await client.PostAsync("http://ip-api.com/json/", formContenst);

                                string jsonres = await responseTime.Content.ReadAsStringAsync();

                                var datares = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonres);

                                string ResulttimeZone = datares["status"].ToString();
                                if (ResulttimeZone == "success")
                                {
                                    TimeZoneContry = datares["timezone"].ToString();
                                }
                            }
                            catch (Exception)
                            {
                            }

                            var formContent = new FormUrlEncodedContent(new[]
                            {
                                new KeyValuePair <string, string>("username", usernameEntry.Text),
                                new KeyValuePair <string, string>("password", passwordEntry.Text),
                                new KeyValuePair <string, string>("timezone", TimeZoneContry),
                                new KeyValuePair <string, string>("device_id", Settings.Device_ID),
                                new KeyValuePair <string, string>("s", Settings.Session)
                            });

                            var response =
                                await
                                client.PostAsync(
                                    Settings.Website + "/app_api.php?application=phone&type=user_login",
                                    formContent);

                            response.EnsureSuccessStatusCode();
                            string json = await response.Content.ReadAsStringAsync();

                            var    data      = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                            string apiStatus = data["api_status"].ToString();
                            if (apiStatus == "200")
                            {
                                Settings.User_id = data["user_id"].ToString();

                                SQL_Commander.ClearChatUserTable();


                                SQL_Commander.ClearContactTable();


                                await LoginUserFunctions.GetSessionProfileData(Settings.User_id, Settings.Session);

                                //await Functions.GetChatActivity(Settings.User_id, Settings.Session);


                                if (answer)
                                {
                                    LoginTableDB LoginData = new LoginTableDB();
                                    LoginData.ID               = 1;
                                    LoginData.Password         = passwordEntry.Text;
                                    LoginData.Username         = usernameEntry.Text;
                                    LoginData.Session          = Settings.Session;
                                    LoginData.UserID           = Settings.User_id;
                                    LoginData.Onesignal_APP_ID = Settings.Onesignal_APP_ID;
                                    LoginData.Status           = "Active";
                                    SQL_Commander.InsertLoginCredentials(LoginData);
                                }

                                UserDialogs.Instance.HideLoading();

                                try
                                {
                                    if (Settings.ReLogin)
                                    {
                                        //await Navigation.PopAsync();
                                        //await Navigation.PushAsync(new MasterMainSlidePage());
                                    }
                                    else
                                    {
                                        App.GetMainPage();
                                        UserDialogs.Instance.HideLoading();
                                    }
                                }
                                catch
                                {
                                    await Navigation.PopModalAsync();
                                }
                            }
                            else if (apiStatus == "400")
                            {
                                UserDialogs.Instance.HideLoading();
                                JObject errors    = JObject.FromObject(data["errors"]);
                                var     errortext = errors["error_text"].ToString();
                                var     ErrorMSG  =
                                    await
                                    DisplayAlert(AppResources.Label_Security, errortext, AppResources.Label_Retry,
                                                 AppResources.Label_Forget_My_Password);

                                if (ErrorMSG == false)
                                {
                                    await Navigation.PushModalAsync(new ForgetPasswordpage());
                                }
                            }
                        }
                        else
                        {
                            await DisplayAlert("Security", "1- API-KEY And API-ID are incorrect or" + MimeType.Wrong + MimeType.Wrong2, "Yes");

                            UserDialogs.Instance.HideLoading();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
                await DisplayAlert("Server ERROR", ex.ToString(), "Yes");
            }
        }