Example #1
0
        public BaseViewModel(IUserDialogs userDialogs,
                             IMvxMessenger mvxMessenger, AppHelper appHelper)
        {
            _userDialogs  = userDialogs;
            _mvxMessenger = mvxMessenger;
            _appHelper    = appHelper;
            {}

            SignOutCommand = ReactiveCommand
                             .CreateFromObservable <Unit, bool>((_) =>
                                                                _appHelper.RequestConfirmation(AppResources.Profile_Confirm_SignOut)
                                                                .Where((confirmed) => confirmed));

            SignOutCommand.ThrownExceptions.Subscribe(HandleExceptions);

            SignOutCommand.Subscribe((_) =>
            {
                if (Settings.Current.DeviceRegistered)
                {
                    Mvx.Resolve <INotificationService>()?.unsubscribeDevice().Subscribe((result) => {
                        Settings.Current.DeviceRegistered = false;
                        Debug.WriteLine("Device successfully removed from device group ");
                    });
                }

                Bullytect.Core.Config.Settings.AccessToken = null;
                ShowViewModel <AuthenticationViewModel>(new AuthenticationViewModel.AuthenticationParameter()
                {
                    ReasonForAuthentication = AuthenticationViewModel.SIGN_OUT
                });
            });
        }
Example #2
0
        public UserPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService, IGoogleService googleService, IFacebookService facebookService, IAppleService appleService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;
            _googleService     = googleService;
            _facebookService   = facebookService;
            _appleService      = appleService;

            _multiFactorService = new MultiFactorService(this);

            Title = "User";

            var user = _auth.CurrentUser;

            Update(user);

            Name        = new ReactivePropertySlim <string>(user?.DisplayName);
            Email       = new ReactivePropertySlim <string>(user?.Email);
            PhoneNumber = new ReactivePropertySlim <string>(user?.PhoneNumber);

            _isEnrolledMultiFactor.Value = user.MultiFactor.EnrolledFactors.Any();

            UpdateNameCommand.Subscribe(UpdateName);
            UpdateEmailCommand.Subscribe(UpdateEmail);
            UpdatePhoneNumberCommand.Subscribe(UpdatePhoneNumber);
            SignOutCommand.Subscribe(SignOut);
            LinkOrUnlinkWithGoogleCommand.Subscribe(() => IsLinkedWithGoogle.Value ? UnlinkWithProvider("google.com") : LinkWithGoogle());
            LinkOrUnlinkWithTwitterCommand.Subscribe(() => IsLinkedWithTwitter.Value ? UnlinkWithProvider("twitter.com") : LinkWithProvider("twitter.com"));
            LinkOrUnlinkWithFacebookCommand.Subscribe(() => IsLinkedWithFacebook.Value ? UnlinkWithProvider("facebook.com") : LinkWithFacebook());
            LinkOrUnlinkWithGitHubCommand.Subscribe(() => IsLinkedWithGitHub.Value ? UnlinkWithProvider("github.com") : LinkWithProvider("github.com"));
            LinkOrUnlinkWithYahooCommand.Subscribe(() => IsLinkedWithYahoo.Value ? UnlinkWithProvider("yahoo.com") : LinkWithProvider("yahoo.com"));
            LinkOrUnlinkWithMicrosoftCommand.Subscribe(() => IsLinkedWithMicrosoft.Value ? UnlinkWithProvider("microsoft.com") : LinkWithProvider("microsoft.com"));
            LinkOrUnlinkWithAppleCommand.Subscribe(() => IsLinkedWithApple.Value ? UnlinkWithProvider("apple.com") : LinkWithApple());
            EnrollOrUnenrollMultiFactorCommand.Subscribe(() => IsEnrolledMultiFactor.Value ? UnenrollMultiFactor() : EnrollMultiFactor());
            DeleteCommand.Subscribe(Delete);
        }
        public UserPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService, IAuthService authService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;
            _authService       = authService;

            Title = "User";

            _user.Value = CrossFirebaseAuth.Current.Instance.CurrentUser;

            Name        = new ReactivePropertySlim <string>(_user.Value?.DisplayName);
            Email       = new ReactivePropertySlim <string>(_user.Value?.Email);
            PhoneNumber = new ReactivePropertySlim <string>(_user.Value?.PhoneNumber);

            IsLinkedWithGoogle = _user.Where(user => user != null)
                                 .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.GoogleAuthProvider.ProviderId) != null)
                                 .ToReadOnlyReactivePropertySlim();

            IsLinkedWithTwitter = _user.Where(user => user != null)
                                  .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.TwitterAuthProvider.ProviderId) != null)
                                  .ToReadOnlyReactivePropertySlim();

            IsLinkedWithFacebook = _user.Where(user => user != null)
                                   .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.FacebookAuthProvider.ProviderId) != null)
                                   .ToReadOnlyReactivePropertySlim();

            IsLinkedWithGitHub = _user.Where(user => user != null)
                                 .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.GitHubAuthProvider.ProviderId) != null)
                                 .ToReadOnlyReactivePropertySlim();

            _user.Where(user => user != null)
            .Select(user => user.DisplayName)
            .DistinctUntilChanged()
            .Subscribe(name => Name.Value = name);

            _user.Where(user => user != null)
            .Select(user => user.Email)
            .DistinctUntilChanged()
            .Subscribe(email => Email.Value = email);

            _user.Where(user => user != null)
            .Select(user => user.PhoneNumber)
            .DistinctUntilChanged()
            .Subscribe(phoneNumber => PhoneNumber.Value = phoneNumber);

            UpdateNameCommand.Subscribe(UpdateName);
            UpdateEmailCommand.Subscribe(UpdateEmail);
            UpdatePhoneNumberCommand.Subscribe(UpdatePhoneNumber);
            SignOutCommand.Subscribe(SignOut);
            LinkOrUnlinkWithGoogleCommand.Subscribe(() => IsLinkedWithGoogle.Value ? UnlinkWithGoogle() : LinkWithGoogle());
            LinkOrUnlinkWithTwitterCommand.Subscribe(() => IsLinkedWithTwitter.Value ? UnlinkWithTwitter() : LinkWithTwitter());
            LinkOrUnlinkWithFacebookCommand.Subscribe(() => IsLinkedWithFacebook.Value ? UnlinkWithFacebook() : LinkWithFacebook());
            LinkOrUnlinkWithGitHubCommand.Subscribe(() => IsLinkedWithGitHub.Value ? UnlinkWithGitHub() : LinkWithGitHub());
            DeleteCommand.Subscribe(Delete);
        }