Esempio n. 1
0
        async void AcceptButton_Clicked(object sender, EventArgs e)
        {
            AcceptButton.IsEnabled = false;

            var phone = PhoneHelper.ValidPhoneNumber(PhoneTB.Text);

            if (phone == 0)
            {
                return;
            }

            AppBusyPage.Show("Авторизация...");
            App.ClearTestLog();
            var res = await ApiService.Auth(PhoneTB.Text, PassTB.Text);

            await App.ShowTestLog(this);

            if (!string.IsNullOrEmpty(res))
            {
                AppBusyPage.Close();
                await DisplayAlert("Ошибка", res, "ОК");

                AcceptButton.IsEnabled = true;
                return;
            }
            if (autoLogin)
            {
                //AppData.Crew.Online = lastOnline;
                AppData.Crew.CrewTypeId = lastCrewTypeId;
            }

            AppBusyPage.Show("Получение списка типов бригад...");
            App.ClearTestLog();
            res = await ApiService.GetCrewTypes();

            await App.ShowTestLog(this);

            if (!string.IsNullOrEmpty(res))
            {
                AppBusyPage.Close();
                await DisplayAlert("Ошибка", res, "ОК");

                AcceptButton.IsEnabled = true;
                return;
            }

            if ((AppData.CrewTypes?.Count ?? 0) == 0)
            {
                AppBusyPage.Close();
                await DisplayAlert("Ошибка", "Не удалось получить список типов бригад", "ОК");

                AcceptButton.IsEnabled = true;
                return;
            }

            AppBusyPage.Close();
            sctPage = new SelectCrewTypePage();
            sctPage.Disappearing += CrewTypePopup_Disappearing;
            await PopupNavigation.Instance.PushAsync(sctPage, true);
        }
Esempio n. 2
0
        public async void Login(string email, string password)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                await App.AppCurrent.MainPage.DisplayAlert(AppResource.alertInvalidFields, AppResource.alertFillEmailPassword, AppResource.textOk);

                return;
            }

            Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoading);
            ApiService service = new ApiService();

            try
            {
                LoginVm loginVm = new LoginVm();

                loginVm.Email    = email.Trim();
                loginVm.Password = password;

                string deviceType = "";

                switch (Device.OS)
                {
                case TargetPlatform.Other:
                    deviceType = "Other";
                    break;

                case TargetPlatform.iOS:
                    deviceType = "ios";
                    break;

                case TargetPlatform.Android:
                    deviceType = "android";
                    break;

                case TargetPlatform.WinPhone:
                    deviceType = "WindowsPhone";
                    break;

                case TargetPlatform.Windows:
                    deviceType = "Windows";
                    break;

                default:
                    deviceType = "None";
                    break;
                }


                loginVm.PushId    = App.AppDeviceId;
                loginVm.PushToken = App.AppDeviceToken;
                loginVm.Latitude  = App.AppCurrent.Latitude;
                loginVm.Longitude = App.AppCurrent.Longitude;

                decimal offset = (decimal)DateTimeOffset.Now.Offset.TotalHours;

                var userJson    = JsonConvert.SerializeObject(loginVm);
                var resultToken = await service.Auth(loginVm.Email, loginVm.Password);

                var token  = JsonConvert.DeserializeObject <AuthAcessToken>(resultToken);
                var result = await service.GetMe(loginVm.PushId, loginVm.PushToken, loginVm.Latitude, loginVm.Longitude, token.AcessToken);

                var user = JsonConvert.DeserializeObject <User>(result);

                App.AppCurrent.StoreUser(user.Id, user.Name, user.Photo, user.UserRole, user.CompanyId, false, offset, user.DesirableLanguage, token.AcessToken);

                App.AppCurrent.FirstLogin = true;


                if (Helpers.Settings.DisplayUserRole == Enums.UserRole.Manager.ToString())
                {
                    var resultCompanies = await service.GetAsync("company/getcompaniesbymanagerid?id=" + Helpers.Settings.DisplayUserId);

                    var list = JsonConvert.DeserializeObject <List <Company> >(resultCompanies);

                    if (list.Count >= 1)
                    {
                        Helpers.Settings.DisplayHasLocation = list.FirstOrDefault().HasLocation;
                        App.AppCurrent.CompanyCulture       = list.FirstOrDefault().CurrencyType.ToCultureInfo();
                    }

                    await App.AppCurrent.ConfigureAppPhase();
                }
                else if (Helpers.Settings.DisplayUserRole == Enums.UserRole.Employee.ToString())
                {
                    if (user.Company != null && user.Company.HasLocation)
                    {
                        Helpers.Settings.DisplayHasLocation = true;
                    }

                    App.AppCurrent.CompanyCulture = user.Company.CurrencyType.ToCultureInfo();

                    await App.AppCurrent.ConfigureAppPhase();
                }
                else
                {
                    await App.AppCurrent.ConfigureAppPhase();
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert(AppResource.alertAlert, ex.Message, AppResource.textOk);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }
Esempio n. 3
0
        private async void OnVisitanteTapped(object sender, EventArgs e)
        {
            Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoging);
            ApiService service = new ApiService();

            try
            {
                LoginVm loginVm = new LoginVm();

                loginVm.Email    = "guest";
                loginVm.Password = "******";

                string deviceType = "";

                switch (Device.OS)
                {
                case TargetPlatform.Other:
                    deviceType = "Other";
                    break;

                case TargetPlatform.iOS:
                    deviceType = "ios";
                    break;

                case TargetPlatform.Android:
                    deviceType = "android";
                    break;

                case TargetPlatform.WinPhone:
                    deviceType = "WindowsPhone";
                    break;

                case TargetPlatform.Windows:
                    deviceType = "Windows";
                    break;

                default:
                    deviceType = "None";
                    break;
                }


                loginVm.PushId    = App.AppDeviceId;
                loginVm.PushToken = App.AppDeviceToken;
                loginVm.Latitude  = App.AppCurrent.Latitude;
                loginVm.Longitude = App.AppCurrent.Longitude;

                decimal offset   = (decimal)DateTimeOffset.Now.Offset.TotalHours;
                var     userJson = JsonConvert.SerializeObject(loginVm);
                //var result = await service.PostAsync(userJson, "user/login");
                var resultToken = await service.Auth(loginVm.Email, loginVm.Password);

                var token  = JsonConvert.DeserializeObject <AuthAcessToken>(resultToken);
                var result = await service.GetMe(loginVm.PushId, loginVm.PushToken, loginVm.Latitude, loginVm.Longitude, token.AcessToken);

                var user = JsonConvert.DeserializeObject <User>(result);

                //App.AppCurrent.StoreUser(user.Id, user.Name, user.Photo, user.UserRole, user.CompanyId);
                App.AppCurrent.StoreUser(user.Id, user.Name, user.Photo, user.UserRole, user.CompanyId, false, offset, user.DesirableLanguage, token.AcessToken);

                await App.AppCurrent.ConfigureAppPhase();
            }
            catch (Exception ex)
            {
                this.DisplayAlert(MocoApp.Resources.AppResource.alertAlert, ex.Message, AppResource.textOk);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }
        private async void OnRegisterTapped(object sender, EventArgs e)
        {
            if (!CheckInfos())
            {
                return;
            }

            ApiService service = new ApiService();

            try
            {
                Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoading);

                Client user = new Client();

                if (App.AppCurrent.User != null && !string.IsNullOrEmpty(App.AppCurrent.User.Photo))
                {
                    user.Photo = App.AppCurrent.User.Photo;
                }

                if (imageStream != null)
                {
                    //faz upload da imagem
                    Helpers.Settings.DisplayUserPhoto = await service.UploadImage(imageStream);

                    user.Photo = Helpers.Settings.DisplayUserPhoto;
                }

                string deviceType = "";

                switch (Device.OS)
                {
                case TargetPlatform.Other:
                    deviceType = "Other";
                    break;

                case TargetPlatform.iOS:
                    deviceType = "ios";
                    break;

                case TargetPlatform.Android:
                    deviceType = "android";
                    break;

                case TargetPlatform.WinPhone:
                    deviceType = "WindowsPhone";
                    break;

                case TargetPlatform.Windows:
                    deviceType = "Windows";
                    break;

                default:
                    deviceType = "None";
                    break;
                }


                user.Name              = txtName.Text;
                user.Cellphone         = txtPhone.Text;
                user.Email             = txtEmail.Text;
                user.DeviceToken       = App.AppDeviceToken;
                user.DeviceType        = deviceType;
                user.CityName          = txtCity.Text;
                user.Password          = txtPassword.Text;
                user.Latitude          = App.AppCurrent.Latitude;
                user.Longitude         = App.AppCurrent.Longitude;
                user.DesirableLanguage = (pckIdioma.SelectedIndex + 1).ToString();
                user.Surname           = txtSurname.Text;


                var json   = JsonConvert.SerializeObject(user);
                var result = await service.PostAsync(json, "client/register");

                var userRetorno = JsonConvert.DeserializeObject <User>(result);

                var resultToken = await service.Auth(user.Email, user.Password);

                var token = JsonConvert.DeserializeObject <AuthAcessToken>(resultToken);

                App.AppCurrent.StoreUser(userRetorno.Id, userRetorno.Name, userRetorno.Photo, Enums.UserRole.Client, "", false, 0, user.DesirableLanguage, token.AcessToken);

                await App.AppCurrent.ConfigureAppPhase();
            }
            catch (Exception ex)
            {
                this.DisplayAlert(MocoApp.Resources.AppResource.alertAlert, ex.Message, AppResource.textOk);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }
Esempio n. 5
0
        }//c_tor

        //обработка нажатия на кнопку входа
        private async void Bt_sign_in_Clicked(object sender, EventArgs e)
        {
            
            try
            {
                ai_ind.IsVisible = true;
                bt_sign_in.IsVisible = false;
                bt_register.IsVisible = false;
                //задаем url отправки
                ApiService api = new ApiService
                {
                    Url = "https://www.exsales.net/api/v1/user/auth"
                };

                //добавляем параметы к запросу
                Dictionary<string, string> data = new Dictionary<string, string>();
                //добавляем почту
                data.Add("email", ApiService.StringUrlEncode(en_login.Text));

                //добавляем роль
                data.Add("password", en_password.Text);
                api.AddParams(data);

                if (!String.IsNullOrEmpty(en_login.Text) && !String.IsNullOrEmpty(en_password.Text))
                {
                    //отправляем запрос и ждем результат
                    JObject res = await api.Auth();
              //      await DisplayAlert("Message", res/*bool.Parse(res["status"].ToString()).ToString()*/, "OK");
               //     получаем ключ авторизации пользователя
                    if (bool.Parse(res["status"].ToString()))
                    {
                        auth_key = res["auth_key"].ToString();
                        //await DisplayAlert("Message", auth_key, "OK");
                        await Navigation.PushModalAsync(new AccountPage(res), true);
                    }
                    else
                    {
#if (DEBUG)
                        await DisplayAlert("Warning", "Ошибка авторизации. Проверьте указанные данные!", "OK");

#else
                        await DisplayAlert("Warning", LangResources.StartPageEnterMessageWarning, "OK"); 
#endif
                    }
                }
                else
                {
                    await DisplayAlert("Warning", "Проверьте указанные данные!", "OK");
                }

                //выводим ответ

            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
            finally
            {
                ai_ind.IsVisible = false;
                bt_sign_in.IsVisible = true;
                bt_register.IsVisible = true;
            }
        }