Beispiel #1
0
}

// 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{
Beispiel #2
0
// Users is the postgres schema for users
var Users = postgres.Table("users",
	sol.Column("id", postgres.Serial()),
	sol.Column("email", types.Varchar().Limit(256).NotNull()),
	sol.Column("first_name", types.Varchar().Limit(64).NotNull()),
	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
}
Beispiel #3
0
}

// Exists returns true if the token exists
func (token Token) Exists() bool {
	return token.Key != ""
}

// Tokens is the postgres schema for user API tokens.
var Tokens = postgres.Table("tokens",
	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.Column(
		"created_at",
		postgres.Timestamp().WithTimezone().NotNull().Default(postgres.Now),
	),
	sol.PrimaryKey("key"),
)

// TokenManager is the internal manager of tokens
type TokenManager struct {
	conn    sol.Conn
	keyFunc KeyFunc
	nowFunc func() time.Time
}

// All returns all tokens for the given user ID