app

package
v0.0.0-...-fa33ba7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2015 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PTPersonal
	PTGoods
	PTServices
)

Payment types.

View Source
const (
	SCOPE     = "https://www.googleapis.com/auth/userinfo.profile https://www.google.com/m8/feeds"
	AUTH_URL  = "https://accounts.google.com/o/oauth2/auth"
	TOKEN_URL = "https://accounts.google.com/o/oauth2/token"

	GOOGLE_API_REQUEST = "https://www.google.com/m8/feeds/contacts/default/full?max-results=10000&alt=json"
)

Variables

This section is empty.

Functions

func AppHostname

func AppHostname(c *Context) string

func AppHostnameForPayPal

func AppHostnameForPayPal(c *Context) string

func Assert

func Assert(condition bool, v ...interface{})

func CheckError

func CheckError(err error)

func ConsumeFlash

func ConsumeFlash(w http.ResponseWriter, r *http.Request) (string, error)

Returns http.ErrNoCookie if there is no flash message.

func ContainsString

func ContainsString(slice []string, str string) bool

func DeleteCookie

func DeleteCookie(name string, w http.ResponseWriter) error

func DeleteSession

func DeleteSession(w http.ResponseWriter, c *Context) error

Deletes session cookie (if any) and updates context.

func ExecuteTemplate

func ExecuteTemplate(name string, data interface{}) (template.HTML, error)

If the returned error is not nil, it is guaranteed to have type template.Error.

func ExecuteTextTemplate

func ExecuteTextTemplate(name string, data interface{}) (string, error)

func GenerateSecureRandomString

func GenerateSecureRandomString() []byte

func GetCookie

func GetCookie(name string, r *http.Request, dst interface{}) error

Reads cookie value into dst. Returns http.ErrNoCookie if there is no cookie with the given name.

func GetPayeeUserKey

func GetPayeeUserKey(reqCode string) *datastore.Key

func GetUserId

func GetUserId(email string, c *Context) (int64, error)

func GetUserIdOrDie

func GetUserIdOrDie(email string, c *Context) int64

func GoogleMakeConfig

func GoogleMakeConfig(tokenCache oauth.Cache) *oauth.Config

NOTE(sadovsky): We set ApprovalPrompt to "force" so that we can easily recover from losing a refresh token.

func MakeSession

func MakeSession(userId int64, email, fullName string, w http.ResponseWriter, c *Context) error

Sets session cookie and updates context.

func NewEphemeralKey

func NewEphemeralKey(c appengine.Context, kind string) *datastore.Key

func ParseAmount

func ParseAmount(amount string) float32

func ParseEmail

func ParseEmail(email string) string

func ParseFullName

func ParseFullName(fullName string) string

func ParsePaymentType

func ParsePaymentType(paymentTypeStr string) int

func ReadSession

func ReadSession(r *http.Request, c *Context) error

Reads session cookie and updates context.

func RedirectWithMessage

func RedirectWithMessage(w http.ResponseWriter, r *http.Request, url, msg string)

func RenderPageOrDie

func RenderPageOrDie(w http.ResponseWriter, c *Context, name string, data interface{})

func RenderTemplateOrDie

func RenderTemplateOrDie(w http.ResponseWriter, name string, data interface{})

func SaltAndHash

func SaltAndHash(salt []byte, password string) []byte

func Serve404

func Serve404(w http.ResponseWriter)

func ServeError

func ServeError(w http.ResponseWriter, data interface{})

func ServeInfo

func ServeInfo(w http.ResponseWriter, info string)

func SetCookie

func SetCookie(name string, value interface{}, options *CookieOptions, w http.ResponseWriter) error

func SetFlash

func SetFlash(value string, w http.ResponseWriter) error

func ToOAuthTokenKey

func ToOAuthTokenKey(c appengine.Context, userId int64, service string) *datastore.Key

func ToUserIdKey

func ToUserIdKey(c appengine.Context, email string) *datastore.Key

func ToUserKey

func ToUserKey(c appengine.Context, userId int64) *datastore.Key

func UpdateSession

func UpdateSession(s *Session, w http.ResponseWriter, c *Context) error

Updates session cookie and context.

func WrapHandler

func WrapHandler(fn AppHandlerFunc) http.HandlerFunc

func WrapHandlerImpl

func WrapHandlerImpl(fn AppHandlerFunc, parseForm bool) http.HandlerFunc

Wraps other http handlers. Creates context object, recovers from panics, etc.

func WrapHandlerNoParseForm

func WrapHandlerNoParseForm(fn AppHandlerFunc) http.HandlerFunc

Types

type AppHandlerFunc

type AppHandlerFunc func(http.ResponseWriter, *http.Request, *Context)

type Contact

type Contact struct {
	Name  string
	Email string
}

func GoogleParseContacts

func GoogleParseContacts(r io.Reader) ([]*Contact, error)

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Aec

func (c *Context) Aec() appengine.Context

func (*Context) AssertLoggedIn

func (c *Context) AssertLoggedIn()

func (*Context) AssertNotLoggedIn

func (c *Context) AssertNotLoggedIn()

func (*Context) Delete

func (c *Context) Delete(key interface{})

func (*Context) DeleteSession

func (c *Context) DeleteSession()

func (*Context) Flash

func (c *Context) Flash() string

func (*Context) Get

func (c *Context) Get(key interface{}) interface{}

func (*Context) LoggedIn

func (c *Context) LoggedIn() bool

func (*Context) Session

func (c *Context) Session() *Session

func (*Context) Set

func (c *Context) Set(key interface{}, value interface{})

func (*Context) SetAec

func (c *Context) SetAec(aec appengine.Context)

func (*Context) SetFlash

func (c *Context) SetFlash(flash string)

func (*Context) SetSession

func (c *Context) SetSession(s *Session)

type CookieOptions

type CookieOptions struct {
	MaxAge int
}

Subset of http://golang.org/pkg/net/http/#Cookie.

type DatastoreOAuthTokenCache

type DatastoreOAuthTokenCache struct {
	UserId  int64
	Context *Context
	Service string
}

Implements oauth.Cache.

func (*DatastoreOAuthTokenCache) DeleteToken

func (tc *DatastoreOAuthTokenCache) DeleteToken() error

func (*DatastoreOAuthTokenCache) PutToken

func (tc *DatastoreOAuthTokenCache) PutToken(t *oauth.Token) error

func (*DatastoreOAuthTokenCache) Token

func (tc *DatastoreOAuthTokenCache) Token() (*oauth.Token, error)

type OAuthToken

type OAuthToken struct {
	AccessToken  string
	RefreshToken string
	Expiry       time.Time
}

Keyed by service name (e.g. "google"), with User as parent. Subset of oauth.Token.

func GetOAuthTokenFromUserId

func GetOAuthTokenFromUserId(userId int64, service string, c *Context) (*OAuthToken, error)

type PageData

type PageData struct {
	FullName string
	Message  string
	Title    template.HTML
	Css      template.HTML
	Body     template.HTML
	Js       template.HTML
}

type PayPalIpnMessage

type PayPalIpnMessage struct {
	Status     string  // status
	PayerEmail string  // sender_email
	PayeeEmail string  // transaction[0].receiver
	Amount     float32 // extracted from transaction[0].amount
	PayKey     string  // pay_key
}

Stores the useful fields from a single paypal IPN message. IPN reference: http://goo.gl/bIX2Q

func PayPalValidateIpn

func PayPalValidateIpn(requestBody string, c *Context) (*PayPalIpnMessage, error)

IPN handler references: http://goo.gl/bIX2Q and http://goo.gl/F1uej

type PayPalPayResponse

type PayPalPayResponse struct {
	Ack           string // responseEnvelope.ack
	Build         string // responseEnvelope.build
	CorrelationId string // responseEnvelope.correlationId
	Timestamp     string // responseEnvelope.timestamp
	PayKey        string // payKey
}

Stores paypal response to one "Pay" request. Pay API reference: http://goo.gl/D6dUR

func PayPalSendPayRequest

func PayPalSendPayRequest(reqCode, payeePayPalEmail, description string, amount float32, c *Context) (*PayPalPayResponse, string, error)

type PayRequest

type PayRequest struct {
	PayeeEmail       string // primary email of payee
	PayerEmail       string // email of payer
	Amount           float32
	PaymentType      int // PTPersonal, PTGoods, or PTServices
	Description      string
	CreationDate     time.Time
	IsPaid           bool      // needed for datastore queries
	PaymentDate      time.Time // unix epoch if not yet paid in full
	DeletionDate     time.Time // unix epoch if not deleted
	ReminderSentDate time.Time // most recent reminder send date, or unix epoch
}

Keyed by int (NewIncompleteKey), with payee User as parent. TODO(sadovsky):

  • Add field for currency code (same as in paypal request).
  • Maybe add a PaymentStatus struct.

type RenderablePayRequest

type RenderablePayRequest struct {
	ReqCode      string
	PayUrl       string
	PayerEmail   string
	Amount       string
	Description  string
	IsPaid       bool
	Status       string
	CreationDate string
}

type ResetPassword

type ResetPassword struct {
	UserId    int64     // user for which to reset password
	Timestamp time.Time // when this request was made
}

Keyed by secure random number (NewEphemeralKey).

type Session

type Session struct {
	UserId    int64
	Timestamp time.Time // when this session was created
	Email     string    // email of user, stored here for convenience
	FullName  string    // full name of user, stored here for convenience
}

type User

type User struct {
	Email       string // primary email of account holder
	Salt        string // DEPRECATED, use SaltB
	SaltB       []byte
	PassHash    string // DEPRECATED, use PassHashB
	PassHashB   []byte // hash of salted password
	FullName    string // full name of user
	PayPalEmail string // paypal account email
	EmailOk     bool   // true if user has verified their primary email
}

Keyed by int (NewIncompleteKey).

func GetUserFromEmail

func GetUserFromEmail(email string, c *Context) (int64, *User, error)

func GetUserFromEmailOrDie

func GetUserFromEmailOrDie(email string, c *Context) (int64, *User)

func GetUserFromSessionOrDie

func GetUserFromSessionOrDie(c *Context) *User

func GetUserFromUserId

func GetUserFromUserId(userId int64, c *Context) (*User, error)

func GetUserFromUserIdOrDie

func GetUserFromUserIdOrDie(userId int64, c *Context) *User

func GetUserOrDie

func GetUserOrDie(key *datastore.Key, c *Context) *User

type UserId

type UserId struct {
	UserId int64
}

Keyed by email address string.

type VerifyEmail

type VerifyEmail struct {
	UserId    int64     // user to verify
	Timestamp time.Time // when this request was made
}

Keyed by secure random number (NewEphemeralKey).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL