Esempio n. 1
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);
        }