Beispiel #1
0
        public async Task LogIn()
        {
            try
            {
                _duringOperation = true;
                NotifyOfPropertyChange(() => CanLogIn);
                LoginInfoMessage = "Łączenie..";
                AuthenticatedUser user = await _apiHelper.Authenticate(UserName, Password);

                LoginInfoMessage = "";

                await _apiHelper.GetLoggedUserData(user.Access_Token);

                if (RemeberMe)
                {
                    WindowsCredentials.SaveLoginPassword(UserName, Password);
                }
                else
                {
                    WindowsCredentials.DeleteLoginPassword();
                }

                await _eventAggregator.PublishOnUIThreadAsync(new LogOnEvent(reloadNeeded : true), new CancellationToken());

                _duringOperation = false;
                NotifyOfPropertyChange(() => CanLogIn);
            }
            catch (Exception ex)
            {
                _logger.Error("Got exception", ex);
                LoginInfoMessage = ex.Message;
                _duringOperation = false;
                NotifyOfPropertyChange(() => CanLogIn);
            }
        }
Beispiel #2
0
        private async Task Login()
        {
            try
            {
                if (!IsBusy)
                {
                    IsBusy = true;
                    OnPropertyChanged(nameof(CanLogin));

                    AuthenticatedUser user = await _apiHelper.Authenticate(UserName, Password);

                    await _apiHelper.GetLoggedUserData(user.Access_Token);

                    if (Remember)
                    {
                        await SaveUserLoginPassword();
                    }
                    else
                    {
                        SecureStorage.RemoveAll();
                    }

                    MessagingService.Current.SendMessage(EventMessages.LogOnEvent);
                    Clear();
                }
            }
            catch (Exception ex)
            {
                //  _logger.Error("Got exception", ex);
                await Application.Current.MainPage.DisplayAlert("Błąd", ex.Message, "Ok");
            }
            finally
            {
                IsBusy = false;
                OnPropertyChanged(nameof(CanLogin));
            }
        }