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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
{
|
||||
|
@ -13,6 +13,9 @@ namespace MediaBrowser.Api
|
|||
/// </summary>
|
||||
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)
|
||||
{
|
||||
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
|
||||
|
@ -20,6 +23,52 @@ namespace MediaBrowser.Api
|
|||
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,
|
||||
bool includeChildren = true,
|
||||
bool includePeople = true)
|
||||
|
@ -52,6 +101,9 @@ namespace MediaBrowser.Api
|
|||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets simple property values on a DTOBaseItem
|
||||
/// </summary>
|
||||
private static void AttachBasicFields(DTOBaseItem dto, BaseItem item, User user)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
backdropCount = 0;
|
||||
|
@ -258,6 +325,9 @@ namespace MediaBrowser.Api
|
|||
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)
|
||||
{
|
||||
var parent = item.Parent;
|
||||
|
@ -275,6 +345,9 @@ namespace MediaBrowser.Api
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ImagesByName entity along with the number of items containing it
|
||||
/// </summary>
|
||||
public static IBNItem GetIBNItem(BaseEntity entity, int itemCount)
|
||||
{
|
||||
return new IBNItem()
|
||||
|
@ -286,6 +359,9 @@ namespace MediaBrowser.Api
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a User to a DTOUser
|
||||
/// </summary>
|
||||
public static DTOUser GetDTOUser(User user)
|
||||
{
|
||||
return new DTOUser()
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -11,7 +9,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
{
|
||||
protected override Task<DTOUser> GetObjectToSerialize()
|
||||
{
|
||||
User user = Kernel.Instance.Users.FirstOrDefault();
|
||||
User user = ApiService.GetDefaultUser(false);
|
||||
|
||||
DTOUser dto = ApiService.GetDTOUser(user);
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -17,8 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
string name = QueryString["name"];
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
return GetAllGenres(parent, user);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Logging;
|
||||
using MediaBrowser.Common.Logging;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -57,8 +57,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
Guid userIdGuid = new Guid(userId);
|
||||
return Kernel.Instance.Users.First(u => u.Id == userIdGuid).PrimaryImagePath;
|
||||
return ApiService.GetUserById(userId, false).PrimaryImagePath;
|
||||
}
|
||||
|
||||
BaseItem item = ApiService.GetItemById(QueryString["id"]);
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -12,8 +9,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
{
|
||||
protected override Task<DTOBaseItem> GetObjectToSerialize()
|
||||
{
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -13,53 +12,48 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
{
|
||||
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);
|
||||
}));
|
||||
}
|
||||
|
||||
protected IEnumerable<BaseItem> ItemsToSerialize
|
||||
private IEnumerable<BaseItem> GetItemsToSerialize(User user)
|
||||
{
|
||||
get
|
||||
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
||||
|
||||
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
||||
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == UserId);
|
||||
|
||||
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetInProgressItems(user);
|
||||
}
|
||||
else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetRecentlyAddedItems(user);
|
||||
}
|
||||
else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetRecentlyAddedUnplayedItems(user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithGenre(QueryString["name"], user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithStudio(QueryString["name"], user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithPerson(QueryString["name"], null, user);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException();
|
||||
return parent.GetInProgressItems(user);
|
||||
}
|
||||
else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetRecentlyAddedItems(user);
|
||||
}
|
||||
else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetRecentlyAddedUnplayedItems(user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithGenre(QueryString["name"], user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithStudio(QueryString["name"], user);
|
||||
}
|
||||
else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parent.GetItemsWithPerson(QueryString["name"], null, user);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
protected string ItemId
|
||||
|
@ -70,14 +64,6 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
}
|
||||
}
|
||||
|
||||
protected Guid UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Guid.Parse(QueryString["userid"]);
|
||||
}
|
||||
}
|
||||
|
||||
private string ListType
|
||||
{
|
||||
get
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -17,8 +15,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
string name = QueryString["name"];
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -17,8 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
string name = QueryString["name"];
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
return GetAllStudios(parent, user);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -12,15 +9,12 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
{
|
||||
protected override async Task<AuthenticationResult> GetObjectToSerialize()
|
||||
{
|
||||
Guid userId = Guid.Parse(await GetFormValue("userid").ConfigureAwait(false));
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
string userId = await GetFormValue("userid").ConfigureAwait(false);
|
||||
User user = ApiService.GetUserById(userId, false);
|
||||
|
||||
string password = await GetFormValue("password").ConfigureAwait(false);
|
||||
|
||||
return new AuthenticationResult()
|
||||
{
|
||||
Success = Kernel.GetMD5(password).Equals(user.Password)
|
||||
};
|
||||
return Kernel.Instance.AuthenticateUser(user, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -17,8 +15,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
string year = QueryString["year"];
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Common.Net.Handlers;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
|
@ -14,8 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers
|
|||
protected override Task<IBNItem[]> GetObjectToSerialize()
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
User user = Kernel.Instance.Users.First(u => u.Id == userId);
|
||||
User user = ApiService.GetUserById(QueryString["userid"], true);
|
||||
|
||||
return GetAllYears(parent, user);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.DTO;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Weather;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -82,12 +83,29 @@ namespace MediaBrowser.ApiInteraction
|
|||
public async Task<DTOBaseItem[]> GetRecentlyAddedItemsAsync(Guid userId)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all Years
|
||||
/// </summary>
|
||||
|
|
|
@ -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.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
|
@ -6,12 +12,6 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
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
|
||||
{
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
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;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Common.Logging;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
|
@ -17,6 +8,15 @@ using MediaBrowser.Controller.Weather;
|
|||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
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
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
Folder folder = item as Folder;
|
||||
|
@ -236,7 +285,6 @@ namespace MediaBrowser.Controller
|
|||
|
||||
user.Name = "Default User";
|
||||
user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b");
|
||||
user.PrimaryImagePath = @"g:\Mel.jpg";
|
||||
list.Add(user);
|
||||
|
||||
user = new User();
|
||||
|
@ -245,19 +293,16 @@ namespace MediaBrowser.Controller
|
|||
user.LastLoginDate = DateTime.UtcNow.AddDays(-1);
|
||||
user.LastActivityDate = DateTime.UtcNow.AddHours(-3);
|
||||
user.Password = GetMD5("1234").ToString();
|
||||
user.PrimaryImagePath = @"g:\abobader.jpg";
|
||||
list.Add(user);
|
||||
|
||||
user = new User();
|
||||
user.Name = "Scottisafool";
|
||||
user.Id = Guid.NewGuid();
|
||||
user.PrimaryImagePath = @"g:\Scott.jpg";
|
||||
list.Add(user);
|
||||
|
||||
user = new User();
|
||||
user.Name = "Redshirt";
|
||||
user.Id = Guid.NewGuid();
|
||||
user.PrimaryImagePath = @"g:\redshirt.png";
|
||||
list.Add(user);
|
||||
|
||||
/*user = new User();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using ProtoBuf;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace MediaBrowser.Model.DTO
|
||||
namespace MediaBrowser.Model.Entities
|
||||
{
|
||||
[ProtoContract]
|
||||
public class AuthenticationResult
|
|
@ -35,7 +35,7 @@
|
|||
<Compile Include="Configuration\BaseApplicationConfiguration.cs" />
|
||||
<Compile Include="Configuration\ServerConfiguration.cs" />
|
||||
<Compile Include="DTO\AudioInfo.cs" />
|
||||
<Compile Include="DTO\AuthenticationResult.cs" />
|
||||
<Compile Include="Entities\AuthenticationResult.cs" />
|
||||
<Compile Include="DTO\DTOBaseItem.cs" />
|
||||
<Compile Include="DTO\DTOUser.cs" />
|
||||
<Compile Include="DTO\VideoInfo.cs" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user