示例#1
0
        /// <summary>
        /// 更新当前Token
        /// </summary>
        /// <param name="filterContext"></param>
        /// <param name="dal"></param>
        /// <param name="authorityModel"></param>
        public void UpdateToken(AuthorizationContext filterContext, IDal dal, CSign authorityModel)
        {
            var token = Guid.NewGuid().ToString();

            filterContext.HttpContext.Response.Cookies["Token"].Values["User"]  = authorityModel.UserCode;
            filterContext.HttpContext.Response.Cookies["Token"].Values["Value"] = token;
            filterContext.HttpContext.Response.Cookies["Token"].Expires         = DateTime.Now.AddDays(30);
            SignBll.UpdateToken(dal, token, authorityModel.UserCode);
        }
示例#2
0
        public CSign Post(CSign value)
        {
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                bool ok;
                try
                {
                    dal.Open();
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", value.UserCode, value.UserName),
                        LogContent = string.Format("{0}#{1}", "Signin", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                var tokenCookie = HttpContext.Current.Request.Cookies["Token"];
                if (value.Remain && tokenCookie != null && string.IsNullOrEmpty(value.UserCode) && string.IsNullOrEmpty(value.UPwd))
                {
                    //Token不为空 用户名和密码为空,则使用token登录
                    ok = SignBll.Signin(dal, tokenCookie.Values["User"], tokenCookie.Values["Value"], value);
                }
                else
                {
                    //使用用户名密码登录
                    ok = SignBll.Signin(dal, value);
                }
                if (!ok)
                {
                    throw new HttpResponseException(new DataNotFoundMessage());
                }
                HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]] = value;
                //生成Token
                var token = Guid.NewGuid().ToString();
                SignBll.UpdateToken(dal, token, value.UserCode);
                HttpContext.Current.Response.Cookies["Token"].Values["User"]  = value.UserCode;
                HttpContext.Current.Response.Cookies["Token"].Values["Value"] = token;

                HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(30);
                if (value.Remain)
                {
                    return(value);
                }
                HttpContext.Current.Response.Cookies["Token"].Expires = DateTime.Now.AddDays(-1);
                SignBll.DropToken(dal, value.UserCode);
                dal.Close();
                return(value);
            }
        }
示例#3
0
        // GET api/menuapi
        public IEnumerable <CMenuCategory> Get()
        {
            using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
            {
                var user =
                    (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];
                try
                {
                    dal.Open();
                    if (user == null)
                    {
                        var httpCookie = HttpContext.Current.Request.Cookies["Token"];
                        if (httpCookie != null)
                        {
                            //存在Token,进行Token登录

                            if (SignBll.Signin(dal, httpCookie.Values["User"], httpCookie.Values["Value"],
                                               user))
                            {
                                HttpContext.Current.Session.Add(ConfigurationManager.AppSettings["AuthSaveKey"],
                                                                user);
                                //更新Token
                                var token = Guid.NewGuid().ToString();
                                HttpContext.Current.Response.Cookies["Token"].Values["User"]  = user.UserCode;
                                HttpContext.Current.Response.Cookies["Token"].Values["Value"] = token;
                                HttpContext.Current.Response.Cookies["Token"].Expires         = DateTime.Now.AddDays(30);
                                SignBll.UpdateToken(dal, token, user.UserCode);
                            }
                            else
                            {
                                throw new HttpResponseException(new SiginFailureMessage());
                            }
                        }
                        else
                        {
                            throw new HttpResponseException(new SiginFailureMessage());
                        }
                    }
                    var menus = FunctionBll.LoadMenu(dal, user.GroupCode);
                    if (menus == null)
                    {
                        throw new HttpResponseException(new DataNotFoundMessage());
                    }
                    return(menus);
                }
                catch (Exception ex)
                {
                    LogBll.Write(dal, new CLog
                    {
                        LogUser    = string.Format("{0}-{1}", user == null?string.Empty:user.UserCode, user == null?string.Empty:user.UserName),
                        LogContent = string.Format("{0}#{1}", "Menu.List", ex.Message),
                        LogType    = LogType.系统异常
                    });
                    throw new HttpResponseException(new SystemExceptionMessage());
                }
                finally
                {
                    dal.Close();
                }
            }
        }