public AccountService(IIdentityService identityService, ISuspensionManagerState suspensionManagerState, ICredentialStore credentialStore)
 {
     _identityService = identityService;
     _suspensionManagerState = suspensionManagerState;
     _credentialStore = credentialStore;
     if (_suspensionManagerState != null)
     {
         if (_suspensionManagerState.SessionState.ContainsKey(ServerCookieHeaderKey))
         {
             _serverCookieHeader = _suspensionManagerState.SessionState[ServerCookieHeaderKey] as string;
         }
         if (_suspensionManagerState.SessionState.ContainsKey(SignedInUserKey))
         {
             _signedInUser = _suspensionManagerState.SessionState[SignedInUserKey] as UserInfo;
         }
         if (_suspensionManagerState.SessionState.ContainsKey(UserNameKey))
         {
             _userName = _suspensionManagerState.SessionState[UserNameKey].ToString();
         }
         if (_suspensionManagerState.SessionState.ContainsKey(PasswordKey))
         {
             _password = _suspensionManagerState.SessionState[PasswordKey].ToString();
         }
     }
 }
 public SignOutFlyoutViewModel(IAccountService accountService, INavigationService navigationService)
 {
     _accountService = accountService;
     _navigationService = navigationService;
     GoBackCommand = new DelegateCommand(() => GoBack());
     if (_accountService != null)
         _userInfo = _accountService.SignedInUser;
 }
 public SignInFlyoutViewModel(IAccountService accountService)
 {
     _accountService = accountService;
     if (accountService != null)
     {
         _lastSignedInUser = _accountService.SignedInUser;
     }
     // <snippet308>
     SignInCommand = DelegateCommand.FromAsyncHandler(SignInAsync, CanSignIn);
     // </snippet308>
     GoBackCommand = new DelegateCommand(() => GoBack());
 }
 public void RaiseUserChanged(UserInfo newUserInfo, UserInfo oldUserInfo)
 {
     UserChanged(this, new UserChangedEventArgs(newUserInfo, oldUserInfo));
 }
        public void SignOut()
        {
            var previousUser = _signedInUser;
            _signedInUser = null;
            _serverCookieHeader = null;

            // remove user from the CredentialStore, if any
            _credentialStore.RemovedSavedCredentials("KonaRI");

            RaiseUserChanged(_signedInUser, previousUser);
        }
 private void RaiseUserChanged(UserInfo newUserInfo, UserInfo oldUserInfo)
 {
     var handler = UserChanged;
     if (handler != null)
     {
         handler(this, new UserChangedEventArgs(newUserInfo, oldUserInfo));
     }
 }
        public async Task<bool> SignInUserAsync(string userName, string password, bool useCredentialStore)
        {
            try
            {
                // <snippet507>
                var result = await _identityService.LogOnAsync(userName, password);
                // </snippet507>

                UserInfo previousUser = _signedInUser;
                _signedInUser = result.UserInfo;

                // Save Server cookie & SignedInUser in the StateService
                _serverCookieHeader = result.ServerCookieHeader;
                _suspensionManagerState.SessionState[ServerCookieHeaderKey] = _serverCookieHeader;
                _suspensionManagerState.SessionState[SignedInUserKey] = _signedInUser;

                // Save username and password in state service
                _userName = userName;
                _password = password;
                _suspensionManagerState.SessionState[UserNameKey] = userName;
                _suspensionManagerState.SessionState[PasswordKey] = password;

                if (useCredentialStore)
                {
                    // Save credentials in the CredentialStore
                    _credentialStore.SaveCredentials("KonaRI", userName, password);
                }

                RaiseUserChanged(_signedInUser, previousUser);
                return true;
            }
            catch (HttpRequestException)
            {
                _serverCookieHeader = string.Empty;
                _suspensionManagerState.SessionState[ServerCookieHeaderKey] = _serverCookieHeader;
            }

            return false;
        }
 public UserChangedEventArgs(UserInfo newUserInfo, UserInfo oldUserInfo)
 {
     NewUserInfo = newUserInfo;
     OldUserInfo = oldUserInfo;
 }