summaryrefslogtreecommitdiff
path: root/Juick/Classes/AccountManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Classes/AccountManager.cs')
-rw-r--r--Juick/Classes/AccountManager.cs62
1 files changed, 36 insertions, 26 deletions
diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs
index 8f8e366..4741992 100644
--- a/Juick/Classes/AccountManager.cs
+++ b/Juick/Classes/AccountManager.cs
@@ -1,53 +1,63 @@
using System;
using System.IO.IsolatedStorage;
using System.Net;
+using System.Windows;
using System.Windows.Controls;
namespace Juick.Classes
{
public class AccountManager
{
- const string FileName = "account.xml";
- public NetworkCredential Credentials
+ private string _userName;
+ private string _password;
+
+ public string UserName
{
get
{
- string userName;
- string password;
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("user", out userName);
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out password);
- return new NetworkCredential
- {
- UserName = userName,
- Password = password,
- };
+ if (_userName == null)
+ {
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("user", out _userName);
+ }
+ return _userName;
}
set
{
- var creds = value;
- if (creds != null)
- {
- IsolatedStorageSettings.ApplicationSettings["user"] = value.UserName;
- IsolatedStorageSettings.ApplicationSettings["password"] = value.Password;
- }
- else
+ _userName = value;
+ IsolatedStorageSettings.ApplicationSettings["user"] = _userName;
+ }
+ }
+
+ public string Password
+ {
+ get
+ {
+ if (_password == null)
{
- IsolatedStorageSettings.ApplicationSettings["user"] = null;
- IsolatedStorageSettings.ApplicationSettings["password"] = null;
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out _password);
}
+ return _password;
+ }
+ set
+ {
+ _password = value;
+ IsolatedStorageSettings.ApplicationSettings["password"] = value;
}
}
- public void SignIn(Page page, string login, string pass, Uri nextUri)
+ public bool IsAuthenticated
{
- Credentials = new NetworkCredential(login, pass);
- page.NavigationService.Navigate(nextUri);
- page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry());
+ get {
+ bool authenticated;
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<bool>("authenticated", out authenticated);
+ return authenticated;
+ }
+ set { IsolatedStorageSettings.ApplicationSettings["authenticated"] = value; }
}
-
+
public void SignOut(Page page)
{
- Credentials = null;
+ IsAuthenticated = false;
page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative));
page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry());
}