aboutsummaryrefslogblamecommitdiff
path: root/http_auth.go
blob: b88fb459b5acd4f7c5d9eab8714f13a974be9136 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


                                                       











                                                                                       
                                                                                                                                                                                                           


              
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>

package main

import (
	"net/http"
)

func get_user_info_from_request(r *http.Request) (id int, username string, err error) {
	session_cookie, err := r.Cookie("session")
	if err != nil {
		return
	}

	err = database.QueryRow(r.Context(), "SELECT user_id, COALESCE(username, '') FROM users u JOIN sessions s ON u.id = s.user_id WHERE s.session_id = $1;", session_cookie.Value).Scan(&id, &username)

	return
}