aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs')
-rw-r--r--MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs68
1 files changed, 67 insertions, 1 deletions
diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
index c2725e9bf..c17a637fe 100644
--- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
+++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Configuration;
+using System.IO;
+using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Model.Entities;
@@ -18,6 +19,7 @@ namespace MediaBrowser.Common.Implementations.Security
public class PluginSecurityManager : ISecurityManager
{
private const string MBValidateUrl = MbAdmin.HttpsUrl + "service/registration/validate";
+ private const string AppstoreRegUrl = /*MbAdmin.HttpsUrl*/ "http://mb3admin.com/admin/" + "service/appstore/register";
/// <summary>
/// The _is MB supporter
@@ -185,6 +187,70 @@ namespace MediaBrowser.Common.Implementations.Security
}
}
+ /// <summary>
+ /// Register an app store sale with our back-end. It will validate the transaction with the store
+ /// and then register the proper feature and then fill in the supporter key on success.
+ /// </summary>
+ /// <param name="parameters">Json parameters to send to admin server</param>
+ public async Task RegisterAppStoreSale(string parameters)
+ {
+ var options = new HttpRequestOptions()
+ {
+ Url = AppstoreRegUrl,
+ CancellationToken = CancellationToken.None
+ };
+ options.RequestHeaders.Add("X-Emby-Token", _appHost.SystemId);
+ options.RequestContent = parameters;
+ options.RequestContentType = "application/json";
+
+ try
+ {
+ using (var response = await _httpClient.Post(options).ConfigureAwait(false))
+ {
+ var reg = _jsonSerializer.DeserializeFromStream<RegRecord>(response.Content);
+
+ if (reg == null)
+ {
+ var msg = "Result from appstore registration was null.";
+ _logger.Error(msg);
+ throw new ApplicationException(msg);
+ }
+ if (!String.IsNullOrEmpty(reg.key))
+ {
+ SupporterKey = reg.key;
+ }
+ }
+
+ }
+ catch (ApplicationException)
+ {
+ SaveAppStoreInfo(parameters);
+ throw;
+ }
+ catch (Exception e)
+ {
+ _logger.ErrorException("Error registering appstore purchase {0}", e, parameters ?? "NO PARMS SENT");
+ SaveAppStoreInfo(parameters);
+ //TODO - could create a re-try routine on start-up if this file is there. For now we can handle manually.
+ throw new ApplicationException("Error registering store sale");
+ }
+
+ }
+
+ private void SaveAppStoreInfo(string info)
+ {
+ // Save all transaction information to a file
+
+ try
+ {
+ File.WriteAllText(Path.Combine(_appPaths.ProgramDataPath, "apptrans-error.txt"), info);
+ }
+ catch (IOException)
+ {
+
+ }
+ }
+
private async Task<MBRegistrationRecord> GetRegistrationStatusInternal(string feature,
string mb2Equivalent = null,
string version = null)