mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-17 15:46:22 +00:00
added new cabac value
This commit is contained in:
@@ -141,6 +141,8 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
try
|
||||
{
|
||||
var localAddress = _appHost.GetSystemInfo().LocalAddress;
|
||||
|
||||
var hasExistingRecord = !string.IsNullOrWhiteSpace(ConnectServerId) &&
|
||||
!string.IsNullOrWhiteSpace(ConnectAccessKey);
|
||||
|
||||
@@ -150,11 +152,12 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
{
|
||||
try
|
||||
{
|
||||
await UpdateServerRegistration(wanApiAddress).ConfigureAwait(false);
|
||||
await UpdateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false);
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
if (!ex.StatusCode.HasValue || !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
|
||||
if (!ex.StatusCode.HasValue ||
|
||||
!new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@@ -165,7 +168,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
if (createNewRegistration)
|
||||
{
|
||||
await CreateServerRegistration(wanApiAddress).ConfigureAwait(false);
|
||||
await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false);
|
||||
@@ -176,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateServerRegistration(string wanApiAddress)
|
||||
private async Task CreateServerRegistration(string wanApiAddress, string localAddress)
|
||||
{
|
||||
var url = "Servers";
|
||||
url = GetConnectUrl(url);
|
||||
@@ -188,6 +191,11 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
{"systemId", _appHost.SystemId}
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(localAddress))
|
||||
{
|
||||
postData["localAddress"] = localAddress;
|
||||
}
|
||||
|
||||
using (var stream = await _httpClient.Post(url, postData, CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
var data = _json.DeserializeFromStream<ServerRegistrationResponse>(stream);
|
||||
@@ -199,24 +207,31 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateServerRegistration(string wanApiAddress)
|
||||
private async Task UpdateServerRegistration(string wanApiAddress, string localAddress)
|
||||
{
|
||||
var url = "Servers";
|
||||
url = GetConnectUrl(url);
|
||||
url += "?id=" + ConnectServerId;
|
||||
|
||||
var postData = new Dictionary<string, string>
|
||||
{
|
||||
{"name", _appHost.FriendlyName},
|
||||
{"url", wanApiAddress},
|
||||
{"systemId", _appHost.SystemId}
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(localAddress))
|
||||
{
|
||||
postData["localAddress"] = localAddress;
|
||||
}
|
||||
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
CancellationToken = CancellationToken.None
|
||||
};
|
||||
|
||||
options.SetPostData(new Dictionary<string, string>
|
||||
{
|
||||
{"name", _appHost.FriendlyName},
|
||||
{"url", wanApiAddress},
|
||||
{"systemId", _appHost.SystemId}
|
||||
});
|
||||
options.SetPostData(postData);
|
||||
|
||||
SetServerAccessToken(options);
|
||||
|
||||
@@ -405,15 +420,46 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
throw new ArgumentNullException("connectUsername");
|
||||
}
|
||||
|
||||
var connectUser = await GetConnectUser(new ConnectUserQuery
|
||||
{
|
||||
Name = connectUsername
|
||||
string connectUserId = null;
|
||||
var result = new UserLinkResult();
|
||||
|
||||
}, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
if (!connectUser.IsActive)
|
||||
try
|
||||
{
|
||||
throw new ArgumentException("The Media Browser account has been disabled.");
|
||||
var connectUser = await GetConnectUser(new ConnectUserQuery
|
||||
{
|
||||
Name = connectUsername
|
||||
|
||||
}, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
if (!connectUser.IsActive)
|
||||
{
|
||||
throw new ArgumentException("The Media Browser account has been disabled.");
|
||||
}
|
||||
|
||||
connectUserId = connectUser.Id;
|
||||
result.GuestDisplayName = connectUser.Name;
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
if (!ex.StatusCode.HasValue ||
|
||||
ex.StatusCode.Value != HttpStatusCode.NotFound ||
|
||||
!Validator.EmailIsValid(connectUsername))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
var sendingUser = GetUser(sendingUserId);
|
||||
var requesterUserName = sendingUser.ConnectUserName;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(requesterUserName))
|
||||
{
|
||||
requesterUserName = sendingUser.Name;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(connectUserId))
|
||||
{
|
||||
return await SendNewUserInvitation(requesterUserName, connectUsername).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var url = GetConnectUrl("ServerAuthorizations");
|
||||
@@ -425,18 +471,11 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
};
|
||||
|
||||
var accessToken = Guid.NewGuid().ToString("N");
|
||||
var sendingUser = GetUser(sendingUserId);
|
||||
|
||||
var requesterUserName = sendingUser.ConnectUserName;
|
||||
if (string.IsNullOrWhiteSpace(requesterUserName))
|
||||
{
|
||||
requesterUserName = sendingUser.Name;
|
||||
}
|
||||
|
||||
var postData = new Dictionary<string, string>
|
||||
{
|
||||
{"serverId", ConnectServerId},
|
||||
{"userId", connectUser.Id},
|
||||
{"userId", connectUserId},
|
||||
{"userType", "Guest"},
|
||||
{"accessToken", accessToken},
|
||||
{"requesterUserName", requesterUserName}
|
||||
@@ -446,8 +485,6 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
SetServerAccessToken(options);
|
||||
|
||||
var result = new UserLinkResult();
|
||||
|
||||
// No need to examine the response
|
||||
using (var stream = (await _httpClient.Post(options).ConfigureAwait(false)).Content)
|
||||
{
|
||||
@@ -461,6 +498,36 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<UserLinkResult> SendNewUserInvitation(string fromName, string email)
|
||||
{
|
||||
var url = GetConnectUrl("users/invite");
|
||||
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
CancellationToken = CancellationToken.None
|
||||
};
|
||||
|
||||
var postData = new Dictionary<string, string>
|
||||
{
|
||||
{"email", email},
|
||||
{"requesterUserName", fromName}
|
||||
};
|
||||
|
||||
options.SetPostData(postData);
|
||||
|
||||
// No need to examine the response
|
||||
using (var stream = (await _httpClient.Post(options).ConfigureAwait(false)).Content)
|
||||
{
|
||||
}
|
||||
|
||||
return new UserLinkResult
|
||||
{
|
||||
IsNewUserInvitation = true,
|
||||
GuestDisplayName = email
|
||||
};
|
||||
}
|
||||
|
||||
public Task RemoveConnect(string userId)
|
||||
{
|
||||
var user = GetUser(userId);
|
||||
@@ -586,6 +653,9 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
if (connectEntry == null)
|
||||
{
|
||||
var deleteUser = user.ConnectLinkType.HasValue &&
|
||||
user.ConnectLinkType.Value == UserLinkType.Guest;
|
||||
|
||||
user.ConnectUserId = null;
|
||||
user.ConnectAccessKey = null;
|
||||
user.ConnectUserName = null;
|
||||
@@ -593,7 +663,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||
|
||||
await _userManager.UpdateUser(user).ConfigureAwait(false);
|
||||
|
||||
if (user.ConnectLinkType.HasValue && user.ConnectLinkType.Value == UserLinkType.Guest)
|
||||
if (deleteUser)
|
||||
{
|
||||
_logger.Debug("Deleting guest user {0}", user.Name);
|
||||
await _userManager.DeleteUser(user).ConfigureAwait(false);
|
||||
|
||||
34
MediaBrowser.Server.Implementations/Connect/Validator.cs
Normal file
34
MediaBrowser.Server.Implementations/Connect/Validator.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Connect
|
||||
{
|
||||
public static class Validator
|
||||
{
|
||||
static Regex ValidEmailRegex = CreateValidEmailRegex();
|
||||
|
||||
/// <summary>
|
||||
/// Taken from http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Regex CreateValidEmailRegex()
|
||||
{
|
||||
string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
|
||||
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
|
||||
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
||||
|
||||
return new Regex(validEmailPattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
internal static bool EmailIsValid(string emailAddress)
|
||||
{
|
||||
bool isValid = ValidEmailRegex.IsMatch(emailAddress);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user