Skip to content

Commit

Permalink
got rid of init(); moved global vars in cookie_handling.go and user_m…
Browse files Browse the repository at this point in the history
…anagement.go
  • Loading branch information
sauerbraten committed May 24, 2013
1 parent 038a181 commit b3a04ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 4 additions & 0 deletions example/cookie_handling.go
@@ -1,10 +1,14 @@
package main

import (
"github.com/gorilla/securecookie"
"net/http"
"time"
)

// initialize secure cookie storage; 16 byte ~ 128 bit AES encryption
var secCookie *securecookie.SecureCookie = securecookie.New([]byte("my very secret hash key"), []byte{0x5d, 0xa5, 0xd3, 0x90, 0xc9, 0x54, 0xa1, 0xc3, 0x70, 0x00, 0x8d, 0x6d, 0xa9, 0xd1, 0x07, 0x53})

// looks for a session cookie and returns the user's email address, or "" if something failed.
// this example has no error handling!
func getUserEmail(req *http.Request) (email string) {
Expand Down
15 changes: 0 additions & 15 deletions example/server.go
Expand Up @@ -2,26 +2,11 @@ package main

import (
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"log"
"net/http"
"text/template"
)

var (
// knownUsers should be a database table or something when using persona in production
knownUsers map[string]bool

secCookie *securecookie.SecureCookie
)

func init() {
knownUsers = map[string]bool{}

// initialize secure cookie storage; 16 byte ~ 128 bit AES encryption
secCookie = securecookie.New([]byte("my very secret hash key"), []byte{0x5d, 0xa5, 0xd3, 0x90, 0xc9, 0x54, 0xa1, 0xc3, 0x70, 0x00, 0x8d, 0x6d, 0xa9, 0xd1, 0x07, 0x53})
}

func landingPage(resp http.ResponseWriter, req *http.Request) {
log.Println("/ req. by " + req.RemoteAddr)
template.Must(template.ParseFiles("html/landing.html")).Execute(resp, getUserEmail(req))
Expand Down
3 changes: 3 additions & 0 deletions example/user_management.go
Expand Up @@ -7,6 +7,9 @@ import (
"net/http"
)

// knownUsers should be a database table or something when using persona in production
var knownUsers map[string]bool = make(map[string]bool)

// signs the client in by checking with the persona verification API and setting a secure session cookie.
// passes the persona verifiation API response down to the client so the javascript can act on it.
func signIn(resp http.ResponseWriter, req *http.Request) {
Expand Down

0 comments on commit b3a04ca

Please sign in to comment.