func generateGhostToken(session *cookies.Session) (string, error) { jsonToken, err := util.SerializeJSON(session) if err != nil { return err.Error(), err } encryptedToken, err := security.Encrypt(jsonToken) if err != nil { return err.Error(), err } ghostToken := util.Encode(encryptedToken) return string(ghostToken), nil }
// WriteCookie writes a cookie in the cookie store. If that cookie already exists, // it is overwritten func (store *FileCookieStore) WriteCookie(cookie *Session) error { fileName := fileLocation(store.location, cookie.Token) jsonData, err := util.SerializeJSON(cookie) if err != nil { return err } encryptedData, err := security.Encrypt(jsonData) if err != nil { return err } err = addUserToken(store.location, cookie.UserID, cookie.Token) if err != nil { return err } return ioutil.WriteFile(fileName, encryptedData, os.ModeDevice) }