/
user.go
61 lines (48 loc) · 1.39 KB
/
user.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
oauth2 "github.com/goincremental/negroni-oauth2"
"github.com/goincremental/negroni-sessions"
"net/http"
"time"
)
type UserConfig struct {
// Hashed email address
UserId []byte
EmailAddress string
CreatedOn time.Time
// Filter strings are passed to Google to define what messages should
// come back as tasks. This parameter stores the last user-provided
// FilterString that returned a successful response code from Google.
FilterString string
// User-provided function input that last executed successfully. Note
// that this is user-provided and should never be passed to any other
// users under any circumstances.
RankingFunc string
}
func GetUserFromSession(r *http.Request) (UserConfig, error) {
session := sessions.GetSession(r)
user := session.Get("config").(UserConfig)
return user, nil
}
func StoreUserInSession(r *http.Request, uc UserConfig) error {
session := sessions.GetSession(r)
session.Set("config", uc)
return nil
}
// TODO: implement
func GetUserFromStorage(email string) (UserConfig, error) {
return UserConfig{}, nil
}
// TODO: implement
func StoreUserInStorage(uc UserConfig) error {
return nil
}
func RemoveUserFromSession(r *http.Request) error {
session := sessions.GetSession(r)
session.Delete("config")
return nil
}
func UserLoggedIn(r *http.Request) bool {
token := oauth2.GetToken(r)
return token != nil && token.Valid()
}