Beispiel #1
0
        public JsonResult Login()
        {
            var dict = new Dictionary <string, object>();

            dict["limit"] = "10101010100111";
            dict["user"]  = new { Name = "张三", Age = 25 };
            string jwt = JwtUtil.Encode(dict, 10 * 60);

            JwtResult result = JwtUtil.Decode(jwt);
            dynamic   user   = (dynamic)result.Result["user"];
            string    name   = user.Name;

            return(Json(jwt));
        }
Beispiel #2
0
        public LoginResult CheckLogin(string webSiteID, string loginName, string password)
        {
            LoginResult loginResult = new LoginResult {
                Success = false
            };

            if (string.IsNullOrWhiteSpace(loginName))
            {
                loginResult.Msg = "登录名不能为空!";
                return(loginResult);
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                loginResult.Msg = "密码不能为空!";
                return(loginResult);
            }

            SysUser sysUser = sysUserDal.GetUser(loginName);

            if (sysUser == null)
            {
                loginResult.Msg = $"登录名{loginName}不存在!";
                return(loginResult);
            }

            if (sysUser.IsDeleted == 1)
            {
                loginResult.Msg = $"登录名{loginName}已被删除!";
                return(loginResult);
            }

            if (sysUser.IsLocked == 1)
            {
                loginResult.Msg = $"登录名{loginName}状态为锁定!";
                return(loginResult);
            }

            if (sysUser.Password != password)
            {
                loginResult.Msg = "密码错误!";
                return(loginResult);
            }

            //
            SysWebSiteDal sysWebSiteDal = lessContext.GetService <SysWebSiteDal>();
            SysWebSite    sysWebSite    = sysWebSiteDal.GetModel(new SysWebSite {
                ID = webSiteID
            });

            if (sysWebSite == null)
            {
                loginResult.Msg = $"站点{webSiteID}不存在!";
                return(loginResult);
            }

            if (sysWebSite.IsDeleted == 1)
            {
                loginResult.Msg = $"站点{webSiteID}已被删除!";
                return(loginResult);
            }

            var dict = new Dictionary <string, object>();

            dict[BasicConst.JWT_USER] = new { loginName = loginName };
            string jwt = JwtUtil.Encode(dict, 24 * 60 * 60);

            loginResult.Success    = true;
            loginResult.Msg        = "登录成功!";
            loginResult.token      = jwt;
            loginResult.sysWebSite = sysWebSite;

            //更新最近登录时间和登录次数
            sysUser.LoginCount   += 1;
            sysUser.LastLoginTime = DateTime.Now;
            sysUserDal.Update(sysUser, o => sysUser.ID);

            return(loginResult);
        }