users

package
v0.0.0-...-cc0b965 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(oauthConf *oauth2.Config, token *oauth2.Token) *github.Client

NewClient returns a github.Client using oauthconf and token.

Types

type Discount

type Discount struct {
	CouponID    string
	StartedAt   time.Time
	EndedAt     time.Time
	Description string
}

Discount represents a discount to be applied.

type Invoice

type Invoice struct {
	AmountDisplay string
	DueDate       time.Time
}

Invoice represents an upcoming or previous invoice.

type Subscription

type Subscription struct {
	ID            string
	Name          string    // Name is the plan name.
	AmountDisplay string    // AmountDisplay is the amount formatted for display.
	AmountCents   uint      // AmountCents is the amount in cents.
	Interval      string    // Interval is the billing interval, such as month.
	StartedAt     time.Time // StartedAt is the date started.
	PeriodEndAt   time.Time // PeriodEndAt is the end date of the current interval.
	CancelledAt   time.Time // CancelledAt is the date the subscription was cancelled.
	// EndedAt is the date the subscription finally ended (it may have been
	// cancelled and ended at the period end).
	EndedAt time.Time
	// Ended is whether the subcription is currently active (it maybe cancelled,
	// but not currently ended).
	Ended bool
}

Subscription represents a payment subscription.

type User

type User struct {
	Logger *logrus.Entry

	GHClient         *github.Client
	UserID           int    `db:"id"`
	Email            string `db:"email"`
	GitHubID         int    `db:"github_id"`
	GitHubToken      []byte `db:"github_token"` // nil if none assigned to user
	StripeCustomerID string `db:"stripe_customer_id"`
	// contains filtered or unexported fields
}

User represents a GopherCI-web user.

func GetUser

func GetUser(logger *logrus.Entry, db *sqlx.DB, oauthConf *oauth2.Config, userID int) (*User, error)

GetUser looks up a user in the db and returns it, if no user was found, user is nil, if an error occurs it will be returned.

func (*User) CancelStripeSubscription

func (u *User) CancelStripeSubscription(id string, endCancel bool) error

CancelStripeSubscription cancels a stripe subscription at the end of the current billing period if endCancel is true. It does not disable any enabled installations.

func (*User) DisableInstallation

func (u *User) DisableInstallation(installationID int) error

DisableInstallation marks a GitHub installation as disabled for this user. This does not disable the installation in GopherCI. Returns an error if an error occurred, else success if successfully changed from enabled to disabled.

func (*User) EnableInstallation

func (u *User) EnableInstallation(installationID int) error

EnableInstallation marks a GitHub installation as enabled for this user. This does not enable the installation in GopherCI. Returns an error if an error occured, else success if successfully changed from disabled to enabled.

func (*User) EnabledInstallations

func (u *User) EnabledInstallations() ([]int, error)

EnabledInstallations returns a slice of installationIDs that are marked as enabled by for the user.

func (*User) GitHubListOrgMembershipsActive

func (u *User) GitHubListOrgMembershipsActive(ctx context.Context) ([]*github.Membership, error)

GitHubListOrgMembershipsActive returns active https://godoc.org/github.com/google/go-github/github#OrganizationsService.ListOrgMemberships

func (*User) InstallationEnabled

func (u *User) InstallationEnabled(installationID int) bool

InstallationEnabled checks if installationID is enabled by this user, any error means installation is not enabled by this user.

func (*User) ProcessStripeCoupon

func (u *User) ProcessStripeCoupon(couponID string) error

ProcessStripeCoupon adds a couponID to a stripe customer.

func (*User) ProcessStripePayment

func (u *User) ProcessStripePayment(token, plan string) error

func (*User) StripeCustomer

func (u *User) StripeCustomer() (*stripe.Customer, error)

StripeCustomer gets the stripe customer, returns nil if there's no stripe customer ID or an error if an error occurs.

func (*User) StripeDiscount

func (u *User) StripeDiscount(customer *stripe.Customer) *Discount

StripeDiscount returns the discount for the current user. If the user does not have an active discount, nil is returned.

func (*User) StripeSubscriptions

func (u *User) StripeSubscriptions(customer *stripe.Customer) []Subscription

StripeSubscriptions returns a slice of subscriptions for the current user, both current and previous subscriptions are returned.

func (*User) StripeUpcomingInvoice

func (u *User) StripeUpcomingInvoice() (*Invoice, error)

StripeUpcomingInvoice returns the upcoming invoice for a user, nil if there are no upcoming invoices for this user, or an error.

type UserManager

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

UserManager manages all the user accounts.

func NewUserManager

func NewUserManager(logger *logrus.Entry, db *sqlx.DB, clientID, clientSecret, stripeKey string) *UserManager

NewUserManager returns a new UserManager initialised with db and GitHub clientID and clientSecret.

func (*UserManager) GetUser

func (um *UserManager) GetUser(userID int) (*User, error)

GetUser returns a user for a given UserID, returns nil if user is not found or an error.

func (*UserManager) GitHubLogin

func (um *UserManager) GitHubLogin(ctx context.Context, githubID int, token *oauth2.Token) (userID int, err error)

GitHubLogin assigns the token to an existing user with the given githubID, if the user does not exist, the user is created. If an error occurs err is non-nil, else the userID of the user is returned.

func (*UserManager) OAuthCallbackHandler

func (um *UserManager) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request)

OAuthCallbackHandler handles the callback after GitHub authentication and persists the credentials to storage for use later.

func (*UserManager) OAuthLoginHandler

func (um *UserManager) OAuthLoginHandler(w http.ResponseWriter, r *http.Request)

OAuthLoginHandler starts the initial oauth login flow by redirecting the user to GitHub for authentication and authorisation our app.

Jump to

Keyboard shortcuts

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