Example #1
0
    public override string GetVaryByCustomString(HttpContext context, string arg)
    {
        if (arg == "Ticket")
        {
            HttpCookie sDBlogAuthCookie = context.Request.Cookies[SessionManager.sDBlogAuthCookieName];
            HttpCookie sDBlogPostCookie = context.Request.Cookies[SessionManager.sDBlogPostCookieName];
            int        authLoginId      = sDBlogAuthCookie != null?ManagedLogin.GetLoginId(sDBlogAuthCookie.Value) : 0;

            int postLoginId = sDBlogPostCookie != null?ManagedLogin.GetLoginId(sDBlogPostCookie.Value) : 0;

            return(string.Format("{0}:{1}", authLoginId, postLoginId));
        }

        return(base.GetVaryByCustomString(context, arg));
    }
Example #2
0
    /// <summary>
    /// Create an administrator.
    /// </summary>
    private void CreateAdministrator()
    {
        ISession     session = DBlog.Data.Hibernate.Session.Current;
        ITransaction t       = session.BeginTransaction();

        try
        {
            int adminCount = session.CreateCriteria(typeof(Login))
                             .Add(Expression.Eq("Role", TransitLoginRole.Administrator.ToString()))
                             .SetProjection(Projections.Count("Id"))
                             .UniqueResult <int>();

            if (adminCount == 0)
            {
                Login admin = new Login();
                admin.Name     = admin.Username = "******";
                admin.Role     = TransitLoginRole.Administrator.ToString();
                admin.Password = ManagedLogin.GetPasswordHash(string.Empty);
                session.Save(admin);
                session.Flush();

                if (EventLogEnabled)
                {
                    EventLog.WriteEntry(string.Format(
                                            "Created an Administrator user with id={0}.",
                                            admin.Id),
                                        EventLogEntryType.Information);
                }
            }

            t.Commit();
        }
        catch
        {
            t.Rollback();
            throw;
        }

        session.Flush();
    }
Example #3
0
    private void CacheTicket(string name, ref string ticket)
    {
        HttpCookie authcookie = Request.Cookies[name];

        if (authcookie != null)
        {
            try
            {
                // cache a verified ticket for an hour
                string key = string.Format("ticket:{0}", authcookie.Value);
                ticket = (string)Cache[key];
                if (string.IsNullOrEmpty(ticket))
                {
                    ManagedLogin.GetLoginId(authcookie.Value);
                    ticket = authcookie.Value;
                    Cache.Insert(key, ticket, null,
                                 DateTime.Now.AddHours(1), TimeSpan.Zero);
                }
            }
            catch
            {
            }
        }
    }