Documentation ¶
Index ¶
- Variables
- func FilterAdmin(c *beego.Controller)
- func FilterMeOrAdmin(c *beego.Controller, uid int64)
- func FilterOwnerOrAdmin(c *beego.Controller, owner int64)
- func GetAllDevices() (*[]models.Device, *models.JSONError)
- func GetDevice(port string) (*models.Device, *models.JSONError)
- func PowerDeviceOff(port string) *models.JSONError
- func PowerDeviceOn(port string) *models.JSONError
Constants ¶
This section is empty.
Variables ¶
View Source
var FilterUser = func(ctx *beegoCtx.Context) { unprotectedRoutes := []map[string]string{ {"method": http.MethodGet, "url": "/v1/user/login"}, } for _, route := range unprotectedRoutes { if strings.HasPrefix(ctx.Input.URL(), route["url"]) && route["method"] == ctx.Request.Method { return } } authorization := ctx.Input.Header("Authorization") re := regexp.MustCompilePOSIX(`^Bearer (.+)$`) if !re.MatchString(authorization) { ctx.Output.Status = http.StatusUnauthorized ctx.Output.JSON(map[string]string{"message": "Unauthorized"}, false, false) return } tokenString := strings.Split(authorization, " ")[1] claims := &models.Claims{} token, err := jwt.ParseWithClaims(tokenString, claims, func(token *jwt.Token) (interface{}, error) { return []byte(beego.AppConfig.String("jwtsecret")), nil }) if err != nil { ctx.Output.Status = http.StatusUnauthorized ctx.Output.JSON(map[string]string{"message": "Unauthorized"}, false, false) return } if !token.Valid { ctx.Output.Status = http.StatusUnauthorized ctx.Output.JSON(map[string]string{"message": "Unauthorized"}, false, false) return } ctxWithUser := context.WithValue(ctx.Request.Context(), interface{}("claims"), claims) ctx.Request = ctx.Request.WithContext(ctxWithUser) }
FilterUser verifies if the `User` is authenticated
Functions ¶
func FilterAdmin ¶
func FilterAdmin(c *beego.Controller)
FilterAdmin checks if the `User` has an administrator `Role`. If not, return an Unauthorized `JSONError`.
func FilterMeOrAdmin ¶
func FilterMeOrAdmin(c *beego.Controller, uid int64)
FilterMeOrAdmin checks if the `User` is the same as the given `uid` or and admin. If not, return an Unauthorized `JSONError`.
func FilterOwnerOrAdmin ¶
func FilterOwnerOrAdmin(c *beego.Controller, owner int64)
FilterOwnerOrAdmin checks id the `User` is the same as the given `uid`
func GetAllDevices ¶
GetAllDevices add all the Rubus `Device` into the database
func PowerDeviceOff ¶
PowerDeviceOff shuts down the `Device` on the given `port`
func PowerDeviceOn ¶
PowerDeviceOn boots the `Device` on the given `port`
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.