From 49eb44f852ab21e72c17bbc436ffa79525a1aba3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 11 Feb 2012 22:22:50 +0400 Subject: v 0.999 :) --- Juick/Classes/AccountManager.cs | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Juick/Classes/AccountManager.cs (limited to 'Juick/Classes/AccountManager.cs') diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs new file mode 100644 index 0000000..f7fcc75 --- /dev/null +++ b/Juick/Classes/AccountManager.cs @@ -0,0 +1,65 @@ +using System; +using System.IO; +using System.IO.IsolatedStorage; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using System.Xml; +using System.Xml.Serialization; + +namespace Juick.Classes +{ + public class AccountManager + { + const string FileName = "account.xml"; + public NetworkCredential Credentials + { + get + { + return new NetworkCredential + { + UserName = IsolatedStorageSettings.ApplicationSettings.Contains("user") ? + IsolatedStorageSettings.ApplicationSettings["user"] as string : null, + Password = IsolatedStorageSettings.ApplicationSettings.Contains("password") ? + IsolatedStorageSettings.ApplicationSettings["password"] as string : null, + }; + } + set + { + var creds = value; + if (creds != null) + { + IsolatedStorageSettings.ApplicationSettings["user"] = value.UserName; + IsolatedStorageSettings.ApplicationSettings["password"] = value.Password; + } else + { + IsolatedStorageSettings.ApplicationSettings["user"] = null; + IsolatedStorageSettings.ApplicationSettings["password"] = null; + } + } + } + + public void SignIn(Page page, string login, string pass) + { + Credentials = new NetworkCredential(login, pass); + page.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); + page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); + } + + public void SignOut(Page page) + { + Credentials = null; + page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative)); + page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); + } + } +} -- cgit v1.2.3