forked from jarias/stormpath-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
39 lines (32 loc) · 1.01 KB
/
web.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
package stormpathweb
import (
"github.com/gorilla/context"
"github.com/jarias/stormpath-sdk-go"
"net/http"
)
//ApplicationKey is the key of the current application in the context
const ApplicationKey = "application"
//AccountKey is the key of the current account in the context and session
const AccountKey = "account"
//GetApplication returns the application from the context previouly set by the ApplicationMiddleware
func GetApplication(r *http.Request) *stormpath.Application {
app := context.Get(r, ApplicationKey)
if app == nil {
return nil
}
application := app.(stormpath.Application)
return &application
}
//GetCurrentAccount retrives the current account if any from the request context
func GetCurrentAccount(r *http.Request) *stormpath.Account {
acc := context.Get(r, AccountKey)
if acc == nil {
return nil
}
account := acc.(stormpath.Account)
return &account
}
//IsAuthenticated checks if there is an authenticated user
func IsAuthenticated(r *http.Request) bool {
return GetCurrentAccount(r) != nil
}