示例#1
0
        public async Task <JsonResult> Get(string id)
        {
            return(await Task.Run <JsonResult>(() =>
            {
                PageResponse json = new Tibos.Common.PageResponse();
                //获取dhm库的数据
                var list_manager = _ManagerService.GetList();
                //获取tibos库数据
                var list_dict = _DictService.GetList();

                var list_dy = _DictTypeService.GetList();

                Dict dict = new Dict()
                {
                    Id = "testtest",
                    Description = "test",
                    Name = "test",
                    Sort = 99,
                    Status = 0,
                    Tid = "test"
                };

                //var res =_DictService.Add(dict, false);
                //_DictService.SaveChanges(id=="1");

                //测试自定义业务
                //var test = _DictService.GetTest();
                //json.data = list_dict;
                return Json(json);
            }));
        }
示例#2
0
        public JsonResult Login(string user_name, string password, string code, string returnUrl)
        {
            PageResponse json     = new Tibos.Common.PageResponse();
            string       pic_code = HttpContext.Session.GetString("pic_code");

            using (var md5 = MD5.Create())
            {
                var res = md5.ComputeHash(Encoding.UTF8.GetBytes(code.ToLower()));
                code = BitConverter.ToString(res);
            }

            if (string.IsNullOrEmpty(pic_code))
            {
                json.status = -1;
                json.msg    = "请获取验证码";
                return(Json(json));
            }
            if (pic_code != code)
            {
                json.status = -1;
                json.msg    = "验证码不正确";
                return(Json(json));
            }
            var model = _ManagerService.Get(m => m.UserName == user_name && m.Password == password && m.Status == 1);

            if (model != null)
            {
                //只使用授权,认证功能使用自定义认证
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim(ClaimTypes.Name, model.Id));
                HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
                //缓存用户(滑动过期15分钟)
                _MemoryCache.GetOrCreate(model.Id, entry =>
                {
                    entry.SetSlidingExpiration(TimeSpan.FromSeconds(15 * 60)); //15分钟
                    return(model);
                });
                if (!String.IsNullOrEmpty(returnUrl))
                {
                    json.returnUrl = returnUrl;
                }
                else
                {
                    json.returnUrl = "/home/index";
                }
            }
            else
            {
                json.status = -1;
                json.msg    = "帐户或者密码不正确";
            }
            return(Json(json));
        }
示例#3
0
        /// <summary>
        /// 验证Token
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public PageResponse CheckToken(string token)
        {
            PageResponse json = new PageResponse();

            if (string.IsNullOrEmpty(token))
            {
                json.msg    = "token不能为空!";
                json.status = -1;
                json.code   = StatusCodeDefine.Unauthorized;
                return(json);
            }
            var id = _Cache.Get(token);

            if (id == null)
            {
                json.msg    = "token已失效!";
                json.status = -1;
                json.code   = StatusCodeDefine.Unauthorized;
                return(json);
            }
            return(json);
        }