private static void AddRolesToUser(QNZ.Data.User user, List <QNZ.Data.Role> roles)
 {
     user.Roles.Clear();
     foreach (QNZ.Data.Role r in roles)
     {
         user.Roles.Add(r);
     }
 }
        public static void SetUserCookies(bool isPersist, QNZ.Data.User user)
        {
            var roles = user.Roles.Select(m => m.RoleName).ToArray();

            CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel()
            {
                UserId   = user.Id,
                RealName = user.RealName,
                Avatar   = string.IsNullOrEmpty(user.PhotoUrl) ? SettingsManager.User.DefaultAvatar : user.PhotoUrl,
                Roles    = roles
            };
            //serializeModel.Menus = GetUserMenus(user.);
            TimeSpan timeout = FormsAuthentication.Timeout;
            DateTime expire  = DateTime.Now.Add(timeout);


            string userData = JsonConvert.SerializeObject(serializeModel, Formatting.Indented,
                                                          new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });


            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                1,
                user.UserName,
                DateTime.Now,
                expire,
                isPersist,
                userData);

            string     encTicket = FormsAuthentication.Encrypt(authTicket);
            HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

            System.Web.HttpContext.Current.Response.Cookies.Add(faCookie);
        }