public void SignIn(UserAccount user, bool createPersistentCookie)
        {
            var accountEntry = new AccountCollectionEntry();

            accountEntry.AddAccount(user, createPersistentCookie);
            var authTicket = new FormsAuthenticationTicket(1,
                                                           user.Id,
                                                           DateTime.Now,
                                                           DateTime.Now.AddYears(5),
                                                           createPersistentCookie,
                                                           AccountCollectionEntry.Serialize(accountEntry));

            UpdateContextResponse(authTicket, accountEntry);
        }
        public void DeleteUserFromContext(string id)
        {
            HttpCookie currentUserCookie     = _context.Request.Cookies["webrunes"];
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(currentUserCookie.Value);
            var collectionentry = AccountCollectionEntry.Deserialize(ticket.UserData);

            collectionentry.DeleteBy(id);
            collectionentry.CurrentAccountId = null;

            var authTicket = new FormsAuthenticationTicket(1,
                                                           "",
                                                           DateTime.Now,
                                                           DateTime.Now.AddDays(-1),
                                                           false,
                                                           AccountCollectionEntry.Serialize(collectionentry));

            UpdateContextResponse(authTicket, collectionentry);
        }
        public bool SignOut(IUserService userService)
        {
            if (!_context.User.Identity.IsAuthenticated)
            {
                return(false);
            }
            HttpCookie currentUserCookie = _context.Request.Cookies["webrunes"];

            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(currentUserCookie.Value);
            var collectionentry = AccountCollectionEntry.Deserialize(ticket.UserData);

            collectionentry.CurrentAccountId = null;

            var authTicket = new FormsAuthenticationTicket(1,
                                                           "",
                                                           DateTime.Now,
                                                           DateTime.Now.AddDays(-1),
                                                           false,
                                                           AccountCollectionEntry.Serialize(collectionentry));

            UpdateContextResponse(authTicket, collectionentry);
            return(true);
        }