forked from globocom/secDevLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
37 lines (31 loc) · 1.06 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package handlers
import (
"fmt"
"net/http"
"github.com/globocom/secDevLabs/owasp-top10-2017-apps/a5/ecommerce-api/app/db"
"github.com/labstack/echo"
)
// HealthCheck is the heath check function.
func HealthCheck(c echo.Context) error {
return c.String(http.StatusOK, "WORKING\n")
}
// GetTicket returns the userID ticket.
func GetTicket(c echo.Context) error {
id := c.Param("id")
userDataQuery := map[string]interface{}{"userID": id}
userDataResult, err := db.GetUserData(userDataQuery)
if err != nil {
// could not find this user in MongoDB (or MongoDB err connection)
return c.JSON(http.StatusBadRequest, map[string]string{"result": "error", "details": "Error finding this UserID."})
}
format := c.QueryParam("format")
if format == "json" {
return c.JSON(http.StatusOK, map[string]string{
"result": "success",
"username": userDataResult.Username,
"ticket": userDataResult.Ticket,
})
}
msgTicket := fmt.Sprintf("Hey, %s! This is your ticket: %s\n", userDataResult.Username, userDataResult.Ticket)
return c.String(http.StatusOK, msgTicket)
}