Skip to content
Permalink
Browse files

Fix Initial User Creation when password is specified

  • Loading branch information...
da3dsoul committed Apr 2, 2019
1 parent af4603d commit 38e904012b44a3615805d48c27453f78f159d3c1
Showing with 33 additions and 31 deletions.
  1. +29 −30 Shoko.Server/API/APIHelper.cs
  2. +4 −1 Shoko.Server/Databases/BaseDatabase.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using Nancy;
using Shoko.Models.PlexAndKodi;
using Shoko.Server.API.v2.Models.common;
@@ -16,73 +17,71 @@ public static class APIHelper

public static string ConstructUnsortUrl(NancyContext ctx, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "/api/file/unsort", short_url);
return ProperURL(ctx, "/api/file/unsort", short_url);
}

[Obsolete]
public static string ConstructGroupIdUrl(NancyContext ctx, string gid, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "__TEST__" + (int) JMMType.Group + "/" + gid, short_url);
return ProperURL(ctx, "__TEST__" + (int) JMMType.Group + "/" + gid, short_url);
}

[Obsolete]
public static string ConstructSerieIdUrl(NancyContext ctx, string sid, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "__TEST__" + (int) JMMType.Serie + " / " + sid, short_url);
return ProperURL(ctx, "__TEST__" + (int) JMMType.Serie + " / " + sid, short_url);
}

[Obsolete]
public static string ConstructVideoUrl(NancyContext ctx, string vid, JMMType type, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "__TEST__" + (int) type + "/" + vid, short_url);
return ProperURL(ctx, "__TEST__" + (int) type + "/" + vid, short_url);
}

public static string ConstructFilterIdUrl(NancyContext ctx, int groupfilter_id, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "/api/filter?id=" + groupfilter_id, short_url);
return ProperURL(ctx, "/api/filter?id=" + groupfilter_id, short_url);
}

public static string ConstructFilterUrl(NancyContext ctx, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "/api/filter", short_url);
return ProperURL(ctx, "/api/filter", short_url);
}

[Obsolete]
public static string ConstructFiltersUrl(NancyContext ctx, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "__TEST__", short_url);
return ProperURL(ctx, "__TEST__", short_url);
}

[Obsolete]
public static string ConstructSearchUrl(NancyContext ctx, string limit, string query, bool searchTag, bool short_url = false)
{
if (searchTag)
{
return APIHelper.ProperURL(ctx, "/api/searchTag/" + limit + "/" + System.Net.WebUtility.UrlEncode(query),
short_url);
}
else
{
return APIHelper.ProperURL(ctx, "/api/search/" + limit + "/" + System.Net.WebUtility.UrlEncode(query),
return ProperURL(ctx, "/api/searchTag/" + limit + "/" + WebUtility.UrlEncode(query),
short_url);
}

return ProperURL(ctx, "/api/search/" + limit + "/" + WebUtility.UrlEncode(query),
short_url);
}

[Obsolete]
public static string ConstructPlaylistUrl(NancyContext ctx, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "/api/metadata/" + (int) JMMType.Playlist + "/0", short_url);
return ProperURL(ctx, "/api/metadata/" + (int) JMMType.Playlist + "/0", short_url);
}

[Obsolete]
public static string ConstructPlaylistIdUrl(NancyContext ctx, int pid, bool short_url = false)
{
return APIHelper.ProperURL(ctx, "/api/metadata/" + (int) JMMType.Playlist + "/" + pid, short_url);
return ProperURL(ctx, "/api/metadata/" + (int) JMMType.Playlist + "/" + pid, short_url);
}

public static string ConstructSupportImageLink(NancyContext ctx, string name, bool short_url = true)
{
return APIHelper.ProperURL(ctx, "/api/image/support/" + name, short_url);
return ProperURL(ctx, "/api/image/support/" + name, short_url);
}

public static string ConstructImageLinkFromRest(NancyContext ctx, string path, bool short_url = true)
@@ -92,12 +91,12 @@ public static string ConstructImageLinkFromRest(NancyContext ctx, string path, b

public static string ConstructImageLinkFromTypeAndId(NancyContext ctx, int type, int id, bool short_url = true)
{
return APIHelper.ProperURL(ctx, "/api/image/" + type.ToString() + "/" + id.ToString(), short_url);
return ProperURL(ctx, "/api/image/" + type + "/" + id, short_url);
}

public static string ConstructVideoLocalStream(NancyContext ctx, int userid, string vid, string name, bool autowatch)
{
return APIHelper.ProperURL(ctx, "/Stream/" + vid + "/" + userid + "/" + autowatch + "/" + name);
return ProperURL(ctx, "/Stream/" + vid + "/" + userid + "/" + autowatch + "/" + name);
}

#endregion
@@ -110,7 +109,7 @@ private static string ConvertRestImageToNonRestUrl(NancyContext ctx, string url,
// Regardless of ',' or '.', ratio will not parse as int
if (string.IsNullOrEmpty(url)) return null;
string link = url.ToLower();
string[] split = link.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
string[] split = link.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
int type;
if (int.TryParse(split[split.Length - 1], out int id)) // no ratio
{
@@ -135,7 +134,7 @@ public static Filter FilterFromGroupFilter(NancyContext ctx, SVR_GroupFilter gg,
{
name = gg.GroupFilterName,
id = gg.GroupFilterID,
url = APIHelper.ConstructFilterIdUrl(ctx, gg.GroupFilterID)
url = ConstructFilterIdUrl(ctx, gg.GroupFilterID)
};
if (gg.GroupsIds.ContainsKey(uid))
{
@@ -151,10 +150,10 @@ public static Filter FilterFromGroupFilter(NancyContext ctx, SVR_GroupFilter gg,
Video v = ag.GetPlexContract(uid);
if (v?.Art != null && v.Thumb != null)
{
ob.art.fanart.Add(new Art() {url = APIHelper.ConstructImageLinkFromRest(ctx, v.Art), index = 0});
ob.art.thumb.Add(new Art()
ob.art.fanart.Add(new Art {url = ConstructImageLinkFromRest(ctx, v.Art), index = 0});
ob.art.thumb.Add(new Art
{
url = APIHelper.ConstructImageLinkFromRest(ctx, v.Thumb),
url = ConstructImageLinkFromRest(ctx, v.Thumb),
index = 0
});
break;
@@ -171,7 +170,7 @@ public static Filter FilterFromAnimeGroup(NancyContext ctx, SVR_AnimeGroup grp,
{
name = grp.GroupName,
id = grp.AnimeGroupID,
url = APIHelper.ConstructFilterIdUrl(ctx, grp.AnimeGroupID),
url = ConstructFilterIdUrl(ctx, grp.AnimeGroupID),
size = -1,
viewed = -1
};
@@ -185,23 +184,23 @@ public static Filter FilterFromAnimeGroup(NancyContext ctx, SVR_AnimeGroup grp,

if (fanart != null)
{
ob.art.fanart.Add(new Art()
ob.art.fanart.Add(new Art
{
url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int) fanart.ImageType, fanart.ImageID),
url = ConstructImageLinkFromTypeAndId(ctx, (int) fanart.ImageType, fanart.ImageID),
index = ob.art.fanart.Count
});
ob.art.thumb.Add(new Art()
ob.art.thumb.Add(new Art
{
url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int) fanart.ImageType, fanart.ImageID),
url = ConstructImageLinkFromTypeAndId(ctx, (int) fanart.ImageType, fanart.ImageID),
index = ob.art.thumb.Count
});
}

if (banner != null)
{
ob.art.banner.Add(new Art()
ob.art.banner.Add(new Art
{
url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int) banner.ImageType, banner.ImageID),
url = ConstructImageLinkFromTypeAndId(ctx, (int) banner.ImageType, banner.ImageID),
index = ob.art.banner.Count
});
}
@@ -404,14 +404,17 @@ private void CreateInitialUsers()

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

string defaultPassword = ServerSettings.DefaultUserPassword == ""
? ""
: Digest.Hash(ServerSettings.DefaultUserPassword);
SVR_JMMUser defaultUser = new SVR_JMMUser
{
CanEditServerSettings = 1,
HideCategories = string.Empty,
IsAdmin = 1,
IsAniDBUser = 1,
IsTraktUser = 1,
Password = ServerSettings.DefaultUserPassword,
Password = defaultPassword,
Username = ServerSettings.DefaultUserUsername
};
RepoFactory.JMMUser.Save(defaultUser, true);

0 comments on commit 38e9040

Please sign in to comment.
You can’t perform that action at this time.