Exemple #1
0
// CreationSessions creates in-base a session for the
// given user already created in database.
func CreateSession(conn db.Conn, user db.User, creationTime time.Time) (db.Session, error) {
	if len(user.Uuid) == 0 {
		return db.Session{}, fmt.Errorf("nil user given to CreateSession")
	}

	session := db.Session{
		Token:   uuid.New(),
		User:    user,
		HitTime: creationTime,
	}

	err := conn.InsertSession(session)
	return session, err
}
Exemple #2
0
func GetUser(conn db.Conn, r *http.Request) db.User {
	if r == nil {
		return db.User{}
	}

	cookie, err := r.Cookie("t")
	if err != nil {
		return db.User{}
	}

	sessionToken := cookie.Value

	user, err := conn.GetUserFromSessionToken(sessionToken)
	if err != nil {
		log.Printf("err: while getting an user from the session ID '%s': %s", sessionToken, err.Error())
		return db.User{}
	}

	conn.UpdateSession(sessionToken)

	return user
}