blob: 9761d802da878fa1c5f370054275a33057e0f948 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package auth
import (
"go-gentoo/pkg/config"
"go-gentoo/pkg/models"
"net/http"
)
func IsValidUser(w http.ResponseWriter, r *http.Request) bool {
session, err := CookieStore.Get(r, config.SessionStoreKey())
if err != nil {
return false
}
if token, ok := session.Values["idToken"].(string); ok {
_, err = Verifier.Verify(Ctx, token)
return err == nil
}
return false
}
func GetUser(w http.ResponseWriter, r *http.Request) *models.User {
session, err := CookieStore.Get(r, config.SessionStoreKey())
if err != nil {
return nil
}
user := session.Values["user"].(*models.User)
err = user.ComputeProjects()
if err != nil {
return nil
}
return user
}
|