controllers

package
v4.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerFactory

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

ControllerFactory generates controlloers by given persistent storage connection and mail service

func NewControllerFactory

func NewControllerFactory(gormDB *gorm.DB, mgoSession *mgo.Session, mailSvc services.MailService) *ControllerFactory

NewControllerFactory generate *ControllerFactory struct

func (*ControllerFactory) GetFacebookController

func (cf *ControllerFactory) GetFacebookController() Facebook

GetFacebookController returns Facebook struct

func (*ControllerFactory) GetGoogleController

func (cf *ControllerFactory) GetGoogleController() Google

GetGoogleController returns Google struct

func (*ControllerFactory) GetGormDB

func (cf *ControllerFactory) GetGormDB() *gorm.DB

GetMgoSession returns *gorm.DB it holds

func (*ControllerFactory) GetMailController

func (cf *ControllerFactory) GetMailController() *MailController

GetMailController returns *MailController struct

func (*ControllerFactory) GetMailService

func (cf *ControllerFactory) GetMailService() services.MailService

GetMailService returns MailService it holds

func (*ControllerFactory) GetMembershipController

func (cf *ControllerFactory) GetMembershipController() *MembershipController

GetMembershipController returns *MembershipController struct

func (*ControllerFactory) GetMgoSession

func (cf *ControllerFactory) GetMgoSession() *mgo.Session

GetMgoSession returns *mgo.Session it holds

func (*ControllerFactory) GetNewsController

func (cf *ControllerFactory) GetNewsController() *NewsController

GetNewsController returns *NewsController struct

func (*ControllerFactory) GetOAuthController

func (cf *ControllerFactory) GetOAuthController(oauthType string) (oauth *OAuth)

GetOAuthController returns OAuth struct

type Facebook

type Facebook struct {
	Storage storage.MembershipStorage
	// contains filtered or unexported fields
}

Facebook ...

func (*Facebook) Authenticate

func (f *Facebook) Authenticate(c *gin.Context)

Authenticate requests the user profile from Facebook

func (*Facebook) BeginAuth

func (f *Facebook) BeginAuth(c *gin.Context)

BeginAuth redirects user to the Facebook Authentication

func (*Facebook) GetRemoteUserData

func (f *Facebook) GetRemoteUserData(r *http.Request, w http.ResponseWriter) (string, error)

GetRemoteUserData fetched user data from Facebook

func (*Facebook) InitOauthConfig

func (f *Facebook) InitOauthConfig(destination string)

InitOauthConfig initialize facebook oauth config

type Google

type Google struct {
	Storage storage.MembershipStorage
	// contains filtered or unexported fields
}

Google ...

func (*Google) Authenticate

func (g *Google) Authenticate(c *gin.Context)

Authenticate requests the user profile from Google

func (*Google) BeginAuth

func (g *Google) BeginAuth(c *gin.Context)

BeginAuth redirects user to the Google Authentication

func (*Google) GetRemoteUserData

func (g *Google) GetRemoteUserData(r *http.Request, w http.ResponseWriter) (string, error)

GetRemoteUserData fetched user data from Google

func (*Google) InitOauthConfig

func (g *Google) InitOauthConfig(destination string)

InitOauthConfig initialize google oauth config

type IndexPageQueryStruct

type IndexPageQueryStruct struct {
	MongoQuery   models.MongoQuery
	Limit        int
	Offset       int
	Sort         string
	Embedded     []string
	ResourceType string
	Full         bool
}

IndexPageQueryStruct struct for querying.

type MailController

type MailController struct {
	HTMLTemplate *template.Template
	MailService  services.MailService
}

MailController is the data structure holding HTML template and mail service

func NewMailController

func NewMailController(svc services.MailService, t *template.Template) *MailController

NewMailController is used to new *MailController

func (*MailController) LoadTemplateFiles

func (contrl *MailController) LoadTemplateFiles(filenames ...string)

LoadTemplateFiles is a wrapper function to parse template files

func (*MailController) SendActivation

func (contrl *MailController) SendActivation(c *gin.Context) (int, gin.H, error)

SendActivation retrieves email and activation link from rqeuest body, and invoke MailService to send activation mail

func (*MailController) SendDonationSuccessMail

func (contrl *MailController) SendDonationSuccessMail(c *gin.Context) (int, gin.H, error)

type MembershipController

type MembershipController struct {
	Storage storage.MembershipStorage
}

MembershipController ...

func NewMembershipController

func NewMembershipController(s storage.MembershipStorage) *MembershipController

NewMembershipController ...

func (*MembershipController) Activate

func (mc *MembershipController) Activate(c *gin.Context) (int, gin.H, error)

Activate - validate the reporter account if validated, then sign in successfully, otherwise, sign in unsuccessfully.

func (*MembershipController) ActivateV2

func (mc *MembershipController) ActivateV2(c *gin.Context)

ActivateV2 - validate the reporter account if validated, then sign in successfully, otherwise, sign in unsuccessfully.

func (*MembershipController) Close

func (mc *MembershipController) Close() error

Close is the method of Controller interface

func (*MembershipController) CreateABookmarkOfAUser

func (mc *MembershipController) CreateABookmarkOfAUser(c *gin.Context) (int, gin.H, error)

CreateABookmarkOfAUser given userID and bookmark POST body, this func will try to create bookmark record in the bookmarks table, and build the relationship between bookmark and user

func (*MembershipController) CreateADonationOfAUser

func (mc *MembershipController) CreateADonationOfAUser(c *gin.Context) (int, gin.H, error)

Handler for an authenticated user to create an one-time donation

func (*MembershipController) CreateAPeriodicDonationOfAUser

func (mc *MembershipController) CreateAPeriodicDonationOfAUser(c *gin.Context) (int, gin.H, error)

Handler for an authenticated user to create a periodic donation

func (*MembershipController) DeleteABookmarkOfAUser

func (mc *MembershipController) DeleteABookmarkOfAUser(c *gin.Context) (int, gin.H, error)

DeleteABookmarkOfAUser given userID and bookmarkHref, this func will remove the relationship between user and bookmark

func (*MembershipController) GetADonationOfAUser

func (mc *MembershipController) GetADonationOfAUser(c *gin.Context, donationType string) (int, gin.H, error)

GetADonationOfAUser returns a donation of a user

func (*MembershipController) GetBookmarksOfAUser

func (mc *MembershipController) GetBookmarksOfAUser(c *gin.Context) (int, gin.H, error)

GetBookmarksOfAUser given userID this func will list all the bookmarks belongs to the user

func (*MembershipController) GetDonationsOfAUser

func (mc *MembershipController) GetDonationsOfAUser(c *gin.Context) (int, gin.H, error)

TODO GetDonationsOfAUser returns the donations list of a user

func (*MembershipController) IsWebPushSubscribed

func (mc *MembershipController) IsWebPushSubscribed(c *gin.Context) (int, gin.H, error)

IsWebPushSubscribed - which handles the HTTP Get request, and try to check if the web push subscription is existed or not

func (*MembershipController) PatchADonationOfAUser

func (mc *MembershipController) PatchADonationOfAUser(c *gin.Context, donationType string) (int, gin.H, error)

PatchADonationOfAUser method Handler for an authenticated user to patch an prime/token/periodic donation

func (*MembershipController) RenewJWT

func (mc *MembershipController) RenewJWT(c *gin.Context) (int, gin.H, error)

RenewJWT - validate the old JWT, if validated, then renew a new one

func (*MembershipController) SignIn

func (mc *MembershipController) SignIn(c *gin.Context) (int, gin.H, error)

SignIn - send email containing sign-in information to the client

func (*MembershipController) SignInV2

func (mc *MembershipController) SignInV2(c *gin.Context) (int, gin.H, error)

SignInV2 - send email containing sign-in information to the client

func (*MembershipController) SubscribeWebPush

func (mc *MembershipController) SubscribeWebPush(c *gin.Context) (int, gin.H, error)

SubscribeWebPush - which handles the HTTP POST request, and try to create a web push subscription record into the persistent database

func (*MembershipController) TokenDispatch

func (mc *MembershipController) TokenDispatch(c *gin.Context)

TokenDispatch returns the `access_token` in payload for frontend server

func (*MembershipController) TokenInvalidate

func (mc *MembershipController) TokenInvalidate(c *gin.Context)

TokenInvalidate deletes the id_token stored in the client side

type MenuItemsController struct{}

MenuItemsController ...

func (u MenuItemsController) Retrieve(c *gin.Context)

Retrieve ...

type NewsController

type NewsController struct {
	Storage storage.NewsStorage
}

NewsController has methods to handle requests which wants posts, topics ... etc news resource.

func NewNewsController

func NewNewsController(s storage.NewsStorage) *NewsController

NewNewsController ...

func (*NewsController) GetAPost

func (nc *NewsController) GetAPost(c *gin.Context)

GetAPost receive HTTP GET method request, and return the certain post.

func (*NewsController) GetATopic

func (nc *NewsController) GetATopic(c *gin.Context)

GetATopic receive HTTP GET method request, and return the certain post.

func (*NewsController) GetAuthors

func (nc *NewsController) GetAuthors(c *gin.Context) (int, gin.H, error)

GetAuthors receive HTTP GET method request, and return the authors. `limit`, `offset` and `sort` are the url query params, which define the rule we retrieve authors from storage.

func (*NewsController) GetCategoriesPosts

func (nc *NewsController) GetCategoriesPosts(c *gin.Context)

GetCategoriesPosts is specifically made for index page. It will return the posts of all the categories.

func (*NewsController) GetIndexPageContents

func (nc *NewsController) GetIndexPageContents(c *gin.Context)

GetIndexPageContents is specifically made for index page. It will return the first fourth sections including latest, editor picks, latest topic and reviews.

func (*NewsController) GetPosts

func (nc *NewsController) GetPosts(c *gin.Context)

GetPosts receive HTTP GET method request, and return the posts. `query`, `limit`, `offset`, `sort` and `full` are the url query params, which define the rule we retrieve posts from storage.

func (*NewsController) GetQueryParam

func (nc *NewsController) GetQueryParam(c *gin.Context) (mq models.MongoQuery, limit int, offset int, sort string, full bool)

GetQueryParam pares url param

func (*NewsController) GetTopics

func (nc *NewsController) GetTopics(c *gin.Context)

GetTopics receive HTTP GET method request, and return the topics. `query`, `limit`, `offset` and `sort` are the url query params, which define the rule we retrieve topics from storage.

func (*NewsController) SearchAuthors

func (nc *NewsController) SearchAuthors(c *gin.Context)

SearchAuthors - search authors from algolia webservice

func (*NewsController) SearchPosts

func (nc *NewsController) SearchPosts(c *gin.Context)

SearchPosts - search posts of authors from algolia webservice

type OAuth

type OAuth struct {
	Storage storage.MembershipStorage
	// contains filtered or unexported fields
}

OAuth which stores storage connection and oauth config

func (*OAuth) Authenticate

func (o *OAuth) Authenticate(c *gin.Context)

Authenticate handles [google|facebook] oauth of users and redirect them to specific URL they want with Set-Cookie response header which contains JWT

func (*OAuth) BeginOAuth

func (o *OAuth) BeginOAuth(c *gin.Context)

BeginAuth redirects user to the [facebook|google] authentication(login) page

func (*OAuth) InitFacebookConfig

func (o *OAuth) InitFacebookConfig()

InitGoogleConfig initiates facebook oauth config

func (*OAuth) InitGoogleConfig

func (o *OAuth) InitGoogleConfig()

InitGoogleConfig initiates google oauth config

Jump to

Keyboard shortcuts

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