Beispiel #1
0
func gettask(c *gin.Context) (*todo.Todo, *todolist.TodoList, bool) {
	u, ok := user.FromContext(c)
	if !ok {
		ctl.Render403(c)
		return nil, nil, false
	}
	id, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		ctl.Render404(c)
		return nil, nil, false
	}
	td, ok := todo.Find(uint(id))
	if !ok {
		ctl.Render404(c)
		return nil, nil, false
	}
	l, ok := todolist.Find(td.TodoListID)
	if !ok {
		ctl.Render500(c)
		return nil, nil, false
	}
	if u.ID != l.UserID {
		ctl.Render403(c)
		return nil, nil, false
	}
	return td, l, true
}
Beispiel #2
0
func getlist(c *gin.Context) (*todolist.TodoList, bool) {
	u, ok := user.FromContext(c)
	if !ok {
		ctl.Render403(c)
		return nil, false
	}
	id, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		ctl.Render404(c)
		return nil, false
	}
	l, ok := todolist.Find(uint(id))
	if !ok {
		ctl.Render404(c)
		return nil, false
	}
	if l.UserID != u.ID {
		ctl.Render403(c)
		return nil, false
	}
	return l, true
}