sol.Column("last_name", types.Varchar().Limit(64).NotNull()), sol.Column("about", types.Varchar().Limit(512).NotNull()), sol.Column("photo", types.Varchar().Limit(512).NotNull()), sol.Column("is_active", types.Boolean().NotNull().Default(true)), sol.Column("is_superuser", types.Boolean().NotNull().Default(false)), sol.Column("password", types.Varchar().Limit(256).NotNull()), sol.Column("token", types.Varchar().Limit(256).NotNull()), sol.Column( "token_set_at", postgres.Timestamp().WithTimezone().NotNull().Default(postgres.Now), ), sol.Column( "created_at", postgres.Timestamp().WithTimezone().NotNull().Default(postgres.Now), ), sol.PrimaryKey("id"), sol.Unique("email"), ) // UserManager is the internal manager of users type UserManager struct { conn sol.Conn hash Hasher tokenFunc KeyFunc } // Create will create a new user with given email and cleartext password. // It will panic on any crypto or database connection errors. func (m *UserManager) Create(email, first, last, clear string) (User, error) { return m.create(email, first, last, clear, false) }
// Exists returns true if the session exists func (session Session) Exists() bool { return session.Key != "" } // Sessions is the postgres schema for sessions var Sessions = postgres.Table("sessions", sol.Column("key", types.Varchar().NotNull()), sol.ForeignKey( "user_id", Users.C("id"), types.Integer().NotNull(), ).OnDelete(sol.Cascade).OnUpdate(sol.Cascade), sol.Column("expires", postgres.Timestamp().WithTimezone()), sol.PrimaryKey("key"), ) // SessionManager is the internal manager of sessions type SessionManager struct { conn sol.Conn cookie config.Cookie keyFunc KeyFunc nowFunc func() time.Time } // Create creates a new session using a key generated for the given User func (m *SessionManager) Create(user User) (session Session) { // Set the expires from the cookie config session = Session{ Expires: m.nowFunc().Add(m.cookie.Age),