public IActionResult List() { Guid blogId = CacheManager.Get <UserDTO>(CacheKey.GetUserKey("Admin"))?.BlogInfoDTO.Id ?? Guid.Empty; List <ClassInfoDTO> dtoList = _classAS.GetClassListByBlogId(blogId); return(View(dtoList)); }
/// <summary> /// 当作登录了 /// </summary> private void SetAdminUser() { //BlogUser blogUser = new BlogUser //{ // UserName = "******", // Id = Guid.Parse("00000001-0000-0000-0000-000000000000") //}; UserDTO blogUser = _blogUserAppService.GetUser("Admin"); CacheManager.AddOrSet(CacheKey.GetUserKey("Admin"), x => blogUser); }
public async Task <IActionResult> Create(ClassInfoDTO classInfo) { classInfo.BlogId = CacheManager.Get <UserDTO>(CacheKey.GetUserKey("Admin"))?.BlogInfoDTO.Id ?? Guid.Empty; if (ModelState.IsValid) { var ss = await _classAS.AddClassAsync(classInfo); return(RedirectToAction("Index")); } return(View(classInfo)); }
public IActionResult Index() { string userKey = CacheKey.GetUserKey("Admin"); UserDTO dto = CacheManager.Get <UserDTO>(userKey); if (dto == null) { return(RedirectToAction("Index", "Blog")); } else { ViewBag.User = dto; } return(View(dto)); }
public ActionResult SignOut() { CookieUtil.DeleteCookie(GlobalVar.CookieName); var repo = GetRepo <User>(); var account = repo.GetFiltered(f => f.Id == UserId, true).First(); account.ModifiedAt = DateTime.Now; repo.UnitOfWork.SaveChanges(); Resolve <ICache>().Remove(CacheKey.GetUserKey(UserId)); if (IsGetRequest) { return(RedirectToAction("SignIn")); } var result = new BaseOutput(); SetResponse(s => s.Success, null, result); return(JsonNet(result)); }
public ActionResult SignIn(InputSignIn input) { if (IsGetRequest) { return(View()); } var result = new BaseOutput(); if (string.IsNullOrEmpty(input.UserName)) { SetResponse(s => s.NameEmpty, input, result); } else if (string.IsNullOrEmpty(input.Pwd)) { SetResponse(s => s.PwdEmpty, input, result); } else { var repo = GetRepo <User>(); var level = 0; var account = repo.GetFiltered(f => f.UserName == input.UserName, true).FirstOrDefault(); if (account != null) { if (account.Status == Status.Enabled) { var encryptedPwd = SHAEncrypt.SHA1(input.Pwd); if (account.Pwd != encryptedPwd) { SetResponse(s => s.NamePwdNotMatch, input, result); } else { account.ModifiedAt = DateTime.Now; result.data = new { token = RandomGenerator.Next(20), url = UrlVar.Home_Index }; var expireAt = DateTime.Now.AddMinutes(AppConfig.GetValue <double>(GlobalVar.CacheMinute)); var userInfo = new UserInfo { UserId = account.Id, UserName = input.UserName, Roles = account.Roles.Split(',').Select(s => int.Parse(s)).ToArray(), Token = result.data.token, ExpiredAt = expireAt.ToString("yyyy-MM-dd HH:mm:ss"), LoginIP = HttpUtil.RequestHostAddress }; userInfo.Level = RoleService.GetMaxLevel(userInfo.Roles); userInfo.Auths = CommonService.GetAuths(userInfo.Roles); userInfo.Urls = CommonService.GetUrls(userInfo.Roles); Resolve <ICache>().Set(CacheKey.GetUserKey(userInfo.UserId), userInfo, expireAt); CookieUtil.WriteCookie(GlobalVar.CookieName, GlobalVar.UserId, userInfo.UserId.ToString()); CookieUtil.WriteCookie(GlobalVar.CookieName, GlobalVar.UserName, userInfo.UserName); CookieUtil.WriteCookie(GlobalVar.CookieName, GlobalVar.Level, userInfo.Level.ToString()); CookieUtil.WriteCookie(GlobalVar.CookieName, GlobalVar.AuthToken, userInfo.Token); level = userInfo.Level; SetResponse(s => s.Success, input, result); } } else { SetResponse(s => s.UserForbidden, input, result); } } else { SetResponse(s => s.NameNotExist, input, result); } LogService.AddLoginLog(new LoginLog { UserName = input.UserName, LoginIP = HttpUtil.RequestHostAddress, Status = result.msg, Level = level }); } return(JsonNet(result)); }