Skip to content

Commit

Permalink
api
Browse files Browse the repository at this point in the history
  • Loading branch information
starlying committed Dec 21, 2018
1 parent d7abf43 commit 8b37161
Show file tree
Hide file tree
Showing 29 changed files with 726 additions and 85 deletions.
4 changes: 2 additions & 2 deletions SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SiteServer.Plugin, Version=2.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SiteServer.Plugin.2.1.1\lib\net45\SiteServer.Plugin.dll</HintPath>
<Reference Include="SiteServer.Plugin, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SiteServer.Plugin.2.1.3\lib\net45\SiteServer.Plugin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion SiteServer.BackgroundPages/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<package id="Microsoft.Net.Compilers" version="2.10.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="SiteServer.Plugin" version="2.1.1" targetFramework="net452" />
<package id="SiteServer.Plugin" version="2.1.3" targetFramework="net452" />
</packages>
51 changes: 51 additions & 0 deletions SiteServer.CMS/Api/V1/ApiContentsParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using SiteServer.CMS.Plugin.Impl;
using SiteServer.Utils;

namespace SiteServer.CMS.Api.V1
{
public class ApiContentsParameters
{
public ApiContentsParameters(RequestImpl request)
{
ChannelIds = TranslateUtils.StringCollectionToIntList(request.GetQueryString("channelIds"));
ChannelGroup = StringUtils.Trim(AttackUtils.FilterSql(request.GetQueryString("channelGroup")));
ContentGroup = StringUtils.Trim(AttackUtils.FilterSql(request.GetQueryString("contentGroup")));
Tag = StringUtils.Trim(AttackUtils.FilterSql(request.GetQueryString("tag")));
Top = request.GetQueryInt("top", 20);
Skip = request.GetQueryInt("skip");
Likes = TranslateUtils.StringCollectionToStringList(StringUtils.Trim(AttackUtils.FilterSql(request.GetQueryString("like"))));
OrderBy = StringUtils.Trim(AttackUtils.FilterSql(request.GetQueryString("orderBy")));
QueryString = new NameValueCollection(request.QueryString);

QueryString.Remove("siteId");
QueryString.Remove("channelIds");
QueryString.Remove("channelGroup");
QueryString.Remove("contentGroup");
QueryString.Remove("tag");
QueryString.Remove("top");
QueryString.Remove("skip");
QueryString.Remove("like");
QueryString.Remove("orderBy");
}

public List<int> ChannelIds { get; set; }

public string ChannelGroup { get; set; }

public string ContentGroup { get; set; }

public string Tag { get; set; }

public int Top { get; set; }

public int Skip { get; set; }

public List<string> Likes { get; set; }

public string OrderBy { get; set; }

public NameValueCollection QueryString { get; set; }
}
}
17 changes: 8 additions & 9 deletions SiteServer.CMS/DataCache/AdminManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache.Core;
using SiteServer.CMS.Model;
Expand Down Expand Up @@ -307,13 +306,13 @@ public static string GetRolesHtml(string userName)
{
var isConsoleAdministrator = false;
var isSystemAdministrator = false;
var arraylist = new ArrayList();
var roleNameList = new List<string>();
var roles = DataProvider.AdministratorsInRolesDao.GetRolesForUser(userName);
foreach (var role in roles)
{
if (!EPredefinedRoleUtils.IsPredefinedRole(role))
{
arraylist.Add(role);
roleNameList.Add(role);
}
else
{
Expand All @@ -330,21 +329,21 @@ public static string GetRolesHtml(string userName)
}
}

var retval = string.Empty;
var roleNames = string.Empty;

if (isConsoleAdministrator)
{
retval += EPredefinedRoleUtils.GetText(EPredefinedRole.ConsoleAdministrator);
roleNames += EPredefinedRoleUtils.GetText(EPredefinedRole.ConsoleAdministrator);
}
else if (isSystemAdministrator)
{
retval += EPredefinedRoleUtils.GetText(EPredefinedRole.SystemAdministrator);
roleNames += EPredefinedRoleUtils.GetText(EPredefinedRole.SystemAdministrator);
}
else
{
retval += TranslateUtils.ObjectCollectionToString(arraylist);
roleNames += TranslateUtils.ObjectCollectionToString(roleNameList);
}
return retval;
return roleNames;
}
}
}
16 changes: 16 additions & 0 deletions SiteServer.CMS/DataCache/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ public static List<int> GetChannelIdList(int siteId)
return dic.Values.OrderBy(c => c.Taxis).Select(channelInfo => channelInfo.Id).ToList();
}

public static List<int> GetChannelIdList(int siteId, string channelGroup)
{
var channelInfoList = new List<ChannelInfo>();
var dic = ChannelManagerCache.GetChannelInfoDictionaryBySiteId(siteId);
foreach (var channelInfo in dic.Values)
{
if (string.IsNullOrEmpty(channelInfo.GroupNameCollection)) continue;

if (StringUtils.Contains(channelInfo.GroupNameCollection, channelGroup))
{
channelInfoList.Add(channelInfo);
}
}
return channelInfoList.OrderBy(c => c.Taxis).Select(channelInfo => channelInfo.Id).ToList();
}

public static List<int> GetChannelIdList(ChannelInfo channelInfo, EScopeType scopeType)
{
return GetChannelIdList(channelInfo, scopeType, string.Empty, string.Empty, string.Empty);
Expand Down
11 changes: 11 additions & 0 deletions SiteServer.CMS/Plugin/Apis/AdminApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache;
using SiteServer.CMS.Plugin.Impl;
Expand Down Expand Up @@ -38,6 +39,16 @@ public IAdministratorInfo GetAdminInfoByAccount(string account)
return AdminManager.GetAdminInfoByAccount(account);
}

public List<string> GetUserNameList()
{
return DataProvider.AdministratorDao.GetUserNameList();
}

public IPermissions GetPermissions(string userName)
{
return new PermissionsImpl(userName);
}

public bool IsUserNameExists(string userName)
{
return DataProvider.AdministratorDao.IsUserNameExists(userName);
Expand Down
22 changes: 22 additions & 0 deletions SiteServer.CMS/Plugin/Impl/PermissionsImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public List<int> ChannelIdList
}
}

public bool IsSuperAdmin()
{
return IsConsoleAdministrator;
}

public bool IsSiteAdmin(int siteId)
{
return IsSystemAdministrator && GetSiteIdList().Contains(siteId);
}

public List<int> GetSiteIdList()
{
var siteIdList = new List<int>();
Expand Down Expand Up @@ -184,6 +194,18 @@ public PermissionsImpl(string userName)

public bool IsSystemAdministrator => EPredefinedRoleUtils.IsSystemAdministrator(Roles);

public bool IsSuperAdmin(string userName)
{
var adminPermissionsImpl = new PermissionsImpl(userName);
return adminPermissionsImpl.IsConsoleAdministrator;
}

public bool IsSiteAdmin(string userName, int siteId)
{
var adminPermissionsImpl = new PermissionsImpl(userName);
return adminPermissionsImpl.IsSystemAdministrator && adminPermissionsImpl.HasSitePermissions(siteId);
}

public List<string> PermissionList
{
get
Expand Down
76 changes: 41 additions & 35 deletions SiteServer.CMS/Plugin/Impl/RequestImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,64 @@ public RequestImpl() : this(HttpContext.Current.Request)

public RequestImpl(HttpRequest request)
{
HttpRequest = request;

var apiToken = ApiToken;
if (!string.IsNullOrEmpty(apiToken))
try
{
var tokenInfo = AccessTokenManager.GetAccessTokenInfo(apiToken);
if (tokenInfo != null)
HttpRequest = request;

var apiToken = ApiToken;
if (!string.IsNullOrEmpty(apiToken))
{
if (!string.IsNullOrEmpty(tokenInfo.AdminName))
var tokenInfo = AccessTokenManager.GetAccessTokenInfo(apiToken);
if (tokenInfo != null)
{
var adminInfo = AdminManager.GetAdminInfoByUserName(tokenInfo.AdminName);
if (adminInfo != null && !adminInfo.IsLockedOut)
if (!string.IsNullOrEmpty(tokenInfo.AdminName))
{
AdminInfo = adminInfo;
IsAdminLoggin = true;
var adminInfo = AdminManager.GetAdminInfoByUserName(tokenInfo.AdminName);
if (adminInfo != null && !adminInfo.IsLockedOut)
{
AdminInfo = adminInfo;
IsAdminLoggin = true;
}
}
}

IsApiAuthenticated = true;
IsApiAuthenticated = true;
}
}
}

var userToken = UserToken;
if (!string.IsNullOrEmpty(userToken))
{
var tokenImpl = ParseAccessToken(userToken);
if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
var userToken = UserToken;
if (!string.IsNullOrEmpty(userToken))
{
var userInfo = UserManager.GetUserInfoByUserId(tokenImpl.UserId);
if (userInfo != null && !userInfo.IsLockedOut && userInfo.IsChecked && userInfo.UserName == tokenImpl.UserName)
var tokenImpl = ParseAccessToken(userToken);
if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
{
UserInfo = userInfo;
IsUserLoggin = true;
var userInfo = UserManager.GetUserInfoByUserId(tokenImpl.UserId);
if (userInfo != null && !userInfo.IsLockedOut && userInfo.IsChecked && userInfo.UserName == tokenImpl.UserName)
{
UserInfo = userInfo;
IsUserLoggin = true;
}
}
}
}

var adminToken = AdminToken;
if (!string.IsNullOrEmpty(adminToken))
{
var tokenImpl = ParseAccessToken(adminToken);
if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
var adminToken = AdminToken;
if (!string.IsNullOrEmpty(adminToken))
{
var adminInfo = AdminManager.GetAdminInfoByUserId(tokenImpl.UserId);
if (adminInfo != null && !adminInfo.IsLockedOut && adminInfo.UserName == tokenImpl.UserName)
var tokenImpl = ParseAccessToken(adminToken);
if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
{
AdminInfo = adminInfo;
IsAdminLoggin = true;
var adminInfo = AdminManager.GetAdminInfoByUserId(tokenImpl.UserId);
if (adminInfo != null && !adminInfo.IsLockedOut && adminInfo.UserName == tokenImpl.UserName)
{
AdminInfo = adminInfo;
IsAdminLoggin = true;
}
}
}
}
catch (Exception ex)
{
LogUtils.AddErrorLog(ex);
}
}

public bool IsApiAuthenticated { get; }
Expand Down Expand Up @@ -237,8 +244,7 @@ public decimal GetQueryDecimal(string name, decimal defaultValue = 0)
public bool GetQueryBool(string name, bool defaultValue = false)
{
var str = HttpRequest.QueryString[name];
var retval = !string.IsNullOrEmpty(str) ? TranslateUtils.ToBool(str) : defaultValue;
return retval;
return !string.IsNullOrEmpty(str) ? TranslateUtils.ToBool(str) : defaultValue;
}

public bool IsPostExists(string name)
Expand Down
Loading

0 comments on commit 8b37161

Please sign in to comment.