handlers

package
v0.0.0-...-a35bd06 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenKey is the context key for the JWT token
	TokenKey = "token"
	// PermissionsKey is the context key for the token permissions
	PermissionsKey = "permissions"
)

Variables

This section is empty.

Functions

func ContactHandler

func ContactHandler(mailer mail.Mailer) func(w http.ResponseWriter, r *http.Request)

ContactHandler send an email to coderockr

func CreateNeedHandler

func CreateNeedHandler(create func(model.Need) (model.Need, error)) func(http.ResponseWriter, *http.Request)

CreateNeedHandler creates a new need based on the payload

func DeleteNeedImagesHandler

func DeleteNeedImagesHandler(storage needStorageContainer) func(w http.ResponseWriter, req *http.Request)

DeleteNeedImagesHandler will delete the image

func DeleteOrganizationImageHandler

func DeleteOrganizationImageHandler(storage organizationStorage) func(w http.ResponseWriter, req *http.Request)

DeleteOrganizationImageHandler will delete the image

func ForgotPasswordHandler

func ForgotPasswordHandler(repo UpdatePasswordOrganizationRepository, mailer mail.Mailer, jm *JWTManager) func(w http.ResponseWriter, r *http.Request)

ForgotPasswordHandler create a token to reset password and send it to email

func GetAllCategoriesHandler

func GetAllCategoriesHandler(cR CategoryRepository, nR NeedRepository) func(http.ResponseWriter, *http.Request)

GetAllCategoriesHandler will retrive the data from all categories

func GetModelToken

func GetModelToken(r *http.Request) *model.Token

GetModelToken retrieves the model.Token from the requests context

func GetNeedHandler

func GetNeedHandler(repo NeedRepository, oRepo needOrganizationRepository) func(w http.ResponseWriter, r *http.Request)

GetNeedHandler retorna uma necessidade pelo ID

func GetOrganizationHandler

func GetOrganizationHandler(getOrg func(int64) (*model.Organization, error), needRepo organizationNeedsRepository) func(http.ResponseWriter, *http.Request)

GetOrganizationHandler will retrive the data from a organization

func GetToken

func GetToken(r *http.Request) string

GetToken retorna o token do usuário logado

func GetUserID

func GetUserID(r *http.Request) int64

GetUserID retorna o id do usuário logado.

func HandleHTTPError

func HandleHTTPError(w http.ResponseWriter, errno int, err error)

HandleHTTPError formats and returns errors

func HandleHTTPSuccess

func HandleHTTPSuccess(w http.ResponseWriter, data interface{}, status ...int)

HandleHTTPSuccess formats and write body

func HandleHTTPSuccessNoContent

func HandleHTTPSuccessNoContent(w http.ResponseWriter)

HandleHTTPSuccessNoContent formats and return with no content

func HasPermission

func HasPermission(r *http.Request, p string) bool

HasPermission returns if the current token has a certain permission

func NeedResponse

func NeedResponse(needRepo NeedRepository, needResponseRepo needResponseRepository, mailer mail.Mailer) func(w http.ResponseWriter, r *http.Request)

NeedResponse responde uma necessidade pelo ID

func NewsletterHandler

func NewsletterHandler() func(w http.ResponseWriter, r *http.Request)

NewsletterHandler add new email to newsletter list

func RenderTemplate

func RenderTemplate(w http.ResponseWriter, tmpl string, data interface{})

RenderTemplate renderiza os arquivos de template

func ResetPasswordHandler

func ResetPasswordHandler(repo UpdatePasswordOrganizationRepository) func(w http.ResponseWriter, r *http.Request)

ResetPasswordHandler resets the current user password, if it has the permissions

func SearchHandler

func SearchHandler(sR SearchNeedRepository) func(w http.ResponseWriter, r *http.Request)

SearchHandler search needs for the term

func ShareNeedHandler

func ShareNeedHandler(repo NeedRepository) func(w http.ResponseWriter, r *http.Request)

ShareNeedHandler return html with metatags for share

func UpdateNeedHandler

func UpdateNeedHandler(repo NeedRepository) func(w http.ResponseWriter, r *http.Request)

UpdateNeedHandler get the need, update and save on database

func UpdateOrganizationHandler

func UpdateOrganizationHandler(repo OrganizationRepository) func(w http.ResponseWriter, req *http.Request)

UpdateOrganizationHandler will update the data of an organization

func UpdatePasswordHandler

func UpdatePasswordHandler(repo UpdatePasswordOrganizationRepository) func(w http.ResponseWriter, r *http.Request)

UpdatePasswordHandler update user password

func UploadNeedImagesHandler

func UploadNeedImagesHandler(container needStorageContainer) func(w http.ResponseWriter, r *http.Request)

UploadNeedImagesHandler upload file to storage and save new image

func UploadOrganizationImageHandler

func UploadOrganizationImageHandler(container organizationStorage, orgRepo OrganizationRepository) func(w http.ResponseWriter, r *http.Request)

UploadOrganizationImageHandler upload file to storage and save new image

Types

type AuthHandler

type AuthHandler struct {
	OrganizationGetter OrganizationGetter
	TokenManager       TokenManager
}

AuthHandler represent all the handler endpoints and middlewares.

func (*AuthHandler) AuthMiddleware

func (a *AuthHandler) AuthMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

AuthMiddleware valida o token e filtra usuários não logados corretamente

func (*AuthHandler) Login

func (a *AuthHandler) Login(w http.ResponseWriter, req *http.Request)

Login process the login requests, returning a JWT token and organization data

type CategoryRepository

type CategoryRepository interface {
	GetAll() ([]model.Category, error)
}

CategoryRepository represet operations for category repository.

type ErrorMessage

type ErrorMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ErrorMessage is a JSON formatter

type JWTManager

type JWTManager struct {
	OP JWTOptions
}

JWTManager actually validate and generate the tokens

func (*JWTManager) CreateToken

func (m *JWTManager) CreateToken(u model.User, permissions *[]string) (string, error)

CreateToken Generates a JSON Web Token given an userId (typically an id or an email), and the JWT options to set SigningMethod and the keys you can check http://github.com/dgrijalva/jwt-go

In case you use an symmetric-key algorithm set PublicKey and PrivateKey equal to the SecretKey ,

func (*JWTManager) ValidateToken

func (m *JWTManager) ValidateToken(tokenString string) (*model.Token, error)

ValidateToken Validates the token that is passed in the request with the Authorization header Authorization: Bearer eyJhbGciOiJub25lIn0

Returns the userId, token (base64 encoded), error

type JWTOptions

type JWTOptions struct {
	SigningMethod string
	PublicKey     []byte
	PrivateKey    []byte
	Expiration    time.Duration
}

JWTOptions contains the needed information to validate and generate jwt tokens

type NeedRepository

type NeedRepository interface {
	Get(id int64) (*model.Need, error)
	Update(model.Need) (model.Need, error)
	CreateImage(i model.NeedImage) (model.NeedImage, error)
}

NeedRepository represet operations for need repository.

type OrganizationGetter

type OrganizationGetter interface {
	GetByEmail(email string) (*model.Organization, error)
}

OrganizationGetter represent the operations for retrieve some organization.

type OrganizationRepository

type OrganizationRepository interface {
	Get(id int64) (*model.Organization, error)
	Update(o model.Organization) (model.Organization, error)
	DeleteImage(imageID int64, organizationID int64) error
}

OrganizationRepository represet operations for organization repository.

type SearchNeedRepository

type SearchNeedRepository interface {
	Search(text string, categoriesID []int, organizationsID int64, status string, orderBy string, order string, page int) ([]model.SearchNeed, int, error)
}

SearchNeedRepository represet operations for need repository.

type TokenManager

type TokenManager interface {
	CreateToken(u model.User, permissions *[]string) (string, error)
	ValidateToken(string) (*model.Token, error)
}

TokenManager represet operations for application tokens.

type UpdatePasswordOrganizationRepository

type UpdatePasswordOrganizationRepository interface {
	Get(id int64) (*model.Organization, error)
	GetByEmail(email string) (*model.Organization, error)
	ResetPasswordTo(o *model.Organization, password string) error
	ChangePassword(o model.Organization, cPassword, newPassword string) (model.Organization, error)
}

UpdatePasswordOrganizationRepository represet operations for organization repository.

Jump to

Keyboard shortcuts

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