Example #1
0
// Checks to see if the user is logged in by looking at the sessionID stored on the request cookie
func isUserInSession(req *http.Request) (bool, *User) {
	sessionIdCookie, err := req.Cookie(SESSION_ID)
	var user User
	if err != nil {
		log.Println("Error reading SESSIONID:" + err.Error())
		return false, &user
	}
	// Retrieve the item from memcache
	memcache.Retrieve(sessionIdCookie.Value, req, &user)
	if user.Email != "" {
		return true, &user
	}
	return false, &user
}
Example #2
0
// Get's user's information from memcache, if it does not exists, it will look into datastore.
func GetUserWithEmail(email string, req *http.Request) datastore.User {
	// Getting the data from memcache
	var u datastore.User
	err := memcache.Retrieve(email, req, &u)
	if err != nil {
		log.Println("Cannot get the user from memcache", err)
		// Getting the user from datastore
		u, err = datastore.Retrieve(req, datastore.KIND_USER, email)
		if err == nil {
			// Trying to store the data into memcache
			err := memcache.Store(email, u, req)
			log.LogErrorWithMsg("Cannot store the data retreived from datastore into memcache", err)
		} else {
			log.LogErrorWithMsg("Cannot retreive the data from datastore", err)
		}
	}
	return u
}