Ejemplo n.º 1
0
        public async Task CallWebserviceLoginUser()
        {
            if (AppStatics.CheckInternetConnection())
            {
                try
                {
                    AppStatics.Loading(loading, true);
                    List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >();
                    values.Add(new KeyValuePair <string, string>("username", txtbxEmail.Text));

                    #region  Password Encryption

                    byte[] PasswordBytes        = Encoding.UTF8.GetBytes(txtbxPassword.Text);
                    string base64StringPassword = Convert.ToBase64String(PasswordBytes);


                    var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                    var stringChars = new char[8];
                    var random      = new Random();

                    for (int i = 0; i < stringChars.Length; i++)
                    {
                        stringChars[i] = chars[random.Next(chars.Length)];
                    }

                    var    finalString = new String(stringChars);
                    string EncryptPass = finalString + base64StringPassword + finalString;

                    byte[] EncryptedPasswordBytes  = Encoding.UTF8.GetBytes(EncryptPass);
                    string SendEncryptedStringPass = Convert.ToBase64String(EncryptedPasswordBytes);
                    #endregion

                    values.Add(new KeyValuePair <string, string>("password", SendEncryptedStringPass));

                    var response = await VadodaraByFoot.ServiceLayer.CallWebservice.GetResponse_Post <RootObjectUserLogin>(WebServiceURL.Url_userLogin, values);

                    AppStatics.Loading(loading, false);
                    if (response != null)
                    {
                        if (response._resultflag == "1")
                        {
                            UserData _userdata = new UserData()
                            {
                                username    = response.username,
                                name        = response.name,
                                first_name  = response.first_name,
                                last_name   = response.last_name,
                                nickname    = response.nickname,
                                slug        = response.slug,
                                URL         = response.URL,
                                avatar      = response.avatar,
                                mobile      = response.mobile,
                                description = response.description,
                                registered  = response.registered,
                                email       = response.email,
                                ID          = response.ID
                            };
                            AppStatics.SaveIsolatedData(_userdata);

                            await Navigation.PopAsync();
                        }
                        else
                        {
                            await DisplayAlert(AppResources.AppResources.LMessage, response.message, AppResources.AppResources.LOk);
                        }
                    }
                    else
                    {
                        await DisplayAlert(AppResources.AppResources.LError, AppResources.AppResources.LWebserverNotResponding, AppResources.AppResources.LOk);
                    }
                }
                catch (Exception e)
                {
                    AppStatics.Loading(loading, false);
                    await DisplayAlert(AppResources.AppResources.LError, AppResources.AppResources.LSomethingWentWrong, AppResources.AppResources.LOk);
                }
            }
            else
            {
                AppStatics.Loading(loading, false);
                await DisplayAlert(AppResources.AppResources.LError, AppResources.AppResources.LNoInternetConnection, AppResources.AppResources.LOk);
            }
        }