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.cs40
1 files changed, 31 insertions, 9 deletions
diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs
index 1f9ffe5..eb99d92 100644
--- a/Juick/Classes/AccountManager.cs
+++ b/Juick/Classes/AccountManager.cs
@@ -3,6 +3,8 @@ using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
+using RestSharp;
+using System.Diagnostics;
namespace Juick.Classes
{
@@ -10,14 +12,14 @@ namespace Juick.Classes
{
private string _userName;
private string _password;
-
+
public string UserName
{
get
{
if (_userName == null)
{
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("user", out _userName);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("user", out _userName);
}
return _userName;
}
@@ -34,7 +36,7 @@ namespace Juick.Classes
{
if (_password == null)
{
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out _password);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out _password);
}
return _password;
}
@@ -47,7 +49,8 @@ namespace Juick.Classes
public bool IsAuthenticated
{
- get {
+ get
+ {
bool authenticated;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<bool>("authenticated", out authenticated);
return authenticated;
@@ -55,26 +58,45 @@ namespace Juick.Classes
set { IsolatedStorageSettings.ApplicationSettings["authenticated"] = value; }
}
+
+
public string NotificationUri
{
get
{
- string savedUri;
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("notification_uri", out savedUri);
- return savedUri;
+ string _notificationUri;
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("notification_uri", out _notificationUri);
+ return _notificationUri;
}
set
{
+ var oldValue = NotificationUri;
+ if (!string.IsNullOrEmpty(oldValue))
+ UnregisterNotificationUrl(oldValue);
IsolatedStorageSettings.ApplicationSettings["notification_uri"] = value;
+ if (!string.IsNullOrEmpty(value))
+ RegisterNotificationUrl(value);
}
}
-
-
+
+
public void SignOut(Page page)
{
IsAuthenticated = false;
+ App.AppContext.DisableNotifications();
page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative));
page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry());
}
+
+ void RegisterNotificationUrl(string newUrl)
+ {
+ App.AppContext.Client.ExecuteAsync(new RestRequest("/winphone/register?url=" + newUrl),
+ response => Debug.WriteLine("Registering push url, status {0}: {1}", response.Request.Resource, response.StatusCode));
+ }
+ void UnregisterNotificationUrl(string oldUrl)
+ {
+ App.AppContext.Client.ExecuteAsync(new RestRequest("/winphone/unregister?url=" + oldUrl),
+ response => Debug.WriteLine("Unregistered push url, status {0}: {1}", response.Request.Resource, response.StatusCode));
+ }
}
}