public AppViewModel()
        {
            _context = new RealEstateContext();

            if (!_context.Database.Exists())
            {
                _context.RunSeeds();
            }

            AppartmentsVM = new AppartmentsViewModel(_context);
            ClientsVM     = new ClientsViewModel(_context);
            DealsVM       = new DealsViewModel(_context);
            UsersVM       = new UsersViewModel(_context);
            StatsVM       = new StatsViewModel(_context);

            AuthModal = new AuthModal();

            ChangeViewCommand   = new RelayCommand <object>(ChangeView);
            GetDealsCommand     = new RelayCommand <object>(GetDeals);
            AuthenticateCommand = new RelayCommand <object>(Authenticate);
            LogoutCommand       = new RelayCommand <object>(Logout);

            IsReloadOn    = true;
            SwitchCommand = new RelayCommand <object>(_ => IsReloadOn = !IsReloadOn);
        }
Beispiel #2
0
        /// <summary>
        /// This is the go-to method to handle the authorization and sign-in OAuth flow.
        /// It tries to fetch the google auth token from cache, and if it can't it will try to
        /// fetch it using a refresh token, if that's not possible it will prompt the user to
        /// authorize the application resulting in a google auth token.
        /// It will then use this google auth token to try to sign into firebase, and if that
        /// doesn't work the first time it will retry a second time after having the using re-authorize
        /// the application. (It does this since the refresh token could have been revoked.)
        /// </summary>
        /// <returns><c>true</c> if sign in was successful, <c>false</c> otherwise.</returns>
        public async Task <bool> SignInPromptUserIfNecessary()
        {
            try
            {
                string googleToken;

                using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Google"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Google", !string.IsNullOrEmpty(GoogleClient.accessToken))))
                {
                    // Try to fetch google token without prompting the user (authorizing).
                    if (await GoogleClient.Client.GetAccessTokenWithoutAuthentication())
                    {
                        googleToken = GoogleClient.accessToken;
                    }
                    else // Prompt the user to authorize the application.
                    {
                        googleToken = await AuthModal.AuthorizeAndGetGoogleAccessTokenAsync();
                    }
                }

                var firebaseSignInSuccess = false;
                using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Firebase"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Firebase", firebaseSignInSuccess)))
                {
                    // Try to sign into firebase with the googleToken.
                    firebaseSignInSuccess = await SignInWithFirebaseAsync(googleToken);
                }
                if (!firebaseSignInSuccess)
                {
                    // Could not log into firebase. Could be caused by a refresh token revocation, try re-authenticating with Google.
                    googleToken = await AuthModal.AuthorizeAndGetGoogleAccessTokenAsync();

                    using (new DisposableLogger(() => AuthLog.GetAccessTokenBegin("Firebase"), (sw) => AuthLog.GetAccessTokenEnd(sw, "Firebase", firebaseSignInSuccess)))
                    {
                        // Retry firebase login.
                        firebaseSignInSuccess = await SignInWithFirebaseAsync(googleToken);

                        // Return result.
                        return(firebaseSignInSuccess);
                    }
                }

                return(firebaseSignInSuccess);
            }
            catch (Exception e)
            {
                // Log Exception.
                LifecycleLog.Exception(e);
                return(false);
            }
        }
Beispiel #3
0
        public ResponseModel Login([FromBody] AuthModal req)
        {
            ResponseModel response = new ResponseModel();

            response.Message = "Unauthorized User";
            response.Status  = false;
            response.Data    = 0;

            //PersonalInfoModel info = new PersonalInfoModel();

            var user = _repo.Login(req.Email, req.Pwd);

            if (user != null)
            {
                response.Message = "Authorized User";
                response.Status  = true;
                response.Data    = user;
            }

            return(response);
        }