예제 #1
0
파일: app.go 프로젝트: gtfour/actuator
func GetDashboardData() func(c *gin.Context) {
	return func(c *gin.Context) {
		if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil {
			dashboardId := c.Param("dashboardId")
			dashboardGroupId := c.Param("dashboardGroupId")
			fmt.Printf("\nDashboard %v DashboardGroup %v\n", dashboardId, dashboardGroupId)
			dashboard_data, _ := webclient.GetDashboardData(user_id, token_id, dashboardId)
			c.JSON(200, gin.H{"status": "ok", "data": dashboard_data})
		} else {
			c.JSON(200, gin.H{"status": "error"})
		}
	}
}
예제 #2
0
파일: app.go 프로젝트: gtfour/actuator
func UserspaceData() func(c *gin.Context) {
	//template_name  := "index.html"
	return func(c *gin.Context) {
		if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil {
			dashboards := webclient.GetUserDashboards(user_id, token_id)
			data := settings.APP_SETTINGS
			data["navigation_menu"] = CreateNavigationMenuJson(dashboards)
			//data["status"]           = "ok"
			c.JSON(200, gin.H{"status": "ok", "data": data})
		} else {
			c.JSON(401, gin.H{"status": "Unauthorized", "data": gin.H{}})
		}
	}
}
예제 #3
0
파일: app.go 프로젝트: gtfour/actuator
func Logout() func(c *gin.Context) {
	return func(c *gin.Context) {
		user_id, token_id, err := auth.GetTokenFromCookies(c)
		wrapper := userstorage.GetWrapper(user_id, token_id)
		if wrapper != nil {
			webclient.Disconnect(wrapper)
			userstorage.RemoveWrapper(user_id, token_id)
			fmt.Printf("Logout:: FindWrapper:: %v", userstorage.FindWrapper(user_id, token_id))
		}
		if err == nil {
			c.Redirect(302, settings.SERVER_URL+"/auth/login")
		} else {
			c.Redirect(302, settings.SERVER_URL+"/index")
		}
		//c.HTML(200, template_name,  data )
	}
}
예제 #4
0
파일: ws.go 프로젝트: gtfour/actuator
func (s *Server) GetHandler(c *gin.Context) (function func(ws *websocket.Conn)) {

	token, user, err := auth.GetTokenFromCookies(c)
	fmt.Printf("token:%v\nuser:%v\nerr:%v\n", token, user, err)
	function = func(ws *websocket.Conn) {
		defer func() {
			err := ws.Close()
			if err != nil {
				s.errChannel <- err
			}
		}()
		client := NewClient(ws, s)
		s.Add(client)
		client.Listen()
	}
	return function
}
예제 #5
0
파일: app.go 프로젝트: gtfour/actuator
func Index() func(c *gin.Context) {
	template_name := "index.html"
	self_link := "/userspace"
	return func(c *gin.Context) {
		//if (auth.IsAuthorized(c,wrappers) && (user_id,token_id,err:=auth.GetTokenFromCookies(c); err==nil) )  {
		// thanks for postman from golang@cjr
		if user_id, token_id, err := auth.GetTokenFromCookies(c); auth.IsAuthorized(c) && err == nil {
			session_id, _ := common.GenId()
			dashboards := webclient.GetUserDashboards(user_id, token_id)
			navigaton_menu := CreateNavigationMenu(dashboards)
			data := settings.APP_SETTINGS
			data["navigation_menu"] = navigaton_menu
			data["session_id"] = session_id
			data["websocket"] = "true"
			data["app_data_url"] = settings.USERSPACE_DATA_URL
			c.HTML(200, template_name, data)
		} else {
			c.Redirect(302, "/auth/login?redirect_to="+self_link)
		}
	}
}