/// <summary> /// 用户登录 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <returns></returns> public OperateResult <AuthorizationUser> Login(string account, string password) { var accountDetail = _sysAccountRepository.AccountDetail(a => a.UserName == account); OperateResult <AuthorizationUser> result = new OperateResult <AuthorizationUser>(); if (accountDetail == null) { result.Message = "用户名或密码错误"; return(result); } if (accountDetail.Password != EncryptUtil.MD5Encrypt32(accountDetail.AccountId + password)) { result.Message = "用户名或密码错误"; } else if (!accountDetail.EnabledMark) { result.Message = "登录账户已被禁用"; } else { result.Status = ResultStatus.Success; var user = accountDetail.MapTo <AuthorizationUser, AccountDetailsDto>(); user.LoginId = SnowflakeUtil.NextStringId(); user.HeadIcon = user.HeadIcon ?? "/images/default.png"; result.Data = user; } return(result); }
/// <summary> /// 新增修改栏目 /// </summary> /// <param name="category"></param> /// <returns></returns> public OperateResult Save(CategoryInfo category) { int count = QueryableCount(c => c.CategoryName == category.CategoryName && c.CategoryId != category.CategoryId); if (count > 0) { return(new OperateResult("文章栏目已存在")); } else { if (string.IsNullOrWhiteSpace(category.CategoryId)) { category.CategoryId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(category)); } else { if (category.CategoryId == category.ParentId) { return(new OperateResult("上级栏目不能与当前栏目相同")); } if (category.ParentId != "0") { var list = Queryable(m => m.DeleteMark == false && m.EnabledMark == true); if (GetChildCategory(list, category.CategoryId).Where(o => o.CategoryId == category.ParentId).Any()) { OperateResult result = new OperateResult(); result.Message = "无法将一级菜单指定到子级栏目下"; return(result); } } return(UpdateRemoveCache(category, i => new { i.CreatorTime, i.DeleteMark })); } } }
/// <summary> /// 获取授权登录地址 /// </summary> /// <param name="cururl">授权成功后返回的地址</param> /// <returns></returns> public static string AuthorizeLoginUrl(string url) { string state = SnowflakeUtil.NextStringId(); HttpContextHelper.Current.Session.SetString("lib" + state, url); return($"https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id={AppId}&redirect_uri={CallbackUrl}&state={state}"); }
public void AddSession(LazynetChannelHandlerContext channelHandlerContext) { var session = new LazynetSession() { Context = channelHandlerContext, ID = SnowflakeUtil.Instance().GetString() }; this.SessionGroup.Add(session); }
/// <summary> /// 添加/修改banner图 /// </summary> /// <param name="banner">轮播图信息</param> /// <returns></returns> public OperateResult Save(BannerInfo banner) { if (string.IsNullOrWhiteSpace(banner.BannerId)) { banner.BannerId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(banner)); } else { return(UpdateRemoveCache(banner, i => new { i.CreatorTime, i.DeleteMark })); } }
/// <summary> /// 添加/编辑通知 /// </summary> /// <param name="noticeinfo">通知信息</param> /// <returns></returns> public OperateResult Save(Noticeinfo noticeinfo) { if (string.IsNullOrWhiteSpace(noticeinfo.NoticeId)) { noticeinfo.NoticeId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(noticeinfo)); } else { return(UpdateRemoveCache(noticeinfo, f => new { f.DeleteMark, f.CreatorTime })); } }
/// <summary> /// 新增/编辑友情链接 /// </summary> /// <param name="link">友情链接信息</param> /// <returns></returns> public OperateResult Save(FriendLink link) { if (string.IsNullOrWhiteSpace(link.FriendLinkId)) { link.FriendLinkId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(link)); } else { return(UpdateRemoveCache(link, f => new { f.DeleteMark, f.CreatorTime })); } }
/// <summary> /// 添加/编辑时间轴 /// </summary> /// <param name="timeLine"></param> /// <returns></returns> public OperateResult Save(TimeLine timeLine) { if (string.IsNullOrWhiteSpace(timeLine.TimeLineId)) { timeLine.TimeLineId = SnowflakeUtil.NextStringId(); return(Insert(timeLine)); } else { return(Update(timeLine, f => new { f.DeleteMark, f.CreatorTime })); } }
/// <summary> /// 分配权限 /// </summary> /// <param name="roleId">角色id</param> /// <param name="permission">分配权限菜单按钮id集合</param> /// <param name="createUserId">创建人userid</param> /// <returns></returns> public async Task <OperateResult> Save(string roleId, List <string> permission, string createUserId) { OperateResult result = new OperateResult(); if (!permission.Any()) { result.Message = "分配的权限不能为空"; return(result); } int count = await _sysRoleService.QueryableCountAsync(c => c.RoleId == roleId); if (string.IsNullOrWhiteSpace(roleId) || count == 0) { result.Message = "所分配角色不存在"; return(result); } var menus = await _sysModuleService.QueryableAsync(m => permission.Contains(m.ModuleId)); var buttons = await _sysButtonService.QueryableAsync(b => permission.Contains(b.ButtonId)); if (!menus.Any() && !buttons.Any()) { result.Message = "分配的权限不能为空"; return(result); } //删除现有权限重新分配权限 await DeleteRemoveCacheAsync(c => c.AuthorizeId == roleId); List <SysPermission> list = new List <SysPermission>(); if (menus.Any()) { list = (from m in menus select new SysPermission() { PermissionId = SnowflakeUtil.NextStringId(), AuthorizeId = roleId, ModuleType = 1, ObjectType = 1, SysModuleId = m.ModuleId }).ToList(); } if (buttons.Any()) { var bs = (from b in buttons select new SysPermission() { PermissionId = SnowflakeUtil.NextStringId(), AuthorizeId = roleId, ModuleType = 2, ObjectType = 1, SysModuleId = b.ButtonId }).ToList(); list.AddRange(bs); } //删除缓存 Redis.DelPattern(roleId); return(await InsertRemoveCacheAsync(list)); }
/// <summary> /// 新增标签 /// </summary> /// <param name="tags">标签信息</param> /// <returns></returns> public OperateResult Save(TagsInfo tags) { if (QueryableCount(c => c.TagName == tags.TagName && c.TagId != tags.TagId && tags.DeleteMark == false) > 0) { return(new OperateResult("标签已存在,请勿重复添加")); } if (string.IsNullOrWhiteSpace(tags.TagId)) { tags.TagId = SnowflakeUtil.NextStringId(); return(Insert(tags)); } else { return(Update(tags, i => new { i.CreatorTime, i.EnabledMark })); } }
/// <summary> /// 新增/修改角色 /// </summary> /// <param name="sysRole">角色实体</param> /// <returns></returns> public OperateResult Save(SysRole sysRole) { if (QueryableCount(c => c.EnCode == sysRole.EnCode && c.RoleId != sysRole.RoleId && sysRole.DeleteMark == false) > 0) { OperateResult result = new OperateResult(); result.Message = "角色编码已存在"; return(result); } if (string.IsNullOrWhiteSpace(sysRole.RoleId)) { sysRole.RoleId = SnowflakeUtil.NextStringId(); return(Insert(sysRole)); } else { return(Update(sysRole, i => new { i.CreatorTime, i.CreatorAccountId, i.DeleteMark })); } }
/// <summary> /// 新增/修改按钮 /// </summary> /// <param name="sysButton">按钮实体</param> /// <returns></returns> public OperateResult Save(SysButton sysButton) { if (_sysButtonRepository.QueryableCount(c => c.EnCode == sysButton.EnCode && c.ButtonId != sysButton.ButtonId && c.SysModuleId == sysButton.SysModuleId) > 0) { OperateResult result = new OperateResult(); result.Message = "按钮编码已存在"; return(result); } if (string.IsNullOrEmpty(sysButton.ButtonId)) { sysButton.ButtonId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(sysButton)); } else { return(UpdateRemoveCache(sysButton, i => new { i.SysModuleId, i.CreatorTime, i.CreatorAccountId })); } }
/// <summary> /// 新增/编辑系统用户 /// </summary> /// <param name="dto"></param> /// <param name="createUserId"></param> /// <returns></returns> public OperateResult Save(AccountDetailsDto dto, string createUserId) { var account = dto.MapTo <SysAccount, AccountDetailsDto>(); var user = dto.MapTo <SysUser, AccountDetailsDto>(); if (_sysAccountRepository.QueryableCount(a => a.UserName == account.UserName && a.AccountId != dto.AccountId) > 0) { return(new OperateResult() { Message = "用户名已存在" }); } //添加 if (string.IsNullOrWhiteSpace(dto.AccountId)) { account.AccountId = SnowflakeUtil.NextStringId(); account.CreatorAccountId = createUserId; user.AccountId = account.AccountId; user.UserId = SnowflakeUtil.NextStringId(); account.Password = EncryptUtil.MD5Encrypt32(account.AccountId + account.Password); var result = Insert(account); if (result.Status == ResultStatus.Success) { result = _sysUserService.Insert(user); } return(result); } else { //编辑 var result = Update(a => new SysAccount() { UserName = account.UserName, RoleId = account.RoleId }, c => c.AccountId == dto.AccountId); if (result.Status == ResultStatus.Success) { result = _sysUserService.Update(user, c => c.AccountId == dto.AccountId, ig => new { ig.UserId, ig.AccountId }); } return(result); } }
/// <summary> /// 新增/修改菜单 /// </summary> /// <param name="module"></param> /// <returns></returns> public OperateResult Save(SysModule module) { if (QueryableCount(m => m.EnCode.ToLower() == module.EnCode.ToLower() && m.ModuleId != module.ModuleId) > 0) { OperateResult result = new OperateResult(); result.Message = "菜单编码已存在"; return(result); } else { module.ParentId = string.IsNullOrWhiteSpace(module.ParentId) ? null : module.ParentId; if (string.IsNullOrWhiteSpace(module.ModuleId)) { module.ModuleId = SnowflakeUtil.NextStringId(); return(InsertRemoveCache(module)); } else { if (module.ModuleId == module.ParentId) { OperateResult result = new OperateResult(); result.Message = "父级菜单不能指向当前菜单"; return(result); } if (module.ParentId != "0") { var list = QueryableCache(m => m.DeleteMark == false && m.EnabledMark == true); if (GetChildMenu(list, module.ModuleId).Where(o => o.ModuleId == module.ParentId).Any()) { OperateResult result = new OperateResult(); result.Message = "无法将父级菜单指定到子级菜单下"; return(result); } } return(UpdateRemoveCache(module, c => new { c.CreatorTime, c.CreatorAccountId, c.DeleteMark })); } } }
/// <summary> /// 登录 /// </summary> /// <param name="code">回调返回的code</param> /// <param name="state">自定义验证状态码</param> /// <returns></returns> public QQUserinfo Login(string code, string state) { //token需要缓存起来,有效期30天 var token = QQAuthorize.GetAccessToken(code, state); string openid = QQAuthorize.GetOpenId(token.access_token); QQUserinfo userinfo = _qQUserinfoRepository.FindEntity(c => c.OpenId == openid); if (userinfo == null) { var user = QQAuthorize.GetUserInfo(token.access_token, openid); userinfo = new QQUserinfo() { UserId = SnowflakeUtil.NextStringId(), NikeName = user.nickname, Gender = user.gender, Birthday = user.year, OpenId = openid, Province = user.province, Image40 = user.figureurl_qq_1, Image100 = user.figureurl_qq_2, LastLoginTime = DateTime.Now, AccessToken = token.access_token, RefreshToken = token.refresh_token, ExpireDate = DateTime.Now.AddSeconds(token.expires_in) }; _qQUserinfoRepository.Insert(userinfo); } else { userinfo.LastLoginTime = DateTime.Now; userinfo.AccessToken = token.access_token; userinfo.RefreshToken = token.refresh_token; userinfo.ExpireDate = DateTime.Now.AddSeconds(token.expires_in); _qQUserinfoRepository.Update(userinfo, i => new { i.CreatorTime, i.IsMaster, i.OpenId }); } return(userinfo); }
/// <summary> /// 留言评论 /// </summary> /// <param name="content">留言内容</param> /// <param name="userid">评论人id</param> /// <param name="articleId">文章id</param> /// <returns></returns> public OperateResult Comment(string content, string userid, string articleId) { OperateResult result = new OperateResult(); if (string.IsNullOrWhiteSpace(content)) { result.Message = "请输入留言内容"; return(result); } if (content.Length > 500) { result.Message = "回复内容超出长度"; } else { if (!string.IsNullOrWhiteSpace(articleId)) { if (_articleInfoService.QueryableCount(c => c.ArticleId == articleId) == 0) { result.Message = "评论的文章不存在"; return(result); } } LeavemsgInfo leavemsg = new LeavemsgInfo(); leavemsg.FromUId = userid; leavemsg.Content = content; leavemsg.IP = HttpHelper.GetClientIp(); leavemsg.Adscription = HttpHelper.GetAddressByApi(); leavemsg.MsgId = SnowflakeUtil.NextStringId(); leavemsg.ParentId = leavemsg.MsgId; leavemsg.ArticleId = articleId; Insert(leavemsg); result.Status = ResultStatus.Success; } return(result); }
/// <summary> /// 添加/编辑文章 /// </summary> /// <param name="article">文章信息</param> /// <returns></returns> public OperateResult Save(ArticleInfo article) { bool b = string.IsNullOrWhiteSpace(article.ArticleId); if (b) { article.ArticleId = SnowflakeUtil.NextStringId(); } if (!article.Categories.Any()) { return(new OperateResult("请选择文章分类")); } if (!article.Tags.Any()) { return(new OperateResult("请选择文章标签")); } List <ArticleCategory> categories = new List <ArticleCategory>(); List <ArticleTags> tags = new List <ArticleTags>(); article.Categories.ForEach(c => { categories.Add(new ArticleCategory() { ACId = SnowflakeUtil.NextStringId(), ArticleId = article.ArticleId, CategoryId = c }); }); article.Tags.ForEach(t => { tags.Add(new ArticleTags() { ArticleTagsId = SnowflakeUtil.NextStringId(), ArticleId = article.ArticleId, TagsId = t }); }); _articleInfoRepository.Save(article, categories, tags, b); return(new OperateResult("保存成功", ResultStatus.Success)); }
/// <summary> /// 回复留言/评论 /// </summary> /// <param name="rootid">评论ID</param> /// <param name="pid">上级评论id</param> /// <param name="fromid">回复人id</param> /// <param name="content">回复内容</param> /// <param name="userid">评论回复人id</param> /// <param name="articleId">文章id</param> /// <returns></returns> public OperateResult Reply(string rootid, string pid, string fromid, string content, string userid, string articleId) { OperateResult result = new OperateResult(); if (string.IsNullOrWhiteSpace(content)) { result.Message = "请输入留言内容"; return(result); } if (content.Length > 500) { result.Message = "回复内容超出长度"; return(result); } if (fromid == userid) { result.Message = "不能回复自己的留言"; return(result); } if (string.IsNullOrWhiteSpace(rootid) || string.IsNullOrWhiteSpace(fromid)) { result.Message = "缺少参数"; } else { if (string.IsNullOrWhiteSpace(pid) || rootid == pid) { if (_leavemsgRepository.QueryableCount(c => c.MsgId == rootid) == 0) { result.Message = "请选择回复内容"; return(result); } } else { if (_leavemsgRepository.QueryableCount(c => c.MsgId == rootid || c.MsgId == pid) != 2) { result.Message = "请选择回复内容"; return(result); } } if (!string.IsNullOrWhiteSpace(articleId)) { if (_articleInfoService.QueryableCount(c => c.ArticleId == articleId) == 0) { result.Message = "评论的文章不存在"; return(result); } } LeavemsgInfo leavemsg = new LeavemsgInfo(); leavemsg.FromUId = userid; leavemsg.ToUId = fromid; leavemsg.RootId = rootid; leavemsg.ParentId = pid ?? rootid; leavemsg.Content = content; leavemsg.IP = HttpHelper.GetClientIp(); leavemsg.Adscription = HttpHelper.GetAddressByApi(); leavemsg.MsgId = SnowflakeUtil.NextStringId(); leavemsg.ArticleId = articleId; Insert(leavemsg); result.Status = ResultStatus.Success; } return(result); }
public IActionResult upload([FromServices] IHostingEnvironment env) { try { //最大文件大小 int maxSize = 2048; //文件保存目录路径 string savePath = "/Uploads/attached/"; //文件保存目录URL string saveUrl = "/Uploads/attached/"; //定义允许上传的文件扩展名 Hashtable extTable = new Hashtable(); extTable.Add("image", "gif,jpg,jpeg,png,bmp"); extTable.Add("flash", "swf,flv"); extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2"); var imgFile = Request.Form.Files["imgFile"]; if (imgFile == null) { return(Json(new { error = 1, message = "请选择文件" })); } string dirPath = env.WebRootPath + savePath; if (!Directory.Exists(dirPath)) { return(Json(new { error = 1, message = "上传目录不存在" })); } string dirName = HttpContext.Request.Query["dir"].FirstOrDefault(); if (string.IsNullOrEmpty(dirName)) { dirName = "image"; } if (!extTable.ContainsKey(dirName)) { return(Json(new { error = 1, message = "目录名不正确" })); } string fileName = imgFile.FileName; string fileExt = Path.GetExtension(fileName).ToLower(); if (imgFile.Length / 1024 > maxSize) { return(Json(new { error = 1, message = "上传文件大小超过限制" })); } if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(((string)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1) { return(Json(new { error = 1, message = "上传文件扩展名是不允许的扩展名。\n只允许" + ((string)extTable[dirName]) + "格式" })); } //创建文件夹 dirPath += dirName + "/"; saveUrl += dirName + "/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string ymd = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo); dirPath += ymd + "/"; saveUrl += ymd + "/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string newFileName = SnowflakeUtil.NextStringId() + fileExt; string filePath = dirPath + newFileName; using (FileStream fs = System.IO.File.Create(filePath)) { imgFile.CopyTo(fs); fs.Flush(); } string fileUrl = saveUrl + newFileName; return(Json(new { error = 0, url = fileUrl })); } catch (Exception ex) { return(Json(new { error = 1, message = ex.Message })); } }