Adding a new account now forces a logout to clear any stale Pithos cookies
[pithos-ms-client] / trunk / Pithos.Client.WPF / Preferences / LoginView.xaml.cs
index a9ee875..c0aa6a9 100644 (file)
@@ -5,6 +5,7 @@ using System.Linq;
 using System.Linq.Expressions;
 using System.Reflection;
 using System.Text;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
@@ -14,6 +15,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Shapes;
 using Caliburn.Micro;
+using Pithos.Client.WPF.Properties;
 
 
 namespace Pithos.Client.WPF.Preferences
@@ -26,6 +28,9 @@ namespace Pithos.Client.WPF.Preferences
         private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
         private Uri _uri;
+        private Uri _logoutUri;
+        private bool _loggingOut;
+
         public Uri Uri
         {
             get
@@ -47,15 +52,20 @@ namespace Pithos.Client.WPF.Preferences
             }
         }
 
-        public LoginView(Uri uri,string account=null)
+        public LoginView(Uri loginUri, Uri logoutUri, string account = null)
         {
             InitializeComponent();
             if (String.IsNullOrWhiteSpace(account))
                 this.Title = "Retrieve Pithos credentials";
             else
                 this.Title = "Retrieve Pithos credentials for " + account;
-            Uri = uri;
-            LoginBrowser.Navigate(uri);
+            Uri = loginUri;
+
+            
+            _logoutUri = logoutUri;
+
+            _loggingOut = true;
+            LoginBrowser.Navigate(logoutUri ?? loginUri);
         }
 
 
@@ -66,7 +76,10 @@ namespace Pithos.Client.WPF.Preferences
         private void LoginBrowser_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
         {
             IsBusy.IsBusy = true;
-            Log.Debug(e.ToString());
+            LoginBrowser.Visibility=Visibility.Hidden;
+
+            if (Log.IsDebugEnabled)
+                Log.Debug(e.ToString());
 
             if (e.Uri.Scheme == "pithos")
             {
@@ -101,7 +114,17 @@ namespace Pithos.Client.WPF.Preferences
 
         private void LoginBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
         {
-            IsBusy.IsBusy = false;
+            if (_loggingOut)
+            {
+                _loggingOut = false;
+                IsBusy.BusyContent = "Opening login screen";
+                LoginBrowser.Navigate(Uri);
+            }
+            else
+            {
+                IsBusy.IsBusy = false;
+                LoginBrowser.Visibility = Visibility.Visible;
+            }
         }
     }
 }