mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Updated authentication
This commit is contained in:
parent
31c710ca34
commit
8fc828361e
@ -1,10 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Controller;
|
||||||
|
using MediaBrowser.Model.DTO;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Model.DTO;
|
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
namespace MediaBrowser.Api
|
||||||
{
|
{
|
||||||
@ -13,6 +13,9 @@ namespace MediaBrowser.Api
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ApiService
|
public static class ApiService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an Item by Id, or the root item if none is supplied
|
||||||
|
/// </summary>
|
||||||
public static BaseItem GetItemById(string id)
|
public static BaseItem GetItemById(string id)
|
||||||
{
|
{
|
||||||
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
|
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
|
||||||
@ -20,6 +23,52 @@ namespace MediaBrowser.Api
|
|||||||
return Kernel.Instance.GetItemById(guid);
|
return Kernel.Instance.GetItemById(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a User by Id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logActivity">Whether or not to update the user's LastActivityDate</param>
|
||||||
|
public static User GetUserById(string id, bool logActivity)
|
||||||
|
{
|
||||||
|
Guid guid = new Guid(id);
|
||||||
|
|
||||||
|
User user = Kernel.Instance.Users.FirstOrDefault(u => u.Id == guid);
|
||||||
|
|
||||||
|
if (logActivity)
|
||||||
|
{
|
||||||
|
LogUserActivity(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default User
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logActivity">Whether or not to update the user's LastActivityDate</param>
|
||||||
|
public static User GetDefaultUser(bool logActivity)
|
||||||
|
{
|
||||||
|
User user = Kernel.Instance.GetDefaultUser();
|
||||||
|
|
||||||
|
if (logActivity)
|
||||||
|
{
|
||||||
|
LogUserActivity(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates LastActivityDate for a given User
|
||||||
|
/// </summary>
|
||||||
|
public static void LogUserActivity(User user)
|
||||||
|
{
|
||||||
|
user.LastActivityDate = DateTime.UtcNow;
|
||||||
|
Kernel.Instance.SaveUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a BaseItem to a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
public async static Task<DTOBaseItem> GetDTOBaseItem(BaseItem item, User user,
|
public async static Task<DTOBaseItem> GetDTOBaseItem(BaseItem item, User user,
|
||||||
bool includeChildren = true,
|
bool includeChildren = true,
|
||||||
bool includePeople = true)
|
bool includePeople = true)
|
||||||
@ -52,6 +101,9 @@ namespace MediaBrowser.Api
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets simple property values on a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
private static void AttachBasicFields(DTOBaseItem dto, BaseItem item, User user)
|
private static void AttachBasicFields(DTOBaseItem dto, BaseItem item, User user)
|
||||||
{
|
{
|
||||||
dto.AspectRatio = item.AspectRatio;
|
dto.AspectRatio = item.AspectRatio;
|
||||||
@ -168,6 +220,9 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches Studio DTO's to a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
private static async Task AttachStudios(DTOBaseItem dto, BaseItem item)
|
private static async Task AttachStudios(DTOBaseItem dto, BaseItem item)
|
||||||
{
|
{
|
||||||
// Attach Studios by transforming them into BaseItemStudio (DTO)
|
// Attach Studios by transforming them into BaseItemStudio (DTO)
|
||||||
@ -191,6 +246,9 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches child DTO's to a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
private static async Task AttachChildren(DTOBaseItem dto, BaseItem item, User user)
|
private static async Task AttachChildren(DTOBaseItem dto, BaseItem item, User user)
|
||||||
{
|
{
|
||||||
var folder = item as Folder;
|
var folder = item as Folder;
|
||||||
@ -203,6 +261,9 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches trailer DTO's to a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
private static async Task AttachLocalTrailers(DTOBaseItem dto, BaseItem item, User user)
|
private static async Task AttachLocalTrailers(DTOBaseItem dto, BaseItem item, User user)
|
||||||
{
|
{
|
||||||
if (item.LocalTrailers != null && item.LocalTrailers.Any())
|
if (item.LocalTrailers != null && item.LocalTrailers.Any())
|
||||||
@ -211,6 +272,9 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attaches People DTO's to a DTOBaseItem
|
||||||
|
/// </summary>
|
||||||
private static async Task AttachPeople(DTOBaseItem dto, BaseItem item)
|
private static async Task AttachPeople(DTOBaseItem dto, BaseItem item)
|
||||||
{
|
{
|
||||||
// Attach People by transforming them into BaseItemPerson (DTO)
|
// Attach People by transforming them into BaseItemPerson (DTO)
|
||||||
@ -238,6 +302,9 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If an item does not any backdrops, this can be used to find the first parent that does have one
|
||||||
|
/// </summary>
|
||||||
private static Guid? GetParentBackdropItemId(BaseItem item, out int backdropCount)
|
private static Guid? GetParentBackdropItemId(BaseItem item, out int backdropCount)
|
||||||
{
|
{
|
||||||
backdropCount = 0;
|
backdropCount = 0;
|
||||||
@ -258,6 +325,9 @@ namespace MediaBrowser.Api
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If an item does not have a logo, this can be used to find the first parent that does have one
|
||||||
|
/// </summary>
|
||||||
private static Guid? GetParentLogoItemId(BaseItem item)
|
private static Guid? GetParentLogoItemId(BaseItem item)
|
||||||
{
|
{
|
||||||
var parent = item.Parent;
|
var parent = item.Parent;
|
||||||
@ -275,6 +345,9 @@ namespace MediaBrowser.Api
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an ImagesByName entity along with the number of items containing it
|
||||||
|
/// </summary>
|
||||||
public static IBNItem GetIBNItem(BaseEntity entity, int itemCount)
|
public static IBNItem GetIBNItem(BaseEntity entity, int itemCount)
|
||||||
{
|
{
|
||||||
return new IBNItem()
|
return new IBNItem()
|
||||||
@ -286,6 +359,9 @@ namespace MediaBrowser.Api
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a User to a DTOUser
|
||||||
|
/// </summary>
|
||||||
public static DTOUser GetDTOUser(User user)
|
public static DTOUser GetDTOUser(User user)
|
||||||
{
|
{
|
||||||
return new DTOUser()
|
return new DTOUser()
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
using System.Linq;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -11,7 +9,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
{
|
{
|
||||||
protected override Task<DTOUser> GetObjectToSerialize()
|
protected override Task<DTOUser> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
User user = Kernel.Instance.Users.FirstOrDefault();
|
User user = ApiService.GetDefaultUser(false);
|
||||||
|
|
||||||
DTOUser dto = ApiService.GetDTOUser(user);
|
DTOUser dto = ApiService.GetDTOUser(user);
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -17,8 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem> GetObjectToSerialize()
|
protected override Task<IBNItem> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
string name = QueryString["name"];
|
string name = QueryString["name"];
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
return GetAllGenres(parent, user);
|
return GetAllGenres(parent, user);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Logging;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Logging;
|
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -57,8 +57,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(userId))
|
if (!string.IsNullOrEmpty(userId))
|
||||||
{
|
{
|
||||||
Guid userIdGuid = new Guid(userId);
|
return ApiService.GetUserById(userId, false).PrimaryImagePath;
|
||||||
return Kernel.Instance.Users.First(u => u.Id == userIdGuid).PrimaryImagePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseItem item = ApiService.GetItemById(QueryString["id"]);
|
BaseItem item = ApiService.GetItemById(QueryString["id"]);
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -12,8 +9,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
{
|
{
|
||||||
protected override Task<DTOBaseItem> GetObjectToSerialize()
|
protected override Task<DTOBaseItem> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
BaseItem item = ItemToSerialize;
|
BaseItem item = ItemToSerialize;
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
|
using MediaBrowser.Model.DTO;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Model.DTO;
|
|
||||||
using MediaBrowser.Model.Entities;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -13,22 +12,18 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
{
|
{
|
||||||
protected override Task<DTOBaseItem[]> GetObjectToSerialize()
|
protected override Task<DTOBaseItem[]> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == UserId);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
|
|
||||||
return Task.WhenAll<DTOBaseItem>(ItemsToSerialize.Select(i =>
|
return Task.WhenAll<DTOBaseItem>(GetItemsToSerialize(user).Select(i =>
|
||||||
{
|
{
|
||||||
return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: false);
|
return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: false);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IEnumerable<BaseItem> ItemsToSerialize
|
private IEnumerable<BaseItem> GetItemsToSerialize(User user)
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
||||||
|
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == UserId);
|
|
||||||
|
|
||||||
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return parent.GetInProgressItems(user);
|
return parent.GetInProgressItems(user);
|
||||||
@ -60,7 +55,6 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
|
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected string ItemId
|
protected string ItemId
|
||||||
{
|
{
|
||||||
@ -70,14 +64,6 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Guid UserId
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Guid.Parse(QueryString["userid"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string ListType
|
private string ListType
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -17,8 +15,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem> GetObjectToSerialize()
|
protected override Task<IBNItem> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
string name = QueryString["name"];
|
string name = QueryString["name"];
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -17,8 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem> GetObjectToSerialize()
|
protected override Task<IBNItem> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
string name = QueryString["name"];
|
string name = QueryString["name"];
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
return GetAllStudios(parent, user);
|
return GetAllStudios(parent, user);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -12,15 +9,12 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
{
|
{
|
||||||
protected override async Task<AuthenticationResult> GetObjectToSerialize()
|
protected override async Task<AuthenticationResult> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Guid userId = Guid.Parse(await GetFormValue("userid").ConfigureAwait(false));
|
string userId = await GetFormValue("userid").ConfigureAwait(false);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
User user = ApiService.GetUserById(userId, false);
|
||||||
|
|
||||||
string password = await GetFormValue("password").ConfigureAwait(false);
|
string password = await GetFormValue("password").ConfigureAwait(false);
|
||||||
|
|
||||||
return new AuthenticationResult()
|
return Kernel.Instance.AuthenticateUser(user, password);
|
||||||
{
|
|
||||||
Success = Kernel.GetMD5(password).Equals(user.Password)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -17,8 +15,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem> GetObjectToSerialize()
|
protected override Task<IBNItem> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
string year = QueryString["year"];
|
string year = QueryString["year"];
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Net.Handlers;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net.Handlers;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Api.HttpHandlers
|
namespace MediaBrowser.Api.HttpHandlers
|
||||||
{
|
{
|
||||||
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||||||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||||
{
|
{
|
||||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
|
||||||
|
|
||||||
return GetAllYears(parent, user);
|
return GetAllYears(parent, user);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
using MediaBrowser.Model.DTO;
|
using MediaBrowser.Model.DTO;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Weather;
|
using MediaBrowser.Model.Weather;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -82,7 +83,24 @@ namespace MediaBrowser.ApiInteraction
|
|||||||
public async Task<DTOBaseItem[]> GetRecentlyAddedItemsAsync(Guid userId)
|
public async Task<DTOBaseItem[]> GetRecentlyAddedItemsAsync(Guid userId)
|
||||||
{
|
{
|
||||||
string url = ApiUrl + "/itemlist?listtype=recentlyaddeditems&userId=" + userId.ToString();
|
string url = ApiUrl + "/itemlist?listtype=recentlyaddeditems&userId=" + userId.ToString();
|
||||||
using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(true))
|
|
||||||
|
using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
return DeserializeFromStream<DTOBaseItem[]>(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets recently added items within a specific folder
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The user id.</param>
|
||||||
|
public async Task<DTOBaseItem[]> GetRecentlyAddedItemsAsync(Guid userId, Guid folderId)
|
||||||
|
{
|
||||||
|
string url = ApiUrl + "/itemlist?listtype=recentlyaddeditems&userId=" + userId.ToString();
|
||||||
|
|
||||||
|
url += "&id=" + folderId.ToString();
|
||||||
|
|
||||||
|
using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
return DeserializeFromStream<DTOBaseItem[]>(stream);
|
return DeserializeFromStream<DTOBaseItem[]>(stream);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Logging;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
|
using MediaBrowser.Common.Plugins;
|
||||||
|
using MediaBrowser.Common.Serialization;
|
||||||
|
using MediaBrowser.Model.Configuration;
|
||||||
|
using MediaBrowser.Model.Progress;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.ComponentModel.Composition.Hosting;
|
using System.ComponentModel.Composition.Hosting;
|
||||||
@ -6,12 +12,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Logging;
|
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Common.Plugins;
|
|
||||||
using MediaBrowser.Common.Serialization;
|
|
||||||
using MediaBrowser.Model.Configuration;
|
|
||||||
using MediaBrowser.Model.Progress;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Kernel
|
namespace MediaBrowser.Common.Kernel
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,4 @@
|
|||||||
using System;
|
using MediaBrowser.Common.Kernel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.Composition;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Kernel;
|
|
||||||
using MediaBrowser.Common.Logging;
|
using MediaBrowser.Common.Logging;
|
||||||
using MediaBrowser.Controller.IO;
|
using MediaBrowser.Controller.IO;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
@ -17,6 +8,15 @@ using MediaBrowser.Controller.Weather;
|
|||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Progress;
|
using MediaBrowser.Model.Progress;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.Composition;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller
|
namespace MediaBrowser.Controller
|
||||||
{
|
{
|
||||||
@ -181,6 +181,55 @@ namespace MediaBrowser.Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default user to use when EnableUserProfiles is false
|
||||||
|
/// </summary>
|
||||||
|
public User GetDefaultUser()
|
||||||
|
{
|
||||||
|
User user = Users.FirstOrDefault();
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Persists a User
|
||||||
|
/// </summary>
|
||||||
|
public void SaveUser(User user)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Authenticates a User and returns a result indicating whether or not it succeeded
|
||||||
|
/// </summary>
|
||||||
|
public AuthenticationResult AuthenticateUser(User user, string password)
|
||||||
|
{
|
||||||
|
AuthenticationResult result = new AuthenticationResult();
|
||||||
|
|
||||||
|
// When EnableUserProfiles is false, only the default User can login
|
||||||
|
if (!Configuration.EnableUserProfiles)
|
||||||
|
{
|
||||||
|
result.Success = user.Id == GetDefaultUser().Id;
|
||||||
|
}
|
||||||
|
else if (string.IsNullOrEmpty(user.Password))
|
||||||
|
{
|
||||||
|
result.Success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Success = GetMD5(password).Equals(user.Password);
|
||||||
|
|
||||||
|
// Update LastActivityDate and LastLoginDate, then save
|
||||||
|
if (result.Success)
|
||||||
|
{
|
||||||
|
user.LastActivityDate = user.LastLoginDate = DateTime.UtcNow;
|
||||||
|
SaveUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task ReloadItem(BaseItem item)
|
public async Task ReloadItem(BaseItem item)
|
||||||
{
|
{
|
||||||
Folder folder = item as Folder;
|
Folder folder = item as Folder;
|
||||||
@ -236,7 +285,6 @@ namespace MediaBrowser.Controller
|
|||||||
|
|
||||||
user.Name = "Default User";
|
user.Name = "Default User";
|
||||||
user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b");
|
user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b");
|
||||||
user.PrimaryImagePath = @"g:\Mel.jpg";
|
|
||||||
list.Add(user);
|
list.Add(user);
|
||||||
|
|
||||||
user = new User();
|
user = new User();
|
||||||
@ -245,19 +293,16 @@ namespace MediaBrowser.Controller
|
|||||||
user.LastLoginDate = DateTime.UtcNow.AddDays(-1);
|
user.LastLoginDate = DateTime.UtcNow.AddDays(-1);
|
||||||
user.LastActivityDate = DateTime.UtcNow.AddHours(-3);
|
user.LastActivityDate = DateTime.UtcNow.AddHours(-3);
|
||||||
user.Password = GetMD5("1234").ToString();
|
user.Password = GetMD5("1234").ToString();
|
||||||
user.PrimaryImagePath = @"g:\abobader.jpg";
|
|
||||||
list.Add(user);
|
list.Add(user);
|
||||||
|
|
||||||
user = new User();
|
user = new User();
|
||||||
user.Name = "Scottisafool";
|
user.Name = "Scottisafool";
|
||||||
user.Id = Guid.NewGuid();
|
user.Id = Guid.NewGuid();
|
||||||
user.PrimaryImagePath = @"g:\Scott.jpg";
|
|
||||||
list.Add(user);
|
list.Add(user);
|
||||||
|
|
||||||
user = new User();
|
user = new User();
|
||||||
user.Name = "Redshirt";
|
user.Name = "Redshirt";
|
||||||
user.Id = Guid.NewGuid();
|
user.Id = Guid.NewGuid();
|
||||||
user.PrimaryImagePath = @"g:\redshirt.png";
|
|
||||||
list.Add(user);
|
list.Add(user);
|
||||||
|
|
||||||
/*user = new User();
|
/*user = new User();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using ProtoBuf;
|
||||||
using ProtoBuf;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.DTO
|
namespace MediaBrowser.Model.Entities
|
||||||
{
|
{
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class AuthenticationResult
|
public class AuthenticationResult
|
@ -35,7 +35,7 @@
|
|||||||
<Compile Include="Configuration\BaseApplicationConfiguration.cs" />
|
<Compile Include="Configuration\BaseApplicationConfiguration.cs" />
|
||||||
<Compile Include="Configuration\ServerConfiguration.cs" />
|
<Compile Include="Configuration\ServerConfiguration.cs" />
|
||||||
<Compile Include="DTO\AudioInfo.cs" />
|
<Compile Include="DTO\AudioInfo.cs" />
|
||||||
<Compile Include="DTO\AuthenticationResult.cs" />
|
<Compile Include="Entities\AuthenticationResult.cs" />
|
||||||
<Compile Include="DTO\DTOBaseItem.cs" />
|
<Compile Include="DTO\DTOBaseItem.cs" />
|
||||||
<Compile Include="DTO\DTOUser.cs" />
|
<Compile Include="DTO\DTOUser.cs" />
|
||||||
<Compile Include="DTO\VideoInfo.cs" />
|
<Compile Include="DTO\VideoInfo.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user