Пример #1
0
        private async void OnWebAccountRequested(WebAccountCommand cmd, WebAccountInvokedArgs args)
        {
            try
            {
                // Handle the different WebAccount actions...

                if (args.Action == WebAccountAction.Remove)
                {
                    // Signs the provider out.
                    PlatformBase.CurrentCore.Logger.Log(LogLevels.Information, "Web Account Manager - Remove account called");
                    await this.SignoutAsync(cmd.WebAccount.WebAccountProvider.Id);
                }
                else if (args.Action == WebAccountAction.Manage)
                {
                    // Display user management UI for this account
                    PlatformBase.CurrentCore.Logger.Log(LogLevels.Information, "Web Account Manager - Manage account called");
                }
            }
            catch (Exception ex)
            {
                PlatformBase.CurrentCore.Logger.LogError(ex, "Web Token request failed");
            }
            finally
            {
                this.Cleanup();
            }
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebAccountProvider web      = new WebAccountProvider("818", "MicrosoftAccount", new Uri("ms-appdata:///local/ProfilePicture.jpg"));
            WebAccount         account2 = new WebAccount(web, (string)ApplicationData.Current.LocalSettings.Values[StoredEmailKey], WebAccountState.Connected);

            if (account == null)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredEmailKey))
            {
                WebAccountCommand command = new WebAccountCommand(account2, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         await LogoffAndRemoveAccount();
     }
 }
Пример #4
0
        private async Task WebAccountInvokedHandlerCoreAsync(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            if (eventArgs.Action == WebAccountAction.Remove)
            {
                string loginProvider = command.WebAccount.WebAccountProvider.DisplayName;
                string providerKey   = command.WebAccount.UserName;

                RemoveLogin removeLogin = new RemoveLogin()
                {
                    LoginProvider = loginProvider,
                    ProviderKey   = providerKey
                };

                HttpResult result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.RemoveLoginAsync(removeLogin);
                }

                if (result.Succeeded)
                {
                    if (loginProvider == localProvider)
                    {
                        settings.ClearPasswordCredentials();
                    }
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
        }
Пример #5
0
        private void WebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            switch (eventArgs.Action)
            {
            case WebAccountAction.Remove:
                Cancel();
                LocalSettings.RemoveStorageValue(LOCAL_USER_NAME);
                LocalSettings.RemoveStorageValue(LOCAL_OAUTH_TOKEN);
                LoggedIn = WebAccountState.None;
                Disconnect();
                break;

            case WebAccountAction.Reconnect:
                Login();
                break;

            case WebAccountAction.More:
            case WebAccountAction.ViewDetails:
            case WebAccountAction.Manage:
                GoWebsite();
                break;

            default:
                break;
            }
        }
        private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccount account = await GetWebAccount();

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);

            e.WebAccountCommands.Add(command);
        }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         rootPage.NotifyUser("Removing account", NotifyType.StatusMessage);
         await LogoffAndRemoveAccount();
     }
 }
        /// <summary>
        /// This event is generated when the user clicks on Accounts command in settings pane. During this event, add your
        /// WebAccountProviderCommand, WebAccountCommand, CredentialCommand and  SettingsCommand objects to make them available to the
        /// AccountsSettingsPane UI.
        /// </summary>
        /// <param name="accountsSettingsPane">Instance that triggered the event.</param>
        /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
        private void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            var deferral = eventArgs.GetDeferral();

            //Add header text.
            eventArgs.HeaderText = "This is sample text. You can put a message here to give context to user. This section is optional.";

            //Add WebAccountProviders
            WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
            WebAccountProviderCommand facebookProviderCommand          = new WebAccountProviderCommand(facebookProvider, WebAccountProviderInvokedHandler);

            eventArgs.WebAccountProviderCommands.Add(facebookProviderCommand);
            WebAccountProviderCommand twitterProviderCommand = new WebAccountProviderCommand(twitterProvider, WebAccountProviderInvokedHandler);

            eventArgs.WebAccountProviderCommands.Add(twitterProviderCommand);

            //Add WebAccounts if available.
            WebAccountCommandInvokedHandler accountCmdHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);

            if (isFacebookUserLoggedIn)
            {
                facebookAccount = new WebAccount(facebookProvider, facebookUserName, WebAccountState.Connected);
                WebAccountCommand facebookAccountCommand = new WebAccountCommand(
                    facebookAccount, WebAccountInvokedHandler,
                    SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(facebookAccountCommand);
            }

            if (isTwitterUserLoggedIn)
            {
                twitterAccount = new WebAccount(twitterProvider, twitterUserName, WebAccountState.Connected);
                WebAccountCommand twitterAccountCommand = new WebAccountCommand(
                    twitterAccount, WebAccountInvokedHandler,
                    SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(twitterAccountCommand);
            }

            // Add links if needed.
            Object commandID = 1;
            UICommandInvokedHandler globalLinkInvokedHandler = new UICommandInvokedHandler(GlobalLinkInvokedhandler);
            SettingsCommand         command = new SettingsCommand(
                commandID,
                "More details",
                globalLinkInvokedHandler);

            eventArgs.Commands.Add(command);

            SettingsCommand command1 = new SettingsCommand(
                commandID,
                "Privacy policy",
                globalLinkInvokedHandler);

            eventArgs.Commands.Add(command1);

            deferral.Complete();
        }
Пример #9
0
        private async Task AddWebAccountsToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List <WebAccount> accounts = await GetAllAccounts();

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                e.WebAccountCommands.Add(command);
            }
        }
Пример #10
0
        private async void LocalWebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            await WebAccountInvokedHandlerCoreAsync(command, eventArgs);

            if (eventArgs.Action == WebAccountAction.Manage)
            {
                ChangePasswordFlyout changePasswordFlyout = new ChangePasswordFlyout(this.username);
                changePasswordFlyout.Show();
            }
        }
Пример #11
0
 private void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         App.LogoffAndRemoveAccount(command.WebAccount);
     }
     else if (args.Action == WebAccountAction.Reconnect)
     {
         // Display user management UI for this account
     }
 }
Пример #12
0
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         await LogoffAndRemoveAccount(command.WebAccount);
     }
     else if (args.Action == WebAccountAction.Manage)
     {
         // Display user management UI for this account
         rootPage.NotifyUser("Manage invoked for user: " + command.WebAccount.UserName, NotifyType.StatusMessage);
     }
 }
Пример #13
0
        public WebAccountCommand GetAccount()
        {
            account = new WebAccount(Provider, UserName, LoggedIn);

            WebAccountCommand _accountCommand = new WebAccountCommand(
                account, WebAccountInvokedHandler,
                SupportedWebAccountActions.Remove |
                SupportedWebAccountActions.Manage |
                SupportedWebAccountActions.Reconnect);

            return(_accountCommand);
        }
Пример #14
0
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         await LogoffAndRemoveAccount(command.WebAccount);
     }
     else if (args.Action == WebAccountAction.Manage)
     {
         // Display user management UI for this account
         DisplayInfoAsync("Manage invoked for user: " + command.WebAccount.UserName);
     }
 }
Пример #15
0
        private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var taskAccounts = WebAccountManager.FindAllProviderWebAccountsAsync().AsTask <IReadOnlyList <WebAccount> >();

            taskAccounts.Wait();
            var accounts = taskAccounts.Result;

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountCommandInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
Пример #16
0
        // 用户在账号管理界面中选择了某项功能
        private async void WebAccountCommandInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
        {
            // 用户选择的是注销
            if (args.Action == WebAccountAction.Remove)
            {
                await command.WebAccount.SignOutAsync();

                _userId = null;

                lblMsg.Text = "注销成功";
                imagePicture.ImageSource = null;
            }
        }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         rootPage.NotifyUser("Removing account", NotifyType.StatusMessage);
         await LogoffAndRemoveAccount();
     }
     else if (args.Action == WebAccountAction.Manage)
     {
         // Display user management UI for this account
         rootPage.NotifyUser("Managing account", NotifyType.StatusMessage);
     }
 }
Пример #18
0
        private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // In order to make async calls within this callback, the deferral object is needed
            AccountsSettingsPaneEventDeferral deferral = e.GetDeferral();

            try
            {
                foreach (var pi in _providers)
                {
                    // This scenario only lets the user have one account at a time.
                    // If there already is an account, we do not include a provider in the list
                    // This will prevent the add account button from showing up.
                    if (this.HasWebAccountInfo(pi.WebAccountType))
                    {
                        WebAccount account = await this.GetWebAccount(pi.WebAccountType);

                        if (account != null)
                        {
                            WebAccountCommand command = new WebAccountCommand(account, OnWebAccountRequested, pi.Actions);
                            e.WebAccountCommands.Add(command);
                        }
                    }
                    else
                    {
                        var provider = await this.GetProvider(pi.ProviderID, pi.Authority);

                        if (provider != null)
                        {
                            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, OnWebAccountProviderRequested);
                            e.WebAccountProviderCommands.Add(providerCommand);
                        }
                    }
                }

                e.HeaderText = string.Format(Strings.Account.TextWebAccountManagerSignUpDescription, PlatformBase.CurrentCore.AppInfo.AppName);

                // You can add links such as privacy policy, help, general account settings
                e.Commands.Add(new SettingsCommand("privacypolicy", Strings.Resources.ViewTitlePrivacyPolicy, (c) => { PlatformBase.CurrentCore.NavigationBase.PrivacyPolicyCommand.Execute(null); this.Cleanup(); }));
                e.Commands.Add(new SettingsCommand("tos", Strings.Resources.ViewTitleTermsOfService, (c) => { PlatformBase.CurrentCore.NavigationBase.TermsOfServiceCommand.Execute(null); this.Cleanup(); }));
            }
            catch (Exception ex)
            {
                PlatformBase.CurrentCore.Logger.LogError(ex, "Failed to display the web account manager UI.");
                throw ex;
            }
            finally
            {
                deferral.Complete();
            }
        }
Пример #19
0
        // 将指定的 web 账号添加到账号管理界面中
        private async Task ShowLogoutUI(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, _userId);

            if (account != null)
            {
                // 最后一个参数用于指定当用户选择了账号后,会出现哪些功能按钮(我这里测试只有 SupportedWebAccountActions.Remove 是有效的)
                WebAccountCommand command = new WebAccountCommand(account, WebAccountCommandInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                _userId = null;
            }
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                // The account has most likely been deleted in Windows settings
                // Unless there would be significant data loss, you should just delete the account
                // If there would be significant data loss, prompt the user to either re-add the account, or to remove it
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);

            e.WebAccountCommands.Add(command);
        }
Пример #21
0
        private async void WebAccountCommandInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
        {
            if (args.Action == WebAccountAction.Remove)
            {
                DebugPrint("Removing account");

                try
                {
                    if (command.WebAccount != null)
                    {
                        await command.WebAccount.SignOutAsync();

                        await WebAccountManager.DeleteWebAccountAsync(command.WebAccount);
                    }
                } catch (Exception ex)
                {
                    Trace.LogException(ex);
                }
            }
        }
        /// <summary>
        /// This event is generated when the user clicks on action button on account details pane. This method is
        /// responsible for handling what to do with selected action.
        /// </summary>
        /// <param name="command">Instance that triggered the event.</param>
        /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
        private void WebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            OutputText("Account State = " + command.WebAccount.State.ToString() + " and Selected Action = " + eventArgs.Action);

            if (eventArgs.Action == WebAccountAction.Remove)
            {
                //Remove user logon information since user requested to remove account.
                if (command.WebAccount.WebAccountProvider.Id.Equals(FACEBOOK_ID))
                {
                    roamingSettings.Values.Remove(FACEBOOK_USER_NAME);
                    roamingSettings.Values.Remove(FACEBOOK_OAUTH_TOKEN);
                    isFacebookUserLoggedIn = false;
                }
                else if (command.WebAccount.WebAccountProvider.Id.Equals(TWITTER_ID))
                {
                    roamingSettings.Values.Remove(TWITTER_USER_NAME);
                    roamingSettings.Values.Remove(TWITTER_OAUTH_TOKEN);
                    isTwitterUserLoggedIn = false;
                }
            }
        }
Пример #23
0
        private void BuildPaneAsync(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral = e.GetDeferral();

            e.HeaderText = "Sign in to get access to live tiles and notifications";

            var googleProvider  = new WebAccountProvider("youtube", "Youtube", new Uri("ms-appx:///Assets/Images/logo.png"));
            var providerCommand = new WebAccountProviderCommand(googleProvider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);

            List <WebAccount> accounts = App.GetAllAccounts();

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }

            deferral.Complete();
        }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         rootPage.NotifyUser("Removing account", NotifyType.StatusMessage);
         await LogoffAndRemoveAccount();
     }
 }
        public async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral();

            HttpResult<ManageInfo> result;
            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.GetManageInfoAsync();
            }

            if (!result.Succeeded)
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
                // The log off command is not available on the account settings page if there are no accounts, so log off now
                LogOff();
                deferral.Complete();
                return;
            }

            ManageInfo manageInfo = result.Content;
            this.username = manageInfo.UserName;
            this.localProvider = manageInfo.LocalLoginProvider;

            eventArgs.HeaderText = "Manage your account logins";

            ////Add WebAccountProviders
            Dictionary<string, WebAccountProvider> webProviders = new Dictionary<string, WebAccountProvider>();
            WebAccountProviderCommandInvokedHandler providerCommandHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
            foreach (ExternalLogin externalLogin in manageInfo.ExternalLoginProviders)
            {
                WebAccountProvider provider = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]);
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCommandHandler);
                eventArgs.WebAccountProviderCommands.Add(providerCommand);
                webProviders[provider.DisplayName] = provider;
            }

            WebAccountProvider localLoginProvider = new WebAccountProvider(manageInfo.LocalLoginProvider, manageInfo.LocalLoginProvider, null);
            webProviders[manageInfo.LocalLoginProvider] = localLoginProvider;

            ////Add WebAccounts and local accounts if available.
            bool hasLocalLogin = false;
            foreach (UserLoginInfo userLoginInfo in manageInfo.Logins)
            {
                WebAccountCommandInvokedHandler accountCommandHandler;
                SupportedWebAccountActions supportedActions = SupportedWebAccountActions.None;
                if (manageInfo.Logins.Length > 1)
                {
                    supportedActions |= SupportedWebAccountActions.Remove;
                }
                if (userLoginInfo.LoginProvider == manageInfo.LocalLoginProvider)
                {
                    hasLocalLogin = true;
                    supportedActions |= SupportedWebAccountActions.Manage;
                    accountCommandHandler = new WebAccountCommandInvokedHandler(LocalWebAccountInvokedHandler);
                }
                else
                {
                    accountCommandHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);
                }
                WebAccount webAccount = new WebAccount(webProviders[userLoginInfo.LoginProvider], userLoginInfo.ProviderKey, WebAccountState.Connected);

                WebAccountCommand webAccountCommand = new WebAccountCommand(webAccount, accountCommandHandler, supportedActions);
                eventArgs.WebAccountCommands.Add(webAccountCommand);
            }

            if (!hasLocalLogin)
            {
                WebAccountProviderCommandInvokedHandler localProviderCmdHandler = new WebAccountProviderCommandInvokedHandler(LocalProviderInvokedHandler);
                WebAccountProviderCommand localProviderCommand = new WebAccountProviderCommand(localLoginProvider, localProviderCmdHandler);
                eventArgs.WebAccountProviderCommands.Add(localProviderCommand);
            }

            SettingsCommand logOffCommand = new SettingsCommand("Logoff", "Log off", new UICommandInvokedHandler(LogOffHandler));
            eventArgs.Commands.Add(logOffCommand);

            deferral.Complete();
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                // The account has most likely been deleted in Windows settings
                // Unless there would be significant data loss, you should just delete the account
                // If there would be significant data loss, prompt the user to either re-add the account, or to remove it
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
            e.WebAccountCommands.Add(command);
        }
 private async void WebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
 {
     await WebAccountInvokedHandlerCoreAsync(command, eventArgs);
 }
 private async void LocalWebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
 {
     await WebAccountInvokedHandlerCoreAsync(command, eventArgs);
     if (eventArgs.Action == WebAccountAction.Manage)
     {
         ChangePasswordFlyout changePasswordFlyout = new ChangePasswordFlyout(this.username);
         changePasswordFlyout.Show();
     }
 }
Пример #29
0
 /// <summary>
 /// This event is generated when the user clicks on action button on account details pane. This method is 
 /// responsible for handling what to do with selected action.
 /// </summary>
 /// <param name="command">Instance that triggered the event.</param>
 /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
 private void WebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
 {
     OutputText("Account State = " + command.WebAccount.State.ToString() + " and Selected Action = " + eventArgs.Action);
     
     if (eventArgs.Action == WebAccountAction.Remove)
     {
         //Remove user logon information since user requested to remove account.
         if (command.WebAccount.WebAccountProvider.Id.Equals(FACEBOOK_ID))
         {
             roamingSettings.Values.Remove(FACEBOOK_USER_NAME);
             roamingSettings.Values.Remove(FACEBOOK_OAUTH_TOKEN);
             isFacebookUserLoggedIn = false;
         }
         else if (command.WebAccount.WebAccountProvider.Id.Equals(TWITTER_ID))
         {
             roamingSettings.Values.Remove(TWITTER_USER_NAME);
             roamingSettings.Values.Remove(TWITTER_OAUTH_TOKEN);
             isTwitterUserLoggedIn = false;
         }
     }
 }
        private async Task WebAccountInvokedHandlerCoreAsync(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            if (eventArgs.Action == WebAccountAction.Remove)
            {
                string loginProvider = command.WebAccount.WebAccountProvider.DisplayName;
                string providerKey = command.WebAccount.UserName;

                RemoveLogin removeLogin = new RemoveLogin()
                {
                    LoginProvider = loginProvider,
                    ProviderKey = providerKey
                };

                HttpResult result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.RemoveLoginAsync(removeLogin);
                }

                if (result.Succeeded)
                {
                    if (loginProvider == localProvider)
                    {
                        settings.ClearPasswordCredentials();
                    }
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
        }
      private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
      {
          WebAccount account = await GetWebAccount();
 
          WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
          e.WebAccountCommands.Add(command);
      }
Пример #32
0
        /// <summary>
        /// This event is generated when the user clicks on Accounts command in settings pane. During this event, add your
        /// WebAccountProviderCommand, WebAccountCommand, CredentialCommand and  SettingsCommand objects to make them available to the
        /// AccountsSettingsPane UI.
        /// </summary>
        /// <param name="accountsSettingsPane">Instance that triggered the event.</param>
        /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
        private void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            var deferral = eventArgs.GetDeferral();

            //Add header text.
            eventArgs.HeaderText = "This is sample text. You can put a message here to give context to user. This section is optional.";

            //Add WebAccountProviders
            WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
            WebAccountProviderCommand facebookProviderCommand = new WebAccountProviderCommand(facebookProvider, WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(facebookProviderCommand);
            WebAccountProviderCommand twitterProviderCommand = new WebAccountProviderCommand(twitterProvider, WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(twitterProviderCommand);

            //Add WebAccounts if available.
            WebAccountCommandInvokedHandler accountCmdHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);

            if (isFacebookUserLoggedIn)
            {
                facebookAccount = new WebAccount(facebookProvider, facebookUserName, WebAccountState.Connected);
                WebAccountCommand facebookAccountCommand = new WebAccountCommand(
                facebookAccount, WebAccountInvokedHandler,
                SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(facebookAccountCommand);
            }

            if (isTwitterUserLoggedIn)
            {
                twitterAccount = new WebAccount(twitterProvider, twitterUserName, WebAccountState.Connected);
                WebAccountCommand twitterAccountCommand = new WebAccountCommand(
                twitterAccount, WebAccountInvokedHandler,
                SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(twitterAccountCommand);
            }

            // Add links if needed.
            Object commandID = 1;
            UICommandInvokedHandler globalLinkInvokedHandler = new UICommandInvokedHandler(GlobalLinkInvokedhandler);
            SettingsCommand command = new SettingsCommand(
                commandID,
                "More details",
                globalLinkInvokedHandler);
            eventArgs.Commands.Add(command);

            SettingsCommand command1 = new SettingsCommand(
                commandID,
                "Privacy policy",
                globalLinkInvokedHandler);
            eventArgs.Commands.Add(command1);

            deferral.Complete();

        }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         rootPage.NotifyUser("Removing account", NotifyType.StatusMessage);
         await LogoffAndRemoveAccount();
     }
     else if (args.Action == WebAccountAction.Manage)
     {
         // Display user management UI for this account
         rootPage.NotifyUser("Managing account", NotifyType.StatusMessage);
     }
 }
Пример #34
0
        public async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral();

            HttpResult <ManageInfo> result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.GetManageInfoAsync();
            }

            if (!result.Succeeded)
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);

                // The log off command is not available on the account settings page if there are no accounts, so log off now
                LogOff();
                deferral.Complete();
                return;
            }

            ManageInfo manageInfo = result.Content;

            this.username      = manageInfo.UserName;
            this.localProvider = manageInfo.LocalLoginProvider;

            eventArgs.HeaderText = "Manage your account logins";

            ////Add WebAccountProviders
            Dictionary <string, WebAccountProvider> webProviders           = new Dictionary <string, WebAccountProvider>();
            WebAccountProviderCommandInvokedHandler providerCommandHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);

            foreach (ExternalLogin externalLogin in manageInfo.ExternalLoginProviders)
            {
                WebAccountProvider        provider        = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]);
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCommandHandler);
                eventArgs.WebAccountProviderCommands.Add(providerCommand);
                webProviders[provider.DisplayName] = provider;
            }

            WebAccountProvider localLoginProvider = new WebAccountProvider(manageInfo.LocalLoginProvider, manageInfo.LocalLoginProvider, null);

            webProviders[manageInfo.LocalLoginProvider] = localLoginProvider;

            ////Add WebAccounts and local accounts if available.
            bool hasLocalLogin = false;

            foreach (UserLoginInfo userLoginInfo in manageInfo.Logins)
            {
                WebAccountCommandInvokedHandler accountCommandHandler;
                SupportedWebAccountActions      supportedActions = SupportedWebAccountActions.None;
                if (manageInfo.Logins.Length > 1)
                {
                    supportedActions |= SupportedWebAccountActions.Remove;
                }
                if (userLoginInfo.LoginProvider == manageInfo.LocalLoginProvider)
                {
                    hasLocalLogin         = true;
                    supportedActions     |= SupportedWebAccountActions.Manage;
                    accountCommandHandler = new WebAccountCommandInvokedHandler(LocalWebAccountInvokedHandler);
                }
                else
                {
                    accountCommandHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);
                }
                WebAccount webAccount = new WebAccount(webProviders[userLoginInfo.LoginProvider], userLoginInfo.ProviderKey, WebAccountState.Connected);

                WebAccountCommand webAccountCommand = new WebAccountCommand(webAccount, accountCommandHandler, supportedActions);
                eventArgs.WebAccountCommands.Add(webAccountCommand);
            }

            if (!hasLocalLogin)
            {
                WebAccountProviderCommandInvokedHandler localProviderCmdHandler = new WebAccountProviderCommandInvokedHandler(LocalProviderInvokedHandler);
                WebAccountProviderCommand localProviderCommand = new WebAccountProviderCommand(localLoginProvider, localProviderCmdHandler);
                eventArgs.WebAccountProviderCommands.Add(localProviderCommand);
            }

            SettingsCommand logOffCommand = new SettingsCommand("Logoff", "Log off", new UICommandInvokedHandler(LogOffHandler));

            eventArgs.Commands.Add(logOffCommand);

            deferral.Complete();
        }
Пример #35
0
        private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // In order to make async calls within this callback, the deferral object is needed
            AccountsSettingsPaneEventDeferral deferral = e.GetDeferral();

            try
            {
                foreach (var pi in _providers)
                {
                    // This scenario only lets the user have one account at a time.
                    // If there already is an account, we do not include a provider in the list
                    // This will prevent the add account button from showing up.
                    if (this.HasWebAccountInfo(pi.WebAccountType))
                    {
                        WebAccount account = await this.GetWebAccount(pi.WebAccountType);

                        if (account != null)
                        {
                            WebAccountCommand command = new WebAccountCommand(account, OnWebAccountRequested, pi.Actions);
                            e.WebAccountCommands.Add(command);
                        }
                    }
                    else
                    {
                        var provider = await this.GetProvider(pi.ProviderID, pi.Authority);
                        if (provider != null)
                        {
                            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, OnWebAccountProviderRequested);
                            e.WebAccountProviderCommands.Add(providerCommand);
                        }
                    }
                }

                e.HeaderText = Strings.Account.TextWebAccountManagerSignUpDescription;

                // You can add links such as privacy policy, help, general account settings
                e.Commands.Add(new SettingsCommand("privacypolicy", Strings.Resources.ViewTitlePrivacyPolicy, (c) => { Platform.Current.Navigation.NavigateToPrivacyPolicyCommand.Execute(null); this.Cleanup(); }));
                e.Commands.Add(new SettingsCommand("tos", Strings.Resources.ViewTitleTermsOfService, (c) => { Platform.Current.Navigation.NavigateToTermsOfServiceCommand.Execute(null); this.Cleanup(); }));
            }
            catch(Exception ex)
            {
                Platform.Current.Logger.LogError(ex, "Failed to display the web account manager UI.");
                throw ex;
            }
            finally
            {
                deferral.Complete();
            }
        }
Пример #36
0
 private async void WebAccountInvokedHandler(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
 {
     await WebAccountInvokedHandlerCoreAsync(command, eventArgs);
 }
 private async void WebAccountInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
 {
     if (args.Action == WebAccountAction.Remove)
     {
         await LogoffAndRemoveAccount(command.WebAccount);
     }
     else if (args.Action == WebAccountAction.Manage)
     {
         // Display user management UI for this account
         rootPage.NotifyUser("Manage invoked for user: " + command.WebAccount.UserName, NotifyType.StatusMessage);
     }
 }
Пример #38
0
        private async void OnWebAccountRequested(WebAccountCommand cmd, WebAccountInvokedArgs args)
        {
            try
            {
                // Handle the different WebAccount actions...

                if (args.Action == WebAccountAction.Remove)
                {
                    // Signs the provider out.
                    Platform.Current.Logger.Log(LogLevels.Information, "Web Account Manager - Remove account called");
                    await this.SignoutAsync(cmd.WebAccount.WebAccountProvider.Id);
                }
                else if (args.Action == WebAccountAction.Manage)
                {
                    // Display user management UI for this account
                    Platform.Current.Logger.Log(LogLevels.Information, "Web Account Manager - Manage account called");
                }
            }
            catch (Exception ex)
            {
                Platform.Current.Logger.LogError(ex, "Web Token request failed");
            }
            finally
            {
                this.Cleanup();
            }
        }
        private async Task AddWebAccountsToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List<WebAccount> accounts = await GetAllAccounts();

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                e.WebAccountCommands.Add(command);
            }
        }