Beispiel #1
0
func roomGET(c *gin.Context) {
	roomid := c.Param("roomid")
	nick := c.Query("nick")
	if len(nick) < 2 {
		nick = ""
	}
	if len(nick) > 13 {
		nick = nick[0:12] + "..."
	}
	c.HTML(200, "room_login.templ.html", gin.H{
		"roomid":    roomid,
		"nick":      nick,
		"timestamp": time.Now().Unix(),
	})

}
Beispiel #2
0
// Index возвращает главную страницу админской панели.
// GET /admin
func Index(c *gin.Context) {
	if !assertAccess(c) {
		return
	}
	page, err := strconv.Atoi(c.Query("p"))
	if err != nil {
		page = 1
	}
	pcount := user.Pages(usersPerPage)
	ctl.RenderHTML(c, "admin_index.tmpl", gin.H{
		"Users": user.FindPage(page, usersPerPage, user.ByVisitedAtDesc),
		"Pager": gin.H{
			"Cur":      page,
			"Max":      pcount,
			"PathTmpl": "/admin?p=",
		},
	})
}
Beispiel #3
0
func roomPOST(c *gin.Context) {
	roomid := c.Param("roomid")
	nick := c.Query("nick")
	message := c.PostForm("message")
	message = strings.TrimSpace(message)

	validMessage := len(message) > 1 && len(message) < 200
	validNick := len(nick) > 1 && len(nick) < 14
	if !validMessage || !validNick {
		c.JSON(400, gin.H{
			"status": "failed",
			"error":  "the message or nickname is too long",
		})
		return
	}

	post := gin.H{
		"nick":    html.EscapeString(nick),
		"message": html.EscapeString(message),
	}
	messages.Add("inbound", 1)
	room(roomid).Submit(post)
	c.JSON(200, post)
}