Exemple #1
0
        public async Task Deslogar()
        {
            _tokensource = new CancellationTokenSource();

            Boolean answer;

            answer = await
                     this._messageService.ShowAlertChooseAsync(
                AppResources.ConfirmaSair
                , AppResources.cancelar
                , AppResources.Ok
                , null);

            if (answer == true)
            {
                await Task.Run(async() =>
                {
                    TokenDataStore store = new TokenDataStore();
                    store.Clean();

                    try
                    {
                        Bll_PushNotification classPushNotification = new Bll_PushNotification();
                        classPushNotification.DeletePushKey(_tokensource.Token);
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }

                    try
                    {
                        ModelLogin modelUsuario = new ModelLogin();
                        modelUsuario.Deslogar(_tokensource.Token);
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                });

                this._navigationService.NavigateToLogin();
            }
        }
Exemple #2
0
        private async void Login()
        {
            try
            {
                _view.ExibirLoad();
                if (String.IsNullOrEmpty(this.Email) || String.IsNullOrEmpty(this.Password))
                {
                    await this._messageService.ShowAlertAsync(
                        "E-mail e/ou Senha inválidos."
                        , AppResources.Erro
                        );

                    _view.EscondeLoad();
                    return;
                }

                _modelLogin  = new ModelLogin();
                _tokensource = new CancellationTokenSource();


                SetPreferences(Email, Password);


                Task.Run(async() =>
                {
                    try
                    {
                        String paramIdSistemaOperacional;

                        String strIndentificacao = String.Empty;

                        if (!String.IsNullOrEmpty(_app.Util.GetIdentifier()))
                        {
                            strIndentificacao = _app.Util.GetIdentifier();
                        }
                        else
                        {
                            strIndentificacao = CrossDeviceInfo.Current.Id;
                        }


                        if (Device.RuntimePlatform == Device.iOS)
                        {
                            paramIdSistemaOperacional =
                                ((byte)EnumSistemaOperacional.iOS).ToString();
                        }
                        else
                        {
                            paramIdSistemaOperacional =
                                ((byte)EnumSistemaOperacional.Android).ToString();
                        }



                        ServiceResult <Token> result =
                            await _modelLogin.Login(
                                this.Email
                                , this.Password
                                , App.Configuracao.CodigoEmpresa
                                , "10"
                                , strIndentificacao
                                , paramIdSistemaOperacional
                                , _tokensource.Token
                                );

                        if (!_tokensource.IsCancellationRequested)
                        {
                            if (String.IsNullOrWhiteSpace(result.MessageError))
                            {
                                Application.Current.Properties["UrlLogo"] = result.Data.UrlLogo;

                                UpdateToken(result.Data);

                                App.ListPainelSource = result.Data.LstDashBoard;


                                Bll_PushNotification classPushNotification = new Bll_PushNotification();
                                classPushNotification.RegistraPushKey(_tokensource.Token);


                                ////Pagina apos o Login
                                _navigationService.NavigateToPainel();

                                //_navigationService.NavigateToModulos();
                            }
                            else
                            {
                                _view.EscondeLoad();
                                _messageService.ShowAlertAsync(
                                    result.MessageError
                                    , AppResources.Erro
                                    );
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        _view.EscondeLoad();

                        ShowErrorAlert("Exception");
                    }
                }, _tokensource.Token);
            }
            catch
            {
                _view.EscondeLoad();
                ShowErrorAlert("Exception");
            }
        }