30 lines
694 B
Go
30 lines
694 B
Go
package controllers
|
|
|
|
// BaseController operations for APIs
|
|
type BaseAPIController struct {
|
|
BaseController
|
|
}
|
|
|
|
func (this *BaseAPIController) Prepare() {
|
|
|
|
/*
|
|
//Lo que quieras hacer en todos los controladores
|
|
// O puede ser leído de una cabecera HEADER!!
|
|
tokenString := this.Ctx.Request.Header.Get("X-JWTtoken")
|
|
et := jwtbeego.EasyToken{}
|
|
valid, issuer, _ := et.ValidateToken(tokenString)
|
|
if !valid {
|
|
this.Ctx.Output.SetStatus(401)
|
|
this.ServeJsonError("Invalid Token")
|
|
}
|
|
/*
|
|
userSession := this.GetSession("username")
|
|
|
|
if userSession == nil || userSession != issuer {
|
|
this.Ctx.Output.SetStatus(401)
|
|
this.ServeJsonError("Invalid Session")
|
|
}
|
|
*/
|
|
//return
|
|
}
|