-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-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;
-using System.Windows.Documents;
-using System.Windows.Input;
-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
-{
- /// <summary>
- /// Interaction logic for LoginView.xaml
- /// </summary>
- public partial class LoginView : Window,INotifyPropertyChanged
- {
- 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
- {
- return _uri;
- }
- set
- {
- _uri = value;
- RaisePropertyChanged(() => Uri);
- }
- }
-
- private void RaisePropertyChanged(Expression<Func<Uri>> property)
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(property.GetMemberInfo().Name));
- }
- }
-
- 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 = loginUri;
-
-
- _logoutUri = logoutUri;
-
- _loggingOut = true;
-
- LoginBrowser.Navigate(logoutUri ?? loginUri);
- }
-
-
- public string Token { get; set; }
- public string Account { get; set; }
-
-
- private void LoginBrowser_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
- {
- IsBusy.IsBusy = true;
- LoginBrowser.Visibility=Visibility.Hidden;
-
- if (Log.IsDebugEnabled)
- Log.Debug(e.ToString());
-
- if (e.Uri.Scheme == "pithos")
- {
- Log.DebugFormat("Authentication response [{0}]",e.Uri);
- e.Cancel = true;
- var response = ParseResponse(e.Uri.Query);
- Account = response["user"];
- Token = response["token"];
- Log.InfoFormat("Token received for [{0}]", Account);
- DialogResult = true;
- this.Close();
- }
- }
-
- private static Dictionary<string, string> ParseResponse(string request)
- {
- //var parts = request.Split(' ');
- var query = request.TrimStart('?');
-
- var items = query.Split('&')
- .Select(pair => pair.Split('='))
- .ToDictionary(arr => arr[0].ToLower(), arr => Uri.UnescapeDataString(arr[1]));
- return items;
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- private void Retry_Click(object sender, RoutedEventArgs e)
- {
- LoginBrowser.Navigate(Uri);
- }
-
- private void LoginBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
- {
- if (_loggingOut)
- {
- _loggingOut = false;
- IsBusy.BusyContent = "Opening login screen";
- LoginBrowser.Navigate(Uri);
- }
- else
- {
- IsBusy.IsBusy = false;
- LoginBrowser.Visibility = Visibility.Visible;
- }
- }
- }
-}
+using System;\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using System.Linq;\r
+using System.Linq.Expressions;\r
+using System.Reflection;\r
+using System.Text;\r
+using System.Threading.Tasks;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Data;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+using Caliburn.Micro;\r
+using Pithos.Client.WPF.Properties;\r
+\r
+\r
+namespace Pithos.Client.WPF.Preferences\r
+{\r
+ /// <summary>\r
+ /// Interaction logic for LoginView.xaml\r
+ /// </summary>\r
+ public partial class LoginView : Window,INotifyPropertyChanged\r
+ {\r
+ private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);\r
+\r
+ private Uri _uri;\r
+ private Uri _logoutUri;\r
+ private bool _loggingOut;\r
+\r
+ public Uri Uri\r
+ {\r
+ get\r
+ {\r
+ return _uri;\r
+ }\r
+ set\r
+ {\r
+ _uri = value;\r
+ RaisePropertyChanged(() => Uri);\r
+ }\r
+ }\r
+\r
+ private void RaisePropertyChanged(Expression<Func<Uri>> property)\r
+ {\r
+ if (PropertyChanged != null)\r
+ {\r
+ PropertyChanged(this, new PropertyChangedEventArgs(property.GetMemberInfo().Name));\r
+ }\r
+ }\r
+\r
+ public LoginView(Uri loginUri, Uri logoutUri, string account = null)\r
+ {\r
+ InitializeComponent();\r
+ if (String.IsNullOrWhiteSpace(account))\r
+ this.Title = "Retrieve Pithos credentials";\r
+ else\r
+ this.Title = "Retrieve Pithos credentials for " + account;\r
+ Uri = loginUri;\r
+\r
+ \r
+ _logoutUri = logoutUri;\r
+\r
+ _loggingOut = true;\r
+\r
+ LoginBrowser.Navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; ');for(e=0;e<a.length&&a[e];e++){f++;for(b='.'+location.host;b;b=b.replace(/^(?:%5C.|[^%5C.]+)/,'')){for(c=location.pathname;c;c=c.replace(/.$/,'')){document.cookie=(a[e]+'; domain='+b+'; path='+c+'; expires='+new Date((new Date()).getTime()-1e11).toGMTString());}}}})())");\r
+\r
+ LoginBrowser.Navigate(logoutUri ?? loginUri);\r
+ }\r
+\r
+\r
+ public string Token { get; set; }\r
+ public string Account { get; set; }\r
+\r
+\r
+ private void LoginBrowser_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)\r
+ {\r
+ IsBusy.IsBusy = true;\r
+ LoginBrowser.Visibility=Visibility.Hidden;\r
+\r
+ if (Log.IsDebugEnabled)\r
+ Log.Debug(e.ToString());\r
+\r
+ if (e.Uri.Scheme == "pithos")\r
+ {\r
+ Log.DebugFormat("Authentication response [{0}]",e.Uri);\r
+ e.Cancel = true;\r
+ var response = ParseResponse(e.Uri.Query);\r
+ Account = response["user"];\r
+ Token = response["token"];\r
+ Log.InfoFormat("Token received for [{0}]", Account);\r
+ DialogResult = true;\r
+ this.Close();\r
+ }\r
+ }\r
+\r
+ private static Dictionary<string, string> ParseResponse(string request)\r
+ {\r
+ //var parts = request.Split(' ');\r
+ var query = request.TrimStart('?');\r
+\r
+ var items = query.Split('&')\r
+ .Select(pair => pair.Split('='))\r
+ .ToDictionary(arr => arr[0].ToLower(), arr => Uri.UnescapeDataString(arr[1]));\r
+ return items;\r
+ }\r
+\r
+ public event PropertyChangedEventHandler PropertyChanged;\r
+\r
+ private void Retry_Click(object sender, RoutedEventArgs e)\r
+ {\r
+ LoginBrowser.Navigate(Uri);\r
+ }\r
+\r
+ private void LoginBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)\r
+ {\r
+ if (_loggingOut)\r
+ {\r
+ _loggingOut = false;\r
+ IsBusy.BusyContent = "Opening login screen";\r
+ LoginBrowser.Navigate(Uri);\r
+ }\r
+ else\r
+ {\r
+ IsBusy.IsBusy = false;\r
+ LoginBrowser.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+ }\r
+}\r