예제 #1
0
        /// <summary>
        /// 设置登录时设置的票据并返回
        /// </summary>
        /// <param name="uid">用户标识</param>
        /// <param name="roles">用户拥有的角色</param>
        /// <param name="days">有效时间</param>
        /// <param name="userData">用户附加数据(不需要可以设置成null)</param>
        /// <returns>认证票据</returns>
        public Dictionary <string, string> SignIn(string uid, int days, string[] roles, object userData)
        {
            //在这里, 将用户标识(Uid), 用户角色(Roles)和盐值拼接成字符串
            //解密的时候也要按照这个格式来拆分获取
            var expire    = DateTime.Now.AddDays(days);
            var plainText = AuthTicket <object> .Create(uid, roles, userData, expire).ToJson();

            var cipherBytes = SecurityUtils.AesEncrypt(plainText, AesKey);
            var cipherText  = Convert.ToBase64String(cipherBytes);

            var cookieValue = AuthUtils.CreateCookieValue(this.CookieName, cipherText, expire, "/");

            var headers = new Dictionary <string, string>
            {
                { "Set-Cookie", cookieValue }
            };

            return(headers);
        }