diff --git a/.gitignore b/.gitignore index 509668d..fecad19 100644 --- a/.gitignore +++ b/.gitignore @@ -303,3 +303,7 @@ __pycache__/ # OpenCover UI analysis results OpenCover/ +COMCMS.Web/wwwroot/userfiles/ +/COMCMS.Web/COMCMS.Web.csproj.DotSettings +/COMCMS.Web/UploadFile +/COMCMS.Web/UploadTemp diff --git a/COMCMS.Common/AuthenticationHelper.cs b/COMCMS.Common/AuthenticationHelper.cs new file mode 100644 index 0000000..bc0718f --- /dev/null +++ b/COMCMS.Common/AuthenticationHelper.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Security.Claims; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Http; + +namespace COMCMS.Common +{ + /// + /// 认证助手 + /// + public class AuthenticationHelper + { + /* + 登陆过程 + + //信息类型集合,比如姓名、性别、出生日期 + var claims = new[] + { + new Claim("UserName",username) + }; + + //信息类型集合组合成一张证件,比如身份证、驾照、护照 + var claimsIdentity = new ClaimsIdentity(claims,CookieAuthenticationDefaults.AuthenticationScheme); + + //持有者,拥有以上证件的持有者,同时有身份证、驾照、护照、教师证的一个人 + var user = new ClaimsPrincipal(claimsIdentity); + + //注册改证件持有者 + HttpContext.SignInAsync( + CookieAuthenticationDefaults.AuthenticationScheme, + user, + new AuthenticationProperties + { + IsPersistent = true,//session跨多个请求,否则只在当前请求有效 + ExpiresUtc = (remember ?? false) ? (DateTimeOffset?)null : DateTimeOffset.Now.AddMilliseconds(60 * 2),//过期时间,null表示不过期 + }).Wait(); + */ + + private static ClaimsPrincipal _user => _httpContext.User; + private static HttpContext _httpContext => MyHttpContext.Current; + + #region 获取Claim + + /// + /// 获取一项claim信息 + /// + /// claim名称 + /// + public static string GetClaim(string claimType) + { + if (_user != null && _user.HasClaim(c => c.Type == claimType)) + { + return _user.FindFirst(claimType).Value; + } + + return ""; + } + + #endregion + + #region 登录 + + /// + /// 登录 + /// + /// 身份信息项集合 + /// 过期时间,null为不过期 + /// 认证方式,默认为cookie方式 + /// + public static async Task SignInAsync(Claim[] claims, DateTimeOffset? expiresUtc, + string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme) + { + var claimsIdentity = new ClaimsIdentity(claims, authenticationScheme); + var user = new ClaimsPrincipal(claimsIdentity); + + var authenticationProperties = new AuthenticationProperties + { + IsPersistent = true, //session跨多个请求,否则只在当前请求有效 + ExpiresUtc = expiresUtc, //过期时间,null表示不过期 + }; + + await _httpContext.SignInAsync(authenticationScheme, user, authenticationProperties); + } + + /// + /// 登录 + /// + /// 身份证持有者 + /// 过期时间,null为不过期 + /// 认证方式,默认为cookie方式 + /// + public static async Task SignInAsync(ClaimsPrincipal claimsPrincipal, DateTimeOffset? expiresUtc, + string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme) + { + var authenticationProperties = new AuthenticationProperties + { + IsPersistent = true, //session跨多个请求,否则只在当前请求有效 + ExpiresUtc = expiresUtc, //过期时间,null表示不过期 + }; + + await _httpContext.SignInAsync(authenticationScheme, claimsPrincipal, authenticationProperties); + } + + #endregion + + #region 注销 + + /// + /// 注销 + /// + /// 认证方式 + /// + public static async Task SignOutAsync(string authenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme) + { + await _httpContext.SignOutAsync(authenticationScheme); + } + + #endregion + } +} diff --git a/COMCMS.Common/COMCMS.Common.csproj b/COMCMS.Common/COMCMS.Common.csproj index f43dc64..471d873 100644 --- a/COMCMS.Common/COMCMS.Common.csproj +++ b/COMCMS.Common/COMCMS.Common.csproj @@ -5,10 +5,16 @@ - - + + + + + C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.cookies\2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Cookies.dll + + + diff --git a/COMCMS.Common/MyDIMiddleware.cs b/COMCMS.Common/MyDIMiddleware.cs new file mode 100644 index 0000000..d9d757c --- /dev/null +++ b/COMCMS.Common/MyDIMiddleware.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Builder; + +namespace COMCMS.Common +{ + public static class Extensions + { + + public static IApplicationBuilder UseMyMVCDI(this IApplicationBuilder builder) + { + DI.ServiceProvider = builder.ApplicationServices; + return builder; + } + } + /// + /// 依赖注入 + /// + public static class DI + { + public static IServiceProvider ServiceProvider + { + get;set; + } + } +} diff --git a/COMCMS.Common/MySign.cs b/COMCMS.Common/MySign.cs index f3a0ed0..a9e561c 100644 --- a/COMCMS.Common/MySign.cs +++ b/COMCMS.Common/MySign.cs @@ -43,5 +43,34 @@ namespace COMCMS.Common return prestr.ToString(); } #endregion + + #region 生成签名后的地址 + /// + /// 根据规则生成请求地址 + /// + /// + /// + /// + public static string CreateSignURL(SortedDictionary dicArray, string host) + { + StringBuilder prestr = new StringBuilder(); + StringBuilder urlstr = new StringBuilder(); + foreach (KeyValuePair temp in dicArray) + { + if (temp.Key != "signature") + { + prestr.Append(temp.Value); + urlstr.Append(temp.Key + "=" + temp.Value + "&"); + } + } + NewLife.Log.XTrace.WriteLine("加密前数据:" + prestr); + string mysign = Utils.MD5(prestr.ToString() + Utils.SIGNSALT); + + urlstr.Append("signature=" + mysign); + + string reUrl = host + "?" + urlstr.ToString(); + return reUrl; + } + #endregion } } diff --git a/COMCMS.Common/ThumbnailHelper.cs b/COMCMS.Common/ThumbnailHelper.cs index f49d535..0137a40 100644 --- a/COMCMS.Common/ThumbnailHelper.cs +++ b/COMCMS.Common/ThumbnailHelper.cs @@ -4,11 +4,30 @@ using System.DrawingCore.Drawing2D; using System.DrawingCore.Imaging; using System.Text; using System.DrawingCore; +using System.Net; +using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Hosting; +using System.IO; +using NewLife.Log; namespace COMCMS.Common { public class ThumbnailHelper { + /// + /// 目录分隔符 + /// windows 下是 \ linux 下面是 \ + /// + private static string DirectorySeparatorChar = Path.DirectorySeparatorChar.ToString(); + /// + /// 程序绝对目录 + /// + private static string _ContentRootPath = DI.ServiceProvider.GetService().ContentRootPath; + /// + /// 静态文件 + /// + private static string _WebRootPath = DI.ServiceProvider.GetService().WebRootPath; + #region 方式 public enum CutMode { @@ -126,6 +145,8 @@ namespace COMCMS.Common } #endregion + + #region 帮助方法 /// /// 保存图片 /// @@ -178,6 +199,63 @@ namespace COMCMS.Common return ImageFormat.Jpeg; } } + #endregion + + #region 内容远程保存图片 + /// + /// 保存内容种远程图片到本地 + /// + /// + /// + public static string SaveRemoteImgForContent(string content) + { + string recontent = content; + if (string.IsNullOrEmpty(content)) + return ""; + WebClient client = new WebClient(); + + Regex reg = new Regex("IMG[^>]*?src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^\']*)')", RegexOptions.IgnoreCase); + MatchCollection m = reg.Matches(content); + foreach (Match math in m) + { + string imgUrl = math.Groups[1].Value; + Regex regName = new Regex(@"\w+(?:jpg|gif|bmp|png|jpeg)", RegexOptions.IgnoreCase);//不按点。这样可以兼容复制公众号文章 + string imgName = imgUrl.Substring(imgUrl.LastIndexOf("/") + 1, imgUrl.Length - imgUrl.LastIndexOf("/") - 1); + //判断是否是远程图片 + if (imgUrl.ToLower().StartsWith("http://") || imgUrl.ToLower().StartsWith("https://") || imgUrl.ToLower().StartsWith("ftp://")) + { + string imgsrc = imgName.ToLower(); + string ext = "jpg"; + if (imgsrc.EndsWith("gif")) ext = "gif"; + else if (imgsrc.EndsWith("png")) ext = "png"; + else if (imgsrc.EndsWith("jpeg")) ext = "jpeg"; + else if (imgsrc.EndsWith("bmp")) ext = "bmp"; + string strNewImgName = Utils.GetOrderNum() + "." + ext; + string savepath = $"{_WebRootPath}\\userfiles\\images\\auto\\{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}";// + string imgNewSrc = $"/userfiles/images/auto/{DateTime.Now.Year.ToString()}/{DateTime.Now.ToString("MM")}/{strNewImgName}";//保存后路径 + //判断路径 + if (!Directory.Exists(savepath)) + Directory.CreateDirectory(savepath); + string fullpath = Path.Combine(savepath, strNewImgName);//图片 + try + { + //保存图片 + client.DownloadFile(imgUrl, fullpath); + recontent = recontent.Replace(imgUrl, imgNewSrc); + } + catch (Exception ex) + { + //throw new Exception(ex.Message); + XTrace.WriteLine($"远程保存图片保存图片:{imgUrl},错误:{ex.Message}"); + } + } + + } + + return recontent; + } + #endregion + } diff --git a/COMCMS.Common/Utils.cs b/COMCMS.Common/Utils.cs index 97aecdf..4a93e12 100644 --- a/COMCMS.Common/Utils.cs +++ b/COMCMS.Common/Utils.cs @@ -22,10 +22,15 @@ namespace COMCMS.Common static Utils() { - //ReloadOnChange = true 当appsettings.json被修改时重新加载 - Configuration = new ConfigurationBuilder() - .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) - .Build(); + ////ReloadOnChange = true 当appsettings.json被修改时重新加载 + //Configuration = new ConfigurationBuilder() + //.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) + //.Build(); + } + + public static void AddUtils(IConfiguration configuration) + { + Configuration = configuration; } #region 静态变量 @@ -703,6 +708,59 @@ namespace COMCMS.Common TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalSeconds).ToString(); } + + /// + /// 获取JS时间戳 + /// + /// + public static string GetJSTimeStamp() + { + TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); + return Convert.ToInt64(ts.TotalMilliseconds).ToString(); + } + + /// + /// 获取当前URL绝对地址 + /// + /// + public static string GetNowURL() + { + string url = GetServerUrl() + MyHttpContext.Current.Request.Path; + string querystring = MyHttpContext.Current.Request.QueryString.ToString(); + if (!string.IsNullOrWhiteSpace(querystring)) + url = url + querystring; + + return url; + } + + /// + /// 获取post表单金钱字段值 + /// + /// + /// + public static decimal GetPostFormMoney(string inputName) + { + string v = MyHttpContext.Current.Request.Form[inputName]; + decimal price = 0M; + if (!IsDecimal(v) && decimal.Parse(v) < 0) v = "0"; + price = decimal.Parse(v); + return price; + } + + /// + /// 获取get表单金钱字段值 + /// + /// + /// + public static decimal GetQueryStringMoney(string inputName) + { + string v = MyHttpContext.Current.Request.Query[inputName]; + decimal price = 0M; + if (!IsDecimal(v) && decimal.Parse(v) < 0) v = "0"; + price = decimal.Parse(v); + return price; + } + #endregion #region 处理部分 @@ -954,4 +1012,36 @@ namespace COMCMS.Common #endregion } + + #region 常用扩展方法 + /// + /// 扩展方法 + /// + public static class CommExtension + { + #region 货币转换 + /// + /// 数据库中金额换成元单位 + /// + /// + /// + public static decimal ConvertToMoney(this int price) + { + decimal realPrice = (decimal)price / 100; + return realPrice; + } + + /// + /// 元单位的金额换算成分 + /// + /// + /// + public static int ConvertMoneyToInt(this decimal price) + { + return (int)(price * 100); + } + #endregion + + } + #endregion } diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index b61a5ca..3346f3c 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -5,7 +5,7 @@ - + @@ -13,4 +13,10 @@ + + + C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.authentication.cookies\2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Authentication.Cookies.dll + + + diff --git a/COMCMS.Core/Core/友情连接详情.Biz.cs b/COMCMS.Core/Core/友情连接详情.Biz.cs index 710d0eb..9bb31d6 100644 --- a/COMCMS.Core/Core/友情连接详情.Biz.cs +++ b/COMCMS.Core/Core/友情连接详情.Biz.cs @@ -90,7 +90,7 @@ namespace COMCMS.Core { get { - if (_LinkKind == null && KId > 0 && !Dirtys.ContainsKey("LinkKind_" + KId)) + if (_LinkKind == null && KId > 0 && !Dirtys["LinkKind_" + KId]) { _LinkKind = LinkKind.Find(LinkKind._.Id == KId); Dirtys["LinkKind_" + KId] = true; diff --git a/COMCMS.Core/Core/后台菜单.Biz.cs b/COMCMS.Core/Core/后台菜单.Biz.cs index d5a88eb..84175eb 100644 --- a/COMCMS.Core/Core/后台菜单.Biz.cs +++ b/COMCMS.Core/Core/后台菜单.Biz.cs @@ -103,7 +103,7 @@ namespace COMCMS.Core { get { - if (_ListEvent == null && Id > 0 && !Dirtys.ContainsKey("ListEvent_" + Id)) + if (_ListEvent == null && Id > 0 && !Dirtys["ListEvent_" + Id]) { _ListEvent = AdminMenuEvent.FindAll(AdminMenuEvent._.MenuId == Id, AdminMenuEvent._.Id.Asc(), null, 0, 0); Dirtys["ListEvent_" + Id] = true; diff --git a/COMCMS.Core/Core/用户.Biz.cs b/COMCMS.Core/Core/用户.Biz.cs index 6c68a51..be826a1 100644 --- a/COMCMS.Core/Core/用户.Biz.cs +++ b/COMCMS.Core/Core/用户.Biz.cs @@ -154,7 +154,7 @@ namespace COMCMS.Core { get { - if (_Roles == null && RoleId > 0 && !Dirtys.ContainsKey("RoleId_" + RoleId)) + if (_Roles == null && RoleId > 0 && !Dirtys["RoleId_" + RoleId]) { _Roles = MemberRoles.Find(MemberRoles._.Id == RoleId); Dirtys["RoleId_" + RoleId] = true; diff --git a/COMCMS.Core/Core/管理员.Biz.cs b/COMCMS.Core/Core/管理员.Biz.cs index 2abe8c3..bdca1ad 100644 --- a/COMCMS.Core/Core/管理员.Biz.cs +++ b/COMCMS.Core/Core/管理员.Biz.cs @@ -4,6 +4,8 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; +using System.Security.Claims; +using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Web; @@ -21,11 +23,14 @@ using XCode.Configuration; using XCode.DataAccessLayer; using XCode.Membership; using COMCMS.Common; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Authentication.Cookies; namespace COMCMS.Core { /// 管理员 - public partial class Admin : Entity + public partial class Admin : Entity, IIdentity { #region 对象操作 static Admin() @@ -95,13 +100,17 @@ namespace COMCMS.Core #endregion #region 扩展属性 + string IIdentity.Name { get; } + string IIdentity.AuthenticationType { get; } + bool IIdentity.IsAuthenticated { get; } + private AdminRoles _Roles; /// 用户对应的管理组 public AdminRoles Roles { get { - if (_Roles == null && RoleId > 0 && !Dirtys.ContainsKey("AdminRoleId_" + RoleId)) + if (_Roles == null && RoleId > 0 && !Dirtys["AdminRoleId_" + RoleId]) { _Roles = AdminRoles.Find(AdminRoles._.Id == RoleId); Dirtys["AdminRoleId_" + RoleId] = true; @@ -175,7 +184,9 @@ namespace COMCMS.Core { if (IsAdminLogin()) { - return Find(_.UserName == SessionHelper.GetSession(sessionAdminNameKey).ToString()); + //return Find(_.UserName == SessionHelper.GetSession(sessionAdminNameKey).ToString()); + return Find(_.UserName == AuthenticationHelper.GetClaim(sessionAdminNameKey)); + } else { @@ -230,7 +241,9 @@ namespace COMCMS.Core //写入Session 和 Cookies //SessionHelper.WriteSession("rtadminguid", GUID.ToString()); //CookiesHelper.WriteCookie("rtadminguid", GUID.ToString(), 120); - SetAdminInfo(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt); + //SetAdminInfo(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt); + SetAdminInfoAsync(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt).Wait(); + return true; } } @@ -242,16 +255,22 @@ namespace COMCMS.Core /// 是否登录 public static bool IsAdminLogin() { - string adminName = SessionHelper.GetSession(sessionAdminNameKey).ToString();//用户名 - string adminID = SessionHelper.GetSession(sessionAdminIDKey).ToString();//ID + //string adminName = SessionHelper.GetSession(sessionAdminNameKey).ToString();//用户名 + //string adminID = SessionHelper.GetSession(sessionAdminIDKey).ToString();//ID + string adminName = AuthenticationHelper.GetClaim(sessionAdminNameKey);//用户名 + string adminID = AuthenticationHelper.GetClaim(sessionAdminIDKey);//ID //如果Session失效,则用Cookies判断 if (string.IsNullOrEmpty(adminName) || string.IsNullOrEmpty(adminID)) { - string cooAdminName = CookiesHelper.GetCookie(cookiesAdminNameKey);//用户名 - string cooAdminID = CookiesHelper.GetCookie(cookiesAdminIDKey);//ID - string cooLoginInfo = CookiesHelper.GetCookie(cookiesAdminInfoKey);//信息 - string cooAdminLogID = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID + //string cooAdminName = CookiesHelper.GetCookie(cookiesAdminNameKey);//用户名 + //string cooAdminID = CookiesHelper.GetCookie(cookiesAdminIDKey);//ID + //string cooLoginInfo = CookiesHelper.GetCookie(cookiesAdminInfoKey);//信息 + //string cooAdminLogID = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID + string cooAdminName = AuthenticationHelper.GetClaim(cookiesAdminNameKey);//用户名 + string cooAdminID = AuthenticationHelper.GetClaim(cookiesAdminIDKey);//ID + string cooLoginInfo = AuthenticationHelper.GetClaim(cookiesAdminInfoKey);//信息 + string cooAdminLogID = AuthenticationHelper.GetClaim(cookiesAdminLogIDKey);//日志GUID if (string.IsNullOrEmpty(cooAdminID) || string.IsNullOrEmpty(cooAdminName) || string.IsNullOrEmpty(cooLoginInfo) || string.IsNullOrEmpty(cooAdminLogID)) { @@ -273,17 +292,22 @@ namespace COMCMS.Core //获取日志ID if (AdminLog.FindByGUID(cooAdminLogID) == null) { - ClearInfo();//清除信息 + //ClearInfo();//清除信息 + ClearInfoAsync().Wait(); return false;//日志出错 } //重新写入Session 和 Cookies - SetAdminInfo(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt); + //SetAdminInfo(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt); + + SetAdminInfoAsync(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt).Wait(); + return true; } else { - ClearInfo();//清除信息 + //ClearInfo();//清除信息 + ClearInfoAsync().Wait(); return false;//信息错误 } } @@ -322,6 +346,36 @@ namespace COMCMS.Core CookiesHelper.WriteCookie(sessionAdminLogIDKey, adminLogID, 120); } + /// + /// 设置管理员信息,写入Session 和Cookies + /// + /// 是否是超级管理员 + /// 管理员管理权限 + /// 后台日志ID + public static async Task SetAdminInfoAsync(string adminName, string adminPwd, int adminID, int isSupperAdmin, string adminPower, string adminLogID, string adminSalt) + { + var expiresUtc = DateTimeOffset.Now.AddMinutes(60 * 2); + + var claimsIdentity = new ClaimsIdentity(new[] + { + new Claim(sessionAdminIDKey, adminID.ToString()), + new Claim(sessionAdminNameKey, adminName), + new Claim(sessionAdminPowerKey, adminPower), + new Claim(sessionIsSupperAdminKey, isSupperAdmin.ToString()), + new Claim(sessionAdminLogIDKey, adminLogID), + + new Claim(cookiesAdminIDKey, adminID.ToString()), + new Claim(cookiesAdminNameKey, adminName), + //2016-6-01 增加IP加密信息,防止cookies被盗用 + new Claim(cookiesAdminInfoKey, Utils.MD5(adminName + adminPwd + adminSalt + Utils.GetIP())), + }); + + var genericPrincipal = new ClaimsPrincipal(claimsIdentity); + + await AuthenticationHelper.SignInAsync(genericPrincipal, expiresUtc); + } + + /// /// 管理员退出登录,清除信息 /// @@ -341,6 +395,15 @@ namespace COMCMS.Core CookiesHelper.ClearCookies(sessionAdminLogIDKey); } + /// + /// 管理员退出登录,清除信息 + /// + /// + public static async Task ClearInfoAsync() + { + await AuthenticationHelper.SignOutAsync(); + } + /// /// 写入日志 /// @@ -349,17 +412,19 @@ namespace COMCMS.Core { if (IsAdminLogin()) { - string adminLogId = SessionHelper.GetSession(sessionAdminLogIDKey).ToString(); + //string adminLogId = SessionHelper.GetSession(sessionAdminLogIDKey).ToString(); + string adminLogId = AuthenticationHelper.GetClaim(sessionAdminLogIDKey); if (string.IsNullOrEmpty(adminLogId)) { - adminLogId = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID + //adminLogId = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID + adminLogId = AuthenticationHelper.GetClaim(cookiesAdminLogIDKey);//日志GUID } if (!string.IsNullOrEmpty(adminLogId)) { AdminLog log = AdminLog.FindByGUID(adminLogId); if (log != null) { - log.Actions = log.Actions + action; + log.Actions = log.Actions + $"|||{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}: {action}"; log.LastUpdateTime = DateTime.Now; log.Update(); diff --git a/COMCMS.Core/Core/系统配置.Biz.cs b/COMCMS.Core/Core/系统配置.Biz.cs index 66f8e95..6a299bb 100644 --- a/COMCMS.Core/Core/系统配置.Biz.cs +++ b/COMCMS.Core/Core/系统配置.Biz.cs @@ -96,7 +96,7 @@ namespace COMCMS.Core { get { - if (_AttachConfigEntity == null && !Dirtys.ContainsKey("AttachConfig")) + if (_AttachConfigEntity == null && !Dirtys["AttachConfig"]) { OtherConfig ac = OtherConfig.Find(OtherConfig._.ConfigName == "attach"); @@ -105,7 +105,7 @@ namespace COMCMS.Core if (!string.IsNullOrEmpty(ac.ConfigValue)) { _AttachConfigEntity = JsonConvert.DeserializeObject(ac.ConfigValue); - Dirtys.Add("AttachConfig", true); + Dirtys["AttachConfig"] = true; } else { @@ -137,14 +137,14 @@ namespace COMCMS.Core { get { - if (_SMTPConfigEntity == null && !Dirtys.ContainsKey("SMTPConfig")) + if (_SMTPConfigEntity == null && !Dirtys["SMTPConfig"]) { OtherConfig ac = OtherConfig.Find(OtherConfig._.ConfigName == "smtp"); if (ac != null) { _SMTPConfigEntity = JsonConvert.DeserializeObject(ac.ConfigValue); - Dirtys.Add("SMTPConfig", true); + Dirtys["SMTPConfig"] = true; } else { diff --git a/COMCMS.Core/Models/SMTPConfig.cs b/COMCMS.Core/Models/SMTPConfig.cs index d198523..3e5311e 100644 --- a/COMCMS.Core/Models/SMTPConfig.cs +++ b/COMCMS.Core/Models/SMTPConfig.cs @@ -69,6 +69,10 @@ namespace COMCMS.Core.Models set { _postusername = value; } get { return _postusername; } } + /// + /// 是否采用SSL发信 + /// + public int IsSSL { get; set; } = 0; #endregion Model } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 0a73ab9..07c98c3 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -301,6 +301,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } } } + string content = model.Content; + if(Request.Form["autoSaveRemoteImg"] == "1" && !string.IsNullOrEmpty(content)) + { + content = ThumbnailHelper.SaveRemoteImgForContent(content); + model.Content = content; + } model.ItemImg = morIMG; model.AuthorId = Core.Admin.GetMyInfo().Id; model.Insert(); @@ -392,6 +398,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers model.UpdateTime = DateTime.Now; model.ItemImg = morIMG; + string content = model.Content; + if (Request.Form["autoSaveRemoteImg"] == "1" && !string.IsNullOrEmpty(content)) + { + content = ThumbnailHelper.SaveRemoteImgForContent(content); + model.Content = content; + } //model.AuthorId = Core.Admin.GetMyInfo().Id; model.Save(); //Tag.ModifyTags(model.Tags, RTType.RatuoModule.Article, model.Id, model.Title); diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs index 91a09e2..ebb20d2 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs @@ -115,7 +115,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// public IActionResult Logout() { - Admin.ClearInfo(); + //Admin.ClearInfo(); + Admin.ClearInfoAsync().Wait(); return Redirect("~/AdminCP/Login"); } #endregion diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs index 7c72117..0440ad6 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs @@ -32,7 +32,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } [HttpPost] [MyAuthorize("view", "editme", "JSON")] - public IActionResult EditMe(FormCollection fc) + public IActionResult EditMe(IFormCollection fc) { Core.Admin my = Core.Admin.GetMyInfo(); @@ -134,7 +134,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行添加管理组 [HttpPost] [MyAuthorize("add", "adminrole", "JSON")] - public IActionResult AddAdminRole(FormCollection fc) + public IActionResult AddAdminRole(IFormCollection fc) { string RoleName = fc["RoleName"]; string RoleDescription = fc["RoleDescription"]; @@ -236,7 +236,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行编辑管理组 [HttpPost] [MyAuthorize("edit", "adminrole", "JSON")] - public IActionResult EditAdminRole(FormCollection fc) + public IActionResult EditAdminRole(IFormCollection fc) { string Id = fc["Id"]; string RoleName = fc["RoleName"]; @@ -408,7 +408,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行添加管理员 [HttpPost] [MyAuthorize("add", "admins", "JSON")] - public IActionResult AddAdmin(FormCollection fc) + public IActionResult AddAdmin(IFormCollection fc) { string userName = fc["UserName"]; string newPwd = fc["PassWord"]; @@ -487,7 +487,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //执行编辑管理员 [HttpPost] [MyAuthorize("edit", "admins", "JSON")] - public IActionResult EditAdmin(FormCollection fc) + public IActionResult EditAdmin(IFormCollection fc) { string userName = fc["UserName"]; string newPwd = fc["PassWord"]; diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs index b8c7a85..90cd0cf 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs @@ -301,6 +301,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } } } + string content = model.Content; + if (Request.Form["autoSaveRemoteImg"] == "1" && !string.IsNullOrEmpty(content)) + { + content = ThumbnailHelper.SaveRemoteImgForContent(content); + model.Content = content; + } model.ItemImg = morIMG; model.AuthorId = Core.Admin.GetMyInfo().Id; model.Insert(); @@ -399,6 +405,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers model.UpdateTime = DateTime.Now; model.ItemImg = morIMG; + string content = model.Content; + if (Request.Form["autoSaveRemoteImg"] == "1" && !string.IsNullOrEmpty(content)) + { + content = ThumbnailHelper.SaveRemoteImgForContent(content); + model.Content = content; + } //model.AuthorId = Core.Admin.GetMyInfo().Id; model.Save(); //添加TAG diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs index ba07c5e..8c5da32 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs @@ -11,6 +11,8 @@ using COMCMS.Web.Common; using COMCMS.Core.Models; using Microsoft.AspNetCore.Hosting; using System.IO; +using MimeKit; +using MailKit.Net.Smtp; namespace COMCMS.Web.Areas.AdminCP.Controllers { @@ -76,7 +78,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers public IActionResult SmtpConfig(SMTPConfigEntity model) { //验证 - if (!Utils.IsValidEmail(model.SmtpEmail)) + if (!Utils.IsValidEmail(model.PostUserName)) { tip.Message = "SMTP帐号格式错误!请输入正确的Email!"; return Json(tip); @@ -116,7 +118,49 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(tip); } + /// + /// 发送测试 + /// + /// + [HttpPost] + [MyAuthorize("edit", "smptconfig", "JSON")] + public IActionResult SendTestMail() + { + string mail = Request.Form["txtEmail"]; + Config cfg = Config.GetSystemConfig(); + if (string.IsNullOrWhiteSpace(mail) || !Utils.IsValidEmail(mail)) + { + tip.Message = "请输入正确的邮箱格式!"; + return Json(tip); + } + var smtp = cfg.SMTPConfigEntity; + if (string.IsNullOrEmpty(smtp.SmtpHost) || string.IsNullOrEmpty(smtp.SmtpEmail) || string.IsNullOrEmpty(smtp.SmtpEmailPwd)) + { + tip.Message = "系统SMTP配置错误,请先配置后再执行此操作!"; + return Json(tip); + } + + var emailMessage = new MimeMessage(); + emailMessage.From.Add(new MailboxAddress(smtp.PostUserName, smtp.SmtpEmail)); + emailMessage.To.Add(new MailboxAddress("", mail)); + emailMessage.Subject = "发送测试邮件"; + emailMessage.Body = new TextPart("html") { Text = $"

发送测试邮件,发送时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}

" }; + //同步发送 + using (var client = new SmtpClient()) + { + client.Connect(smtp.SmtpHost, int.Parse(smtp.SmtpProt), smtp.IsSSL == 1 ? true : false); + + client.Authenticate(smtp.SmtpEmail, smtp.SmtpEmailPwd); + + client.Send(emailMessage); + client.Disconnect(true); + } + tip.Status = JsonTip.SUCCESS; + tip.Message = "发送成功,请查收!"; + Admin.WriteLogActions($"发送测试Email(to:${mail});"); + return Json(tip); + } #endregion #region 附件配置 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs index 7ef89f9..3c75a9f 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs @@ -14,7 +14,10 @@ using System.IO; using COMCMS.Core.Models; using System.DrawingCore; using System.Text; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; +using Microsoft.Extensions.Primitives; +using NewLife.UserGroup.WebUploader; namespace COMCMS.Web.Areas.AdminCP.Controllers { @@ -46,13 +49,13 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers private readonly SystemSetting _attachsetting; private IHostingEnvironment _env; private AttachConfigEntity attach; - public UploadController( IHostingEnvironment env, IOptions attachsetting) + public UploadController(IHostingEnvironment env, IOptions attachsetting) { attach = Config.GetSystemConfig().AttachConfigEntity; _env = env; _attachsetting = attachsetting.Value; } - + #region CKEditor 上传图片 /// /// ckeditor 上传图片 @@ -67,7 +70,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers CKFileUploadError errorJson = new CKFileUploadError(); if (upload == null) { - + errorJson.error.message = "请选择一张图片!"; return Json(errorJson); } @@ -79,19 +82,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(errorJson); //return Content(string.Format(tpl, "", callback, "请上传一张图片!"), "text/html"); } + var data = Request.Form.Files["upload"]; - string filepath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\images\\"; - string thumbsFilePath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\_thumbs\\images\\"; + string filepath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; + string thumbsFilePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}_thumbs{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; //根据附件配置,设置上传图片目录 string imgPath = DateTime.Now.Year.ToString();//默认按年 switch (attach.SaveType) { case 1://按月份 - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}"; break; case 2: - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("dd")}"; break; } filepath += imgPath;//存放路径 @@ -145,7 +149,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //添加水印 if (attach.IsWaterMark == 1 && !string.IsNullOrEmpty(attach.WaterMarkImg)) { - string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", "\\"); + string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", Path.DirectorySeparatorChar.ToString()); if (System.IO.File.Exists(watermarkimg)) { //先复制一张图片出来 @@ -247,17 +251,17 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers isImage = true; } var data = Request.Form.Files["upload"]; - string filepath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\files\\"; - string thumbsFilePath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\_thumbs\\files\\"; + string filepath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}"; + string thumbsFilePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}_thumbs{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}"; //根据附件配置,设置上传图片目录 string imgPath = DateTime.Now.Year.ToString();//默认按年 switch (attach.SaveType) { case 1://按月份 - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}"; break; case 2: - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("dd")}"; break; } //文件名字 @@ -306,7 +310,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //添加水印 if (isImage && attach.IsWaterMark == 1 && !string.IsNullOrEmpty(attach.WaterMarkImg)) { - string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", "\\"); + string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", Path.DirectorySeparatorChar.ToString()); if (System.IO.File.Exists(watermarkimg)) { //先复制一张图片出来 @@ -427,17 +431,17 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers size = bytes.Length.ToString(); } - string filepath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\images\\"; - string thumbsFilePath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\_thumbs\\images\\"; + string filepath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; + string thumbsFilePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}_thumbs{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; //根据附件配置,设置上传图片目录 string imgPath = DateTime.Now.Year.ToString();//默认按年 switch (attach.SaveType) { case 1://按月份 - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}"; break; case 2: - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("dd")}"; break; } filepath += imgPath;//存放路径 @@ -481,7 +485,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //添加水印 if (attach.IsWaterMark == 1 && !string.IsNullOrEmpty(attach.WaterMarkImg)) { - string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", "\\"); + string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", Path.DirectorySeparatorChar.ToString()); if (System.IO.File.Exists(watermarkimg)) { //先复制一张图片出来 @@ -557,17 +561,17 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers msg = "只能上传一张图片格式文件!"; return Content(JsonConvert.SerializeObject(new { status = status, msg = msg, name = name, path = path, thumb = thumb, size = size, ext = ext }), "text/plain"); } - string filepath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\images\\"; - string thumbsFilePath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\_thumbs\\images\\"; + string filepath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; + string thumbsFilePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}_thumbs{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}"; //根据附件配置,设置上传图片目录 string imgPath = DateTime.Now.Year.ToString();//默认按年 switch (attach.SaveType) { case 1://按月份 - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}"; break; case 2: - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("dd")}"; break; } filepath += imgPath;//存放路径 @@ -623,7 +627,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //添加水印 if (notwater == "0" && attach.IsWaterMark == 1 && !string.IsNullOrEmpty(attach.WaterMarkImg)) { - string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", "\\"); + string watermarkimg = _env.WebRootPath + attach.WaterMarkImg.Replace("/", Path.DirectorySeparatorChar.ToString()); if (System.IO.File.Exists(watermarkimg)) { //先复制一张图片出来 @@ -699,17 +703,17 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers var data = Request.Form.Files[0]; if (data != null) { - string filepath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\files\\"; - string thumbsFilePath = $"{_env.WebRootPath}\\{attach.AttachPatch}\\_thumbs\\files\\"; + string filepath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}"; + string thumbsFilePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}_thumbs{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}"; //根据附件配置,设置上传图片目录 string imgPath = DateTime.Now.Year.ToString();//默认按年 switch (attach.SaveType) { case 1://按月份 - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}"; break; case 2: - imgPath = $"{DateTime.Now.Year.ToString()}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}"; + imgPath = $"{DateTime.Now.Year.ToString()}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("MM")}{Path.DirectorySeparatorChar}{DateTime.Now.ToString("dd")}"; break; } filepath += imgPath;//存放路径 @@ -793,6 +797,100 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Content(JsonConvert.SerializeObject(new { status = status, msg = msg, name = name, path = path, thumb = thumb, size = size, ext = ext }), "text/plain"); } + + #region 分片上传文件,可断点续传 + + /// + /// 保存文件或者分块 + /// + /// 文件md5 + /// 分块号 + /// 分块总数 + /// + [HttpPost] + public IActionResult SaveFile(string md5, int? chunk, int? chunks) + { + var tempDir = "UploadTemp"; // 缓存文件夹 + var targetDir = "UploadFile"; // 目标文件夹 + + var file = Request.Form.Files[0]; + + file.SaveFileOrChunkFile(targetDir, tempDir, md5, chunks, chunk); + + return Json(new + { + Data = new { md5 = md5, url = Path.Combine("/", targetDir, file.FileName) }, + Message = "ok", + Result = true + }); + } + + /// + /// 合并文件 + /// + /// 文件md5 + /// 文件名 + /// 分块数 + /// + [HttpPost] + public IActionResult MergeFile(string md5, string fileName, int chunks) + { + var tempDir = "UploadTemp"; + var targetDir = "UploadFile"; + + var (res,msg) = tempDir.Merge(targetDir, fileName, md5, chunks); + + if (!res) + { + return Json(new + { + Message = msg, + Result = false + }); + } + + return Json(new + { + Data = new { md5 = md5, url = Path.Combine("/", targetDir, fileName) }, + Message = "ok", + Result = true + }); + } + + /// + /// 检查文件或分块是否存在 + /// + /// 文件md5 + /// 文件名 + /// 分块号 + /// + public IActionResult CheckFile(string md5, string fileName, int? chunk) + { + var tempDir = "UploadTemp"; + var targetDir = "UploadFile"; + + string filePath; + + //分片文件 + if (chunk != null) + { + filePath = Path.Combine(tempDir, md5, $"{chunk}.part"); + } + else + { + filePath = Path.Combine(targetDir, fileName); + } + + var exists = System.IO.File.Exists(filePath); + + return Json(new + { + Data = fileName!=null && exists ? (object)new { md5 = md5, url = Path.Combine("/", targetDir, fileName) } : null, + Result = exists + }); + } + #endregion + #endregion #region 帮助方法 diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml index 5004d01..757bb41 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml @@ -122,6 +122,14 @@ +
+ +
+ +
+
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml index ceb95e2..9b67e96 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml @@ -35,15 +35,19 @@
- - @* - *@ + } + + @* + *@
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticle.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticle.cshtml index 1cc6cf0..61a7a4c 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticle.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticle.cshtml @@ -121,6 +121,15 @@ +
+ +
+ +
+
+
@if (!string.IsNullOrEmpty(Model.ItemImg)) { @@ -137,7 +146,7 @@
- +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Guestbook/GuestbookCategorys.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Guestbook/GuestbookCategorys.cshtml index 990cfd0..a0d7485 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Guestbook/GuestbookCategorys.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Guestbook/GuestbookCategorys.cshtml @@ -66,10 +66,10 @@ @@ -83,7 +83,7 @@ - + diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/AddAdmin.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/AddAdmin.cshtml index 75061b6..c617fc4 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/AddAdmin.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/AddAdmin.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "添加管理员"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/Admins.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/Admins.cshtml index 243fc8e..0b1b86c 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/Admins.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/Admins.cshtml @@ -32,7 +32,7 @@
-
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdmin.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdmin.cshtml index d9930df..b9994e6 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdmin.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdmin.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "查看/编辑管理员"; } -
+
@ViewBag.Title
@@ -10,7 +10,7 @@
- @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "eidtAdminForm", @class = "form-horizontal m-t" })) + @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editAdminForm", @class = "form-horizontal m-t" })) {
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdminRole.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdminRole.cshtml index 9b2f6bb..4b533d1 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdminRole.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/EditAdminRole.cshtml @@ -34,8 +34,8 @@
@@ -99,9 +99,9 @@ }
@@ -122,8 +122,26 @@
+@if (Model.IsSuperAdmin == 0) +{ + +} \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml index ce9d49b..a07407f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Member/ViewAdminLogDetail.cshtml @@ -53,7 +53,7 @@
- +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/AddAds.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/AddAds.cshtml index a6d361c..2a580e4 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/AddAds.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/AddAds.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "添加广告"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml index 027b8fd..4388d8f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/AddLink.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "添加友情链接"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/EditAds.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/EditAds.cshtml index 3604509..b06775c 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/EditAds.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/EditAds.cshtml @@ -6,7 +6,7 @@ Model.Content = "[]"; } } -
+
@ViewBag.Title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/EditLink.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/EditLink.cshtml index f45f23f..7ad3302 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/EditLink.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/EditLink.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.title = "编辑友情链接"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Other/LinkCategoryList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Other/LinkCategoryList.cshtml index 46d109d..0fd8423 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Other/LinkCategoryList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Other/LinkCategoryList.cshtml @@ -3,7 +3,7 @@ ViewBag.title = "友情链接分类管理"; } -
+
@ViewBag.title
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Permission/EventKey.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Permission/EventKey.cshtml index b6aedae..90e1b06 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Permission/EventKey.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Permission/EventKey.cshtml @@ -2,25 +2,6 @@
权限事件管理
-
- - - - - - - - - - -
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml index 54b5c6c..4172d20 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/AddProduct.cshtml @@ -18,7 +18,7 @@
@@ -36,11 +36,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -73,11 +73,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -85,11 +85,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -125,6 +125,14 @@
+
+ +
+ +
+
@if (!string.IsNullOrEmpty(Model.ItemImg)) { diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml index 544258f..7f6b063 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/EditProduct.cshtml @@ -36,11 +36,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -73,11 +73,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -85,11 +85,11 @@
@*
- -
- -
-
*@ + +
+ +
+
*@
@@ -125,6 +125,14 @@
+
+ +
+ +
+
@if (!string.IsNullOrEmpty(Model.ItemImg)) { diff --git a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml index c68815d..69f7b9c 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml @@ -14,6 +14,7 @@ + @@ -90,8 +91,6 @@ tips: [1, '#3595CC'] //还可配置颜色 }); }); - - } }) diff --git a/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml index b9953a0..6e63b45 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/System/SmtpConfig.cshtml @@ -17,7 +17,7 @@
- @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editBaseConfigForm", @class = "form-horizontal m-t" })) + @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "editSMTPConfigForm", @class = "form-horizontal m-t" })) {
@@ -44,11 +44,19 @@
- +
+
+ +
+ +
+
@@ -60,18 +68,20 @@
-
- -
- +
+
+ +
+ +
-
-
-
-
- +
+
+
+ +
-
+
@@ -83,7 +93,8 @@
diff --git a/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Cropper.cshtml b/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Cropper.cshtml new file mode 100644 index 0000000..d1dfcf1 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Cropper.cshtml @@ -0,0 +1,15 @@ + +@{ + Layout = null; +} + + + + + + + Cropper + + + + diff --git a/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Uploader.cshtml b/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Uploader.cshtml new file mode 100644 index 0000000..91e52d7 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/WebUploader/Uploader.cshtml @@ -0,0 +1,43 @@ + +@{ + Layout = null; +} + + + + + + WebUploader演示 + + + + +
+
+ + +
+
+
+
+

或将照片拖到这里,单次最多可选300张

+
+
+ +
+
+
+ + + + + + diff --git a/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml b/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml index 70b3c27..148344f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/_ViewImports.cshtml @@ -1,5 +1,6 @@ @using COMCMS.Web @using COMCMS.Core @using COMCMS.Common +@using COMCMS.Web.Common @using XCode @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 07129ae..18d8dc0 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -5,13 +5,17 @@ - - - - + + + + + + - - + + + + @@ -20,16 +24,21 @@ + + + + + @@ -42,6 +51,7 @@ + @@ -189,6 +199,7 @@ + @@ -274,7 +285,7 @@ Always - Always + Never diff --git a/COMCMS.Web/Common/AdminUtils.cs b/COMCMS.Web/Common/AdminUtils.cs new file mode 100644 index 0000000..5fc391b --- /dev/null +++ b/COMCMS.Web/Common/AdminUtils.cs @@ -0,0 +1,58 @@ +using COMCMS.Core; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using COMCMS.Common; +using XCode; +using NewLife.Log; + +namespace COMCMS.Web.Common +{ + public class AdminUtils + { + #region 检查管理员有没有管理权限 + /// + /// 检查管理员有没有管理权限 + /// + /// 动作,如add、edit + /// 菜单名称,如article、product + /// + public static bool CheckAdminPower(string eventKey, string menuKey) + { + if (!Admin.IsAdminLogin()) + { + return false; + } + + //判断权限 + Admin my = Admin.GetMyInfo(); + if (my.Roles.IsSuperAdmin != 1) + { + //获取所有的菜单权限 + if (string.IsNullOrEmpty(my.Roles.Powers)) + return false; + IList listevents = JsonConvert.DeserializeObject>(my.Roles.Powers); + if (listevents == null || listevents.Count <= 0) + { + return false; + } + if (!string.IsNullOrEmpty(menuKey) && !string.IsNullOrEmpty(eventKey)) + { + if (listevents.FirstOrDefault(s => s.EventKey == eventKey && s.MenuKey == menuKey) == null) + { + //获取用户信息 + Admin he = Admin.GetMyInfo(); + string path = MyHttpContext.Current.Request.Path; + XTrace.WriteLine($"管理员:{he.UserName}访问地址:{path}没有找到权限!EventKey:{eventKey};MenuKey:{menuKey}"); + return false; + } + } + } + return true; + } + #endregion + + } +} diff --git a/COMCMS.Web/Common/MyAuthorizeAttribute.cs b/COMCMS.Web/Common/MyAuthorizeAttribute.cs index 373e499..6198ed6 100644 --- a/COMCMS.Web/Common/MyAuthorizeAttribute.cs +++ b/COMCMS.Web/Common/MyAuthorizeAttribute.cs @@ -50,7 +50,7 @@ namespace COMCMS.Web.Common if (!string.IsNullOrEmpty(my.Roles.Powers)) { IList listevents = JsonConvert.DeserializeObject>(my.Roles.Powers); - if (listevents != null && listevents.Count <= 0) + if (listevents != null && listevents.Count > 0) { if (!string.IsNullOrEmpty(_menuKey) && !string.IsNullOrEmpty(_eventKey)) { diff --git a/COMCMS.Web/Controllers/HomeController.cs b/COMCMS.Web/Controllers/HomeController.cs index 4ad3e5b..a4d3dd1 100644 --- a/COMCMS.Web/Controllers/HomeController.cs +++ b/COMCMS.Web/Controllers/HomeController.cs @@ -22,12 +22,14 @@ namespace COMCMS.Web.Controllers { public static IConfiguration Configuration { get; set; } public ConcurrentDictionary AllSession = new ConcurrentDictionary(); - public HomeController() - { - Configuration = new ConfigurationBuilder() -.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) -.Build(); + public HomeController(IConfiguration configuration) + { + //Configuration = new ConfigurationBuilder() + // .SetBasePath(Directory.GetCurrentDirectory()) + // .AddJsonFile("appsettings.json", optional: true, reloadOnChange : true) + // .Build(); + Configuration = configuration; } public IActionResult Index() { @@ -58,6 +60,8 @@ namespace COMCMS.Web.Controllers public IActionResult Contact() { Link l = Link.Find(Link._.Id == 1); + l.Title = "😂😂😂😂"; + l.Save(); return View(l); } @@ -89,7 +93,7 @@ namespace COMCMS.Web.Controllers public IActionResult Test2() { - var settings = "appsettings.json".GetFullPath(); + var settings = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); var css2 = new ConfigurationBuilder().AddJsonFile(settings).Build().GetSection("connectionStrings"); string s = ""; @@ -127,6 +131,23 @@ namespace COMCMS.Web.Controllers } #endregion + #region 测试 + [HttpGet] + public IActionResult Article(string title) + { + return Content(title); + } + #endregion + public IActionResult Uploader() + { + return View("~/Areas/AdminCP/Views/WebUploader/Uploader.cshtml"); + } + + public IActionResult FileTest() + { + return View(); + + } } } diff --git a/COMCMS.Web/Controllers/api/IndexController.cs b/COMCMS.Web/Controllers/api/IndexController.cs index 56f975a..2b65044 100644 --- a/COMCMS.Web/Controllers/api/IndexController.cs +++ b/COMCMS.Web/Controllers/api/IndexController.cs @@ -7,12 +7,15 @@ using COMCMS.Common; using COMCMS.Core; using COMCMS.Web.Filter; using XCode; +using COMCMS.Web.Common; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace COMCMS.Web.Controllers.api { - + [Produces("application/json")] + [Route("api/[controller]/[action]")] + [WebAPIHandleError] public class IndexController : Controller { // GET: api/ @@ -23,7 +26,7 @@ namespace COMCMS.Web.Controllers.api return cfg; } - //#region 测试验签 + #region 测试验签 /// /// 测试验签 /// @@ -32,13 +35,13 @@ namespace COMCMS.Web.Controllers.api /// /// /// - //[HttpGet] - //[CheckFilter] - //public ReJSON CheckSign(string id, string random = "", string timeStamp = "", string signature = "") - //{ - // return new ReJSON("验签成功!"); - //} - //#endregion + [HttpGet] + [CheckFilter] + public ReJson CheckSign(string id, string random = "", string timeStamp = "", string signature = "") + { + return new ReJson("验签成功!"); + } + #endregion //#region 测试出错 //[HttpGet] diff --git a/COMCMS.Web/Controllers/api/PaymentController.cs b/COMCMS.Web/Controllers/api/PaymentController.cs index f649e3c..e0c2408 100644 --- a/COMCMS.Web/Controllers/api/PaymentController.cs +++ b/COMCMS.Web/Controllers/api/PaymentController.cs @@ -9,7 +9,7 @@ using COMCMS.Web.Filter; using XCode; using NewLife.Log; using Senparc.Weixin.MP; -using Senparc.Weixin.MP.TenPayLibV3; +using Senparc.Weixin.TenPay.V3; using Newtonsoft.Json; namespace COMCMS.Web.Controllers.api @@ -92,7 +92,7 @@ namespace COMCMS.Web.Controllers.api - TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify"); + TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify", Utils.GetServerUrl() + "/wxpayment/notify"); TenPayV3Info.TenPayV3Notify = Utils.GetServerUrl() + "/wxpayment/notify"; XTrace.WriteLine("微信支付异步通知地址:" + TenPayV3Info.TenPayV3Notify); //创建支付应答对象 @@ -102,7 +102,7 @@ namespace COMCMS.Web.Controllers.api string rtimeStamp = Utils.GetTimeStamp(); //创建请求统一订单接口参数 - var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, entity.Title, model.PayOrderNum, (int)(entity.TotalPay * 100), Utils.GetIP(), TenPayV3Info.TenPayV3Notify, TenPayV3Type.JSAPI, my.WeixinAppOpenId, TenPayV3Info.Key, nonceStr); + var xmlDataInfo = new TenPayV3UnifiedorderRequestData(TenPayV3Info.AppId, TenPayV3Info.MchId, entity.Title, model.PayOrderNum, (int)(entity.TotalPay * 100), Utils.GetIP(), TenPayV3Info.TenPayV3Notify, Senparc.Weixin.TenPay.TenPayV3Type.JSAPI, my.WeixinAppOpenId, TenPayV3Info.Key, nonceStr); //返回给微信的请求 RequestHandler res = new RequestHandler(null); diff --git a/COMCMS.Web/Controllers/api/UserController.cs b/COMCMS.Web/Controllers/api/UserController.cs index 4d5bce1..9f4482c 100644 --- a/COMCMS.Web/Controllers/api/UserController.cs +++ b/COMCMS.Web/Controllers/api/UserController.cs @@ -14,6 +14,7 @@ using NewLife.Log; using static COMCMS.Web.Models.APIModels; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Senparc.Weixin.WxOpen; namespace COMCMS.Web.Controllers.api { @@ -172,7 +173,7 @@ namespace COMCMS.Web.Controllers.api my.City = info.city; my.Province = info.province; my.Sex = info.gender; - my.Nickname = HttpUtility.UrlEncode(info.nickName); + my.Nickname = info.nickName; my.LastLoginTime = DateTime.Now; if (inviteid > 0 & my.Parent == 0) { @@ -190,11 +191,20 @@ namespace COMCMS.Web.Controllers.api } #endregion + #region 同步获取用户手机号码 + [HttpGet] + public object SyncUserTel(string encryptedData, string iv, string random = "", string timeStamp = "", string signature = "") + { + //Senparc.Weixin.WxOpen.Helpers.EncryptHelper.DecryptPhoneNumber() + return new ReJson(0, "同步电话号码成功!"); + } + #endregion + //#region 测试 //[HttpGet] //public object Test() //{ - + // reJson.code = 0; // reJson.message = "测试信息,成功!"; // return reJson; diff --git a/COMCMS.Web/Controllers/wxpaymentController.cs b/COMCMS.Web/Controllers/wxpaymentController.cs index 8d6f807..0abb1ad 100644 --- a/COMCMS.Web/Controllers/wxpaymentController.cs +++ b/COMCMS.Web/Controllers/wxpaymentController.cs @@ -10,8 +10,9 @@ using NewLife.Log; using Senparc.Weixin.Exceptions; using Senparc.Weixin; using Senparc.Weixin.MP; -using Senparc.Weixin.MP.TenPayLibV3; +using Senparc.Weixin.TenPay.V3; using System.Collections; +using Microsoft.Extensions.Configuration; using Newtonsoft.Json; namespace COMCMS.Web.Controllers @@ -28,9 +29,8 @@ namespace COMCMS.Web.Controllers XTrace.WriteLine("微信支付异步通知开始:"); try { - + ResponseHandler resHandler = new ResponseHandler(null); - string return_code = resHandler.GetParameter("return_code"); string return_msg = resHandler.GetParameter("return_msg"); @@ -41,8 +41,7 @@ namespace COMCMS.Web.Controllers string wxmchId = cfg.MCHId;// ConfigurationManager.AppSettings["WeixinMCHId"]; string wxmchKey = cfg.MCHKey;// ConfigurationManager.AppSettings["WeixinMCHKey"]; - TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify"); - + TenPayV3Info TenPayV3Info = new TenPayV3Info(appId, appSecrect, wxmchId, wxmchKey, Utils.GetServerUrl() + "/wxpayment/notify", Utils.GetServerUrl() + "/wxpayment/notify"); string res = null; resHandler.SetKey(TenPayV3Info.Key); @@ -126,5 +125,7 @@ namespace COMCMS.Web.Controllers } } #endregion + + public wxpaymentController(IConfiguration configuration) : base(configuration){} } } \ No newline at end of file diff --git a/COMCMS.Web/Filter/CheckFilter.cs b/COMCMS.Web/Filter/CheckFilter.cs index 064fbcf..70cd663 100644 --- a/COMCMS.Web/Filter/CheckFilter.cs +++ b/COMCMS.Web/Filter/CheckFilter.cs @@ -6,8 +6,11 @@ using COMCMS.Common; using COMCMS.Web.Common; using COMCMS.Web.Controllers.api; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; + + namespace COMCMS.Web.Filter { public class CheckFilterAttribute : ActionFilterAttribute @@ -35,9 +38,14 @@ namespace COMCMS.Web.Filter var notVali = ValiSignature(context.HttpContext); - if (notVali == null) + if (notVali != null) { - await context.HttpContext.Response.WriteAsync(notVali.ToJson()); + // 过滤器不要抛出错误,也不要向响应流写东西,应该直接赋值Result进行短路 + context.Result = new ContentResult() + { + Content = notVali.ToJson(), + ContentType = "application/json" + }; } } @@ -72,7 +80,7 @@ namespace COMCMS.Web.Filter } //没有签名返回错误 if (string.IsNullOrEmpty(signature)) - throw new Exception("signature Is Null"); + return new ReJson(40004, "signature 为空!"); if (!MySign.CheckSign(pars, signature)) { diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index 2c675e4..fb57925 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -17,6 +17,17 @@ using COMCMS.Web.Models; using COMCMS.Web.Common; using COMCMS.Web.ExceptionHandler; using Lib.Core.MiddlewareExtension.Extension; +using Senparc.Weixin.Entities; +using Senparc.CO2NET; +using Senparc.CO2NET.RegisterServices; +using Senparc.Weixin; +using Senparc.CO2NET.Cache; +using System.Configuration; +using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.Extensions.Options; +using Senparc.Weixin.RegisterServices; +using Microsoft.AspNetCore.Routing.Constraints; namespace COMCMS.Web { @@ -36,6 +47,9 @@ namespace COMCMS.Web services.AddSingleton(); //services.AddMvc().AddSessionStateTempDataProvider(); + //添加Configuration到静态变量 + Utils.AddUtils(Configuration); + services.Configure(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. @@ -67,10 +81,22 @@ namespace COMCMS.Web { options.Filters.Add(); }); + services.AddSenparcGlobalServices(Configuration)//Senparc.CO2NET 全局注册 + .AddSenparcWeixinServices(Configuration);//Senparc.Weixin 注册(如果使用Senparc.Weixin SDK则添加) + + //注册Cookie认证服务 + services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); + + // 设置表单内容限制 + services.Configure(formOptions => + { + formOptions.ValueLengthLimit = int.MaxValue; // 表单内容大小限制,默认4194304,单位byte + formOptions.MultipartBodyLengthLimit = int.MaxValue; // 如果是multipart,默认134217728 + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp, IOptions senparcSetting, IOptions senparcWeixinSetting) { app.Use(async (context, next) => { @@ -94,10 +120,11 @@ namespace COMCMS.Web app.UseStatusCodePagesWithReExecute("/StatusCode/{0}"); //启用Session app.UseSession(); - + app.UseMyMVCDI(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); + app.UseAuthentication(); app.UseStaticHttpContext(); app.UseMvc(routes => @@ -110,8 +137,16 @@ namespace COMCMS.Web routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); - - + routes.MapRoute( + name: "article", + template: "{title}/index.html", + defaults:new { controller ="Home", action= "Article" } + ); + routes.MapRoute( + name: "article2", + template: "{title}/", + defaults: new { controller = "Home", action = "Article" } + ); }); //使用环境变量 @@ -121,9 +156,40 @@ namespace COMCMS.Web }); app.UseMiddlewareExtension(new ResultExceptionHandler()); - + IRegisterService register = RegisterService.Start(env, senparcSetting.Value).UseSenparcGlobal(); //加入HttpContext //MyHttpContext.ServiceProvider = svp; } + + #region Senparc 缓存扩展策略 + /// + /// 获取Container扩展缓存策略 + /// + /// + private IList GetExContainerCacheStrategies() + { + var exContainerCacheStrategies = new List(); + + //如果有配置,可以去掉下面注释 + + ////判断Redis是否可用 + //var redisConfiguration = ConfigurationManager.AppSettings["Cache_Redis_Configuration"]; + //if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")) + //{ + // exContainerCacheStrategies.Add(RedisContainerCacheStrategy.Instance); + //} + + ////判断Memcached是否可用 + //var memcachedConfiguration = ConfigurationManager.AppSettings["Cache_Memcached_Configuration"]; + //if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置")) + //{ + // exContainerCacheStrategies.Add(MemcachedContainerCacheStrategy.Instance); + //} + + //也可扩展自定义的缓存策略 + + return exContainerCacheStrategies; + } + #endregion } } diff --git a/COMCMS.Web/Views/Home/FileTest.cshtml b/COMCMS.Web/Views/Home/FileTest.cshtml new file mode 100644 index 0000000..41f21df --- /dev/null +++ b/COMCMS.Web/Views/Home/FileTest.cshtml @@ -0,0 +1,15 @@ + + + + + title + + +
+
+ + +
+
+ + \ No newline at end of file diff --git a/COMCMS.Web/Views/Home/Index.cshtml b/COMCMS.Web/Views/Home/Index.cshtml index f804781..5fa8db5 100644 --- a/COMCMS.Web/Views/Home/Index.cshtml +++ b/COMCMS.Web/Views/Home/Index.cshtml @@ -1,4 +1,5 @@ @{ + Layout = null; ViewData["Title"] = "Home Page"; } diff --git a/COMCMS.Web/app.config b/COMCMS.Web/app.config index e7d399c..4327f0a 100644 --- a/COMCMS.Web/app.config +++ b/COMCMS.Web/app.config @@ -5,7 +5,7 @@ - + diff --git a/COMCMS.Web/appsettings.json b/COMCMS.Web/appsettings.json index 587197e..4a06da6 100644 --- a/COMCMS.Web/appsettings.json +++ b/COMCMS.Web/appsettings.json @@ -13,11 +13,11 @@ }, "connectionStrings": { "dbconn": { - "connectionString": "Server=.;Port=3306;Database=comcms2;Uid=root;Pwd=root;", + "connectionString": "Server=.;Port=3306;Database=comcms2;Uid=root;Pwd=123456;SslMode=None;charset=utf8mb4", "providerName": "MySql.Data.MySqlClient" }, "mssqlconnon": { - "connectionString": "server=(local);database=comcmscore;uid=sa;pwd=123456", + "connectionString": "server=.\\SQLEXPRESS;database=comcmscore;uid=sa;pwd=123456", "providerName": "System.Data.SqlClient" } } diff --git a/COMCMS.Web/libman.json b/COMCMS.Web/libman.json new file mode 100644 index 0000000..892f4c5 --- /dev/null +++ b/COMCMS.Web/libman.json @@ -0,0 +1,11 @@ +{ + "version": "1.0", + "defaultProvider": "unpkg", + "libraries": [ + { + "library": "webuploader@0.1.8", + "files": [ "dist/Uploader.swf", "dist/webuploader.css", "dist/webuploader.js", "dist/webuploader.min.js" ], + "destination": "wwwroot/lib/webuploader/" + } + ] +} \ No newline at end of file diff --git a/COMCMS.Web/wwwroot/editor/ckeditor/CHANGES.md b/COMCMS.Web/wwwroot/editor/ckeditor/CHANGES.md index 9a2d236..1205b92 100644 --- a/COMCMS.Web/wwwroot/editor/ckeditor/CHANGES.md +++ b/COMCMS.Web/wwwroot/editor/ckeditor/CHANGES.md @@ -1,11 +1,74 @@ CKEditor 4 Changelog ==================== +## CKEditor 4.10 + +New Features: + +* [#1751](https://github.com/ckeditor/ckeditor-dev/issues/1751): Introduced the **Autocomplete** feature that consists of the following plugins: + * [Autocomplete](https://ckeditor.com/cke4/addon/autocomplete) – Provides contextual completion feature for custom text matches based on user input. + * [Text Watcher](https://ckeditor.com/cke4/addon/textWatcher) – Checks whether an editor's text change matches the chosen criteria. + * [Text Match](https://ckeditor.com/cke4/addon/textMatch) – Allows to search [`CKEDITOR.dom.range`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_dom_range.html) for matching text. +* [#1703](https://github.com/ckeditor/ckeditor-dev/issues/1703): Introduced the [Mentions](https://ckeditor.com/cke4/addon/mentions) plugin providing smart completion feature for custom text matches based on user input starting with a chosen marker character. +* [#1746](https://github.com/ckeditor/ckeditor-dev/issues/1703): Introduced the [Emoji](https://ckeditor.com/cke4/addon/emoji) plugin providing completion feature for emoji ideograms. +* [#1761](https://github.com/ckeditor/ckeditor-dev/issues/1761): The [Auto Link](https://ckeditor.com/cke4/addon/autolink) plugin now supports email links. + +Fixed Issues: + +* [#1458](https://github.com/ckeditor/ckeditor-dev/issues/1458): [Edge] Fixed: After blurring the editor it takes 2 clicks to focus a widget. +* [#1034](https://github.com/ckeditor/ckeditor-dev/issues/1034): Fixed: JAWS leaves forms mode after pressing the Enter key in an inline editor instance. +* [#1748](https://github.com/ckeditor/ckeditor-dev/pull/1748): Fixed: Missing [`CKEDITOR.dialog.definition.onHide`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_dialog_definition.html#property-onHide) API documentation. Thanks to [sunnyone](https://github.com/sunnyone)! +* [#1321](https://github.com/ckeditor/ckeditor-dev/issues/1321): Ideographic space character (`\u3000`) is lost when pasting text. +* [#1776](https://github.com/ckeditor/ckeditor-dev/issues/1776): Empty caption placeholder of the [Image Base](https://ckeditor.com/cke4/addon/imagebase) plugin is not hidden when blurred. +* [#1592](https://github.com/ckeditor/ckeditor-dev/issues/1592): The [Image Base](https://ckeditor.com/cke4/addon/imagebase) plugin caption is not visible after paste. +* [#620](https://github.com/ckeditor/ckeditor-dev/issues/620): Fixed: The [`config.forcePasteAsPlainText`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-forcePasteAsPlainText) option is not respected in internal and cross-editor pasting. +* [#1467](https://github.com/ckeditor/ckeditor-dev/issues/1467): Fixed: The resizing cursor of the [Table Resize](https://ckeditor.com/cke4/addon/tableresize) plugin appearing in the middle of a merged cell. + +API Changes: + +* [#850](https://github.com/ckeditor/ckeditor-dev/issues/850): Backward incompatibility: Replaced the `replace` dialog from the [Find / Replace](https://ckeditor.com/cke4/addon/find) plugin with a `tabId` option in the `find` command. +* [#1582](https://github.com/ckeditor/ckeditor-dev/issues/1582): The [`CKEDITOR.editor.addCommand()`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_editor.html#method-addCommand) method can now accept a [`CKEDITOR.command`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_command.html) instance as a parameter. +* [#1712](https://github.com/ckeditor/ckeditor-dev/issues/1712): The [`extraPlugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-extraPlugins), [`removePlugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-removePlugins) and [`plugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-plugins) configuration options allow whitespace. +* [#1802](https://github.com/ckeditor/ckeditor-dev/issues/1802): The [`extraPlugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-extraPlugins), [`removePlugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-removePlugins) and [`plugins`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-plugins) configuration options allow passing plugin names as an array. +* [#1724](https://github.com/ckeditor/ckeditor-dev/issues/1724): Added an option to the [`getClientRect()`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_dom_element.html#method-getClientRect) function allowing to retrieve an absolute bounding rectangle of the element, i.e. a position relative to the upper-left corner of the topmost viewport. +* [#1498](https://github.com/ckeditor/ckeditor-dev/issues/1498) : Added a new [`getClientRects()`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_dom_range.html#method-getClientRects) method to `CKEDITOR.dom.range`. It returns a list of rectangles for each selected element. +* [#1993](https://github.com/ckeditor/ckeditor-dev/issues/1993): Added the [`CKEDITOR.tools.throttle()`](http://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR_tools.html#method-throttle) function. + +Other Changes: + +* Updated [SCAYT](https://ckeditor.com/cke4/addon/scayt) (Spell Check As You Type) and [WebSpellChecker](https://ckeditor.com/cke4/addon/wsc) (WSC) plugins: + * Language dictionary update: Added support for the Uzbek Latin language. + * Languages no longer supported as additional languages: Manx - Isle of Man (`gv_GB`) and Interlingua (`ia_XR`). + * Extended and improved language dictionaries: Georgian and Swedish. Also added the missing word _"Ensure"_ to the American, British and Canada English language. + * [#141](https://github.com/WebSpellChecker/ckeditor-plugin-scayt/issues/141) Fixed: SCAYT throws "Uncaught Error: Error in RangyWrappedRange module: createRange(): Parameter must be a Window object or DOM node". + * [#153](https://github.com/WebSpellChecker/ckeditor-plugin-scayt/issues/153) [Chrome] Fixed: Correcting a word in the widget in SCAYT moves focus to another editable. + * [#155](https://github.com/WebSpellChecker/ckeditor-plugin-scayt/issues/155) [IE8] Fixed: SCAYT throws an error and does not work. + * [#156](https://github.com/WebSpellChecker/ckeditor-plugin-scayt/issues/156) [IE10] Fixed: SCAYT does not seem to work. + * Fixed: After some text is dragged and dropped, the markup is not refreshed for grammar problems in SCAYT. + * Fixed: Request to FastCGI fails when the user tries to replace a word with non-English characters with a proper suggestion in WSC. + * [Firefox] Fixed: Ctrl+Z removes focus in SCAYT. + * Grammar support for default languages was improved. + * New application source URL was added in SCAYT. + * Removed green marks and legend related to grammar-supported languages in the Languages tab of SCAYT. Grammar is now supported for almost all the anguages in the list for an additional fee. + * Fixed: JavaScript error in the console: "Cannot read property 'split' of undefined" in SCAYT and WSC. + * [IE10] Fixed: Markup is not set for a specific case in SCAYT. + * Fixed: Accessibility issue: No `alt` attribute for the logo image in the About tab of SCAYT. + +## CKEditor 4.9.2 + +**Security Updates:** + +* Fixed XSS vulnerability in the [Enhanced Image](https://ckeditor.com/cke4/addon/image2) (`image2`) plugin reported by [Kyaw Min Thein](https://twitter.com/kyawminthein99). + + Issue summary: It was possible to execute XSS inside CKEditor using the `` tag and specially crafted HTML. Please note that the default presets (Basic/Standard/Full) do not include this plugin, so you are only at risk if you made a custom build and enabled this plugin. + +We would like to thank the [Drupal security team](https://www.drupal.org/drupal-security-team) for bringing this matter to our attention and coordinating the fix and release process! + ## CKEditor 4.9.1 Fixed Issues: -* [#1835](https://github.com/ckeditor/ckeditor-dev/issues/1835): Fixed: Integration between [CKFinder](https://ckeditor.com/ckeditor-4/ckfinder/) and [File Browser](https://ckeditor.com/cke4/addon/filebrowser) plugin does not work. +* [#1835](https://github.com/ckeditor/ckeditor-dev/issues/1835): Fixed: Integration between [CKFinder](https://ckeditor.com/ckeditor-4/ckfinder/) and the [File Browser](https://ckeditor.com/cke4/addon/filebrowser) plugin does not work. ## CKEditor 4.9 @@ -44,7 +107,7 @@ Fixed Issues: API Changes: -* [#1346](https://github.com/ckeditor/ckeditor-dev/issues/1346): [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) [context manager API](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.balloontoolbar.contextManager) is now available in the [`pluginDefinition.init`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.pluginDefinition-method-init) method of the [requiring](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.pluginDefinition-property-requires) plugin. +* [#1346](https://github.com/ckeditor/ckeditor-dev/issues/1346): [Balloon Toolbar](https://ckeditor.com/cke4/addon/balloontoolbar) [context manager API](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.balloontoolbar.contextManager) is now available in the [`pluginDefinition.init()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.pluginDefinition-method-init) method of the [requiring](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.pluginDefinition-property-requires) plugin. * [#1530](https://github.com/ckeditor/ckeditor-dev/issues/1530): Added the possibility to use custom icons for [buttons](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR_ui_button.html). Other Changes: @@ -75,9 +138,9 @@ New Features: * [#468](https://github.com/ckeditor/ckeditor-dev/issues/468): [Edge] Introduced support for the Clipboard API. * [#607](https://github.com/ckeditor/ckeditor-dev/issues/607): Manually inserted Hex color is prefixed with a hash character (`#`) if needed. It ensures a valid Hex color value is used when setting the table cell border or background color with the [Color Dialog](https://ckeditor.com/cke4/addon/colordialog) window. * [#584](https://github.com/ckeditor/ckeditor-dev/issues/584): [Font size and Family](https://ckeditor.com/cke4/addon/font) and [Format](https://ckeditor.com/cke4/addon/format) drop-downs are not toggleable anymore. Default option to reset styles added. -* [#856](https://github.com/ckeditor/ckeditor-dev/issues/856): Introduced the [`CKEDITOR.tools.keystrokeToArray`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools-method-keystrokeToArray) method. It converts a keystroke into its string representation, returning every key name as a separate array element. -* [#1053](https://github.com/ckeditor/ckeditor-dev/issues/1053): Introduced the [`CKEDITOR.tools.object.merge`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools.object-method-merge) method. It allows to merge two objects, returning the new object with all properties from both objects deeply cloned. -* [#1073](https://github.com/ckeditor/ckeditor-dev/issues/1073): Introduced the [`CKEDITOR.tools.array.every`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools.array-method-every) method. It invokes a given test function on every array element and returns `true` if all elements pass the test. +* [#856](https://github.com/ckeditor/ckeditor-dev/issues/856): Introduced the [`CKEDITOR.tools.keystrokeToArray()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools-method-keystrokeToArray) method. It converts a keystroke into its string representation, returning every key name as a separate array element. +* [#1053](https://github.com/ckeditor/ckeditor-dev/issues/1053): Introduced the [`CKEDITOR.tools.object.merge()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools.object-method-merge) method. It allows to merge two objects, returning the new object with all properties from both objects deeply cloned. +* [#1073](https://github.com/ckeditor/ckeditor-dev/issues/1073): Introduced the [`CKEDITOR.tools.array.every()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.tools.array-method-every) method. It invokes a given test function on every array element and returns `true` if all elements pass the test. Fixed Issues: @@ -89,7 +152,7 @@ Fixed Issues: * [#842](https://github.com/ckeditor/ckeditor-dev/issues/842): Fixed: List style not restored when toggling list indent level in the [Indent List](https://ckeditor.com/cke4/addon/indentlist) plugin. * [#711](https://github.com/ckeditor/ckeditor-dev/issues/711): Fixed: Dragging widgets should only work with the left mouse button. * [#862](https://github.com/ckeditor/ckeditor-dev/issues/862): Fixed: The "Object Styles" group in the [Styles Combo](https://ckeditor.com/cke4/addon/stylescombo) plugin is visible only if the whole element is selected. -* [#994](https://github.com/ckeditor/ckeditor-dev/pull/994): Fixed: Typo in the [`CKEDITOR.focusManager.focus`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.focusManager-method-focus) API documentation. Thanks to [benjy](https://github.com/benjy)! +* [#994](https://github.com/ckeditor/ckeditor-dev/pull/994): Fixed: Typo in the [`CKEDITOR.focusManager.focus()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.focusManager-method-focus) API documentation. Thanks to [benjy](https://github.com/benjy)! * [#1014](https://github.com/ckeditor/ckeditor-dev/issues/1014): Fixed: The [Table Tools](https://ckeditor.com/cke4/addon/tabletools) Cell Properties dialog is now [Advanced Content Filter](https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_acf) aware — it is not possible to change the cell width or height if corresponding styles are disabled. * [#877](https://github.com/ckeditor/ckeditor-dev/issues/877): Fixed: A list with custom bullets with exotic characters crashes the editor when [pasted from Word](https://ckeditor.com/cke4/addon/pastefromword). * [#605](https://github.com/ckeditor/ckeditor-dev/issues/605): Fixed: Inline widgets do not preserve trailing spaces. @@ -110,7 +173,7 @@ Fixed Issues: API Changes: * [#1097](https://github.com/ckeditor/ckeditor-dev/issues/1097): Widget [`upcast`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widget.definition-property-upcast) methods are now called in the [widget definition's](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.plugins.widget-property-definition) context. -* [#1118](https://github.com/ckeditor/ckeditor-dev/issues/1118): Added the `show` option in the [`balloonPanel.attach`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.ui.balloonPanel-method-attach) method, allowing to attach a hidden [Balloon Panel](https://ckeditor.com/cke4/addon/balloonpanel) instance. +* [#1118](https://github.com/ckeditor/ckeditor-dev/issues/1118): Added the `show` option in the [`balloonPanel.attach()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.ui.balloonPanel-method-attach) method, allowing to attach a hidden [Balloon Panel](https://ckeditor.com/cke4/addon/balloonpanel) instance. * [#1145](https://github.com/ckeditor/ckeditor-dev/issues/1145): Added the [`skipNotifications`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.fileTools.uploadWidgetDefinition-property-skipNotifications) option to the [`CKEDITOR.fileTools.uploadWidgetDefinition`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.fileTools.uploadWidgetDefinition), allowing to switch off default notifications displayed by upload widgets. Other Changes: @@ -139,7 +202,7 @@ Other Changes: * Updated the [WebSpellChecker](https://ckeditor.com/cke4/addon/wsc) plugin: * [#40](https://github.com/WebSpellChecker/ckeditor-plugin-wsc/issues/40): Fixed: IE10 throws an error when spell checking is started. -* [#800](https://github.com/ckeditor/ckeditor-dev/issues/800): Added the [`CKEDITOR.dom.selection.isCollapsed`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.selection-method-isCollapsed) method which is a simpler way to check if the selection is collapsed. +* [#800](https://github.com/ckeditor/ckeditor-dev/issues/800): Added the [`CKEDITOR.dom.selection.isCollapsed()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.selection-method-isCollapsed) method which is a simpler way to check if the selection is collapsed. * [#830](https://github.com/ckeditor/ckeditor-dev/issues/830): Added an option to define which dialog tab should be shown by default when creating [`CKEDITOR.dialogCommand`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dialogCommand). ## CKEditor 4.7.2 @@ -162,15 +225,15 @@ Fixed Issues: * [#501](https://github.com/ckeditor/ckeditor-dev/issues/501): Fixed: Double click does not open the dialog for modifying anchors inserted via the [Link](https://ckeditor.com/cke4/addon/link) plugin. * [#9780](https://dev.ckeditor.com/ticket/9780): [IE8-9] Fixed: Clicking inside an empty [read-only](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.editor-property-readOnly) editor throws an error. * [#16820](https://dev.ckeditor.com/ticket/16820): [IE10] Fixed: Clicking below a single horizontal rule throws an error. -* [#426](https://github.com/ckeditor/ckeditor-dev/issues/426): Fixed: The [`range.cloneContents`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-cloneContents) method selects the whole element when the selection starts at the beginning of that element. -* [#644](https://github.com/ckeditor/ckeditor-dev/issues/644): Fixed: The [`range.extractContents`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-extractContents) method returns an incorrect result when multiple nodes are selected. -* [#684](https://github.com/ckeditor/ckeditor-dev/issues/684): Fixed: The [`elementPath.contains`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.elementPath-method-contains) method incorrectly excludes the last element instead of root when the `fromTop` parameter is set to `true`. +* [#426](https://github.com/ckeditor/ckeditor-dev/issues/426): Fixed: The [`range.cloneContents()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-cloneContents) method selects the whole element when the selection starts at the beginning of that element. +* [#644](https://github.com/ckeditor/ckeditor-dev/issues/644): Fixed: The [`range.extractContents()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-extractContents) method returns an incorrect result when multiple nodes are selected. +* [#684](https://github.com/ckeditor/ckeditor-dev/issues/684): Fixed: The [`elementPath.contains()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.elementPath-method-contains) method incorrectly excludes the last element instead of root when the `fromTop` parameter is set to `true`. Other Changes: * Updated the [SCAYT](https://ckeditor.com/cke4/addon/scayt) (Spell Check As You Type) plugin: * [#148](https://github.com/WebSpellChecker/ckeditor-plugin-scayt/issues/148): Fixed: SCAYT leaves underlined word after the CKEditor Replace dialog corrects it. -* [#751](https://github.com/ckeditor/ckeditor-dev/issues/751): Added the [`CKEDITOR.dom.nodeList.toArray`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.nodeList-method-toArray) method which returns an array representation of a [node list](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.nodeList). +* [#751](https://github.com/ckeditor/ckeditor-dev/issues/751): Added the [`CKEDITOR.dom.nodeList.toArray()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.nodeList-method-toArray) method which returns an array representation of a [node list](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.nodeList). ## CKEditor 4.7.1 @@ -189,7 +252,7 @@ Fixed Issues: * [#424](https://github.com/ckeditor/ckeditor-dev/issues/424): Fixed: Error thrown by [Tab Key Handling](https://ckeditor.com/cke4/addon/tab) and [Indent List](https://ckeditor.com/cke4/addon/indentlist) plugins when pressing Tab with no selection in inline editor. * [#476](https://github.com/ckeditor/ckeditor-dev/issues/476): Fixed: Anchors inserted with the [Link](https://ckeditor.com/cke4/addon/link) plugin on collapsed selection cannot be edited. * [#417](https://github.com/ckeditor/ckeditor-dev/issues/417): Fixed: The [Table Resize](https://ckeditor.com/cke4/addon/tableresize) plugin throws an error when used with a table with only header or footer rows. -* [#523](https://github.com/ckeditor/ckeditor-dev/issues/523): Fixed: The [`editor.getCommandKeystroke`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.editor-method-getCommandKeystroke) method does not obtain the correct keystroke. +* [#523](https://github.com/ckeditor/ckeditor-dev/issues/523): Fixed: The [`editor.getCommandKeystroke()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.editor-method-getCommandKeystroke) method does not obtain the correct keystroke. * [#534](https://github.com/ckeditor/ckeditor-dev/issues/534): [IE] Fixed: [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) does not work in Quirks Mode. * [#450](https://github.com/ckeditor/ckeditor-dev/issues/450): Fixed: [`CKEDITOR.filter`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.filter) incorrectly transforms the `margin` CSS property. @@ -209,8 +272,8 @@ New Features: * [#16847](https://dev.ckeditor.com/ticket/16847): Added support for parsing and inlining any formatting created using the Microsoft Word style system to the [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) plugin. * [#16818](https://dev.ckeditor.com/ticket/16818): Added table cell height parsing in the [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) plugin. * [#16850](https://dev.ckeditor.com/ticket/16850): Added a new [`config.enableContextMenu`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config-cfg-enableContextMenu) configuration option for enabling and disabling the [context menu](https://ckeditor.com/cke4/addon/contextmenu). -* [#16937](https://dev.ckeditor.com/ticket/16937): The `command` parameter in [CKEDITOR.editor.getCommandKeystroke](http://docs.ckeditor.dev/#!/api/CKEDITOR.editor-method-getCommandKeystroke) now also accepts a command name as an argument. -* [#17010](https://dev.ckeditor.com/ticket/17010): The [`CKEDITOR.dom.range.shrink`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-shrink) method now allows for skipping bogus `
` elements. +* [#16937](https://dev.ckeditor.com/ticket/16937): The `command` parameter in [`CKEDITOR.editor.getCommandKeystroke()`](http://docs.ckeditor.dev/#!/api/CKEDITOR.editor-method-getCommandKeystroke) now also accepts a command name as an argument. +* [#17010](https://dev.ckeditor.com/ticket/17010): The [`CKEDITOR.dom.range.shrink()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.dom.range-method-shrink) method now allows for skipping bogus `
` elements. Fixed Issues: @@ -244,7 +307,7 @@ Fixed Issues: * [#14407](https://dev.ckeditor.com/ticket/14407): [IE] Fixed: Non-editable widgets can be edited. * [#16927](https://dev.ckeditor.com/ticket/16927): Fixed: An error thrown if a bundle containing the [Color Button](https://ckeditor.com/cke4/addon/colorbutton) plugin is run in ES5 strict mode. Thanks to [Igor Rubinovich](https://github.com/IgorRubinovich)! * [#16920](https://dev.ckeditor.com/ticket/16920): Fixed: Several plugins not using the [Dialog](https://ckeditor.com/cke4/addon/dialog) plugin as a direct dependency. -* [PR#336](https://github.com/ckeditor/ckeditor-dev/pull/336): Fixed: Typo in [`CKEDITOR.getCss`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR-method-getCss) API documentation. Thanks to [knusperpixel](https://github.com/knusperpixel)! +* [PR#336](https://github.com/ckeditor/ckeditor-dev/pull/336): Fixed: Typo in [`CKEDITOR.getCss()`](https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR-method-getCss) API documentation. Thanks to [knusperpixel](https://github.com/knusperpixel)! * [#17027](https://dev.ckeditor.com/ticket/17027): Fixed: Command event data should be initialized as an empty object. * Fixed the behavior of HTML parser when parsing `src`/`srcdoc` attributes of the `