Beispiel #1
0
        public IActionResult Index()
        {
            //TempData["returnUrl"] = returnUrl;
            _userServices.Login(UserDtoCache.UserId, GetIp());
            _logServices.Insert(new Sys_log
            {
                LogId       = PubId.SnowflakeId,
                Browser     = GetBrowser(),
                CreateBy    = UserDtoCache.UserId,
                Description = $"{UserDtoCache.UserNickname}登录成功",
                LogIp       = GetIp(),
                Url         = GetUrl(),
                LogType     = LogType.login.EnumToString(),
            });
            ViewBag.title    = GetDescriptor("title");
            ViewBag.company  = GetDescriptor("company");
            ViewBag.customer = GetDescriptor("customer");
            ViewBag.nickname = UserDtoCache.UserNickname;
            ViewBag.headimg  = UserDtoCache.HeadImg;

            //菜单
            var menus = _roleServices.GetMenu(UserDtoCache.RoleId.Value);

            GetMemoryCache.Set("menu", menus);
            ViewData["menu"] = menus;
            return(View());
        }
Beispiel #2
0
        public IActionResult CheckLoginAsync([FromBody] SysUserDto sys)
        {
            ClearCache("user");
            ClearCache("menu");
            var item = _userServices.CheckLogin(sys);

            if (item.Item1)
            {
                HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, item.Item3.UserName),
                    new Claim(ClaimTypes.Sid, item.Item3.UserId.ToString()),
                    new Claim(ClaimTypes.Surname, item.Item3.UserNickname),
                    new Claim(ClaimTypes.Role, item.Item3.RoleId?.ToString()),
                    new Claim(ClaimTypes.Uri, string.IsNullOrWhiteSpace(item.Item3.HeadImg)?Path.Combine("upload", "head", "4523c812eb2047c39ad91f8c5de3fb31.jpg"):item.Item3.HeadImg)
                };
                var claimsIdentitys = new ClaimsIdentity(
                    claims,
                    CookieAuthenticationDefaults.AuthenticationScheme);
                var claimsPrincipal = new ClaimsPrincipal(claimsIdentitys);
                HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties
                {
                    IsPersistent = true,
                    ExpiresUtc   = DateTimeOffset.Now.AddDays(1),
                });
            }
            else
            {
                _logServices.Insert(new Sys_log
                {
                    LogId       = PubId.SnowflakeId,
                    Browser     = GetBrowser(),
                    Description = $"{_xss.Filter(sys.UserNickname)}登录失败",
                    LogIp       = GetIp(),
                    Url         = GetUrl(),
                    LogType     = LogType.login.EnumToString()
                });
            }
            item.Item3 = null;
            return(Json(item));
        }