Esempio n. 1
3
func PostLike(db gorm.DB, router *gin.Engine) {
	// POST /like
	// POST new like to database
	router.POST("/like", func(c *gin.Context) {
		var likeData model.LikeData
		if err := c.BindJSON(&likeData); err == nil {
			like := &model.Like{
				LikeData: likeData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				like.Trace.CreatedBy = x_user
				like.Trace.UpdatedBy = x_user
				if err := checkDataLike(like.LikeData); err {
					if err := db.Create(&like).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, like)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 2
0
func PostUserPassword(db gorm.DB, router *gin.Engine) {
	// POST /user_password
	// POST new user_password to database
	router.POST("/user_password", func(c *gin.Context) {
		var user_passwordData model.UserPasswordData
		if err := c.BindJSON(&user_passwordData); err == nil {
			user_password := &model.UserPassword{
				UserPasswordData: user_passwordData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				user_password.Trace.CreatedBy = x_user
				user_password.Trace.UpdatedBy = x_user
				if err := checkDataUserPassword(user_password.UserPasswordData); err {
					if err := db.Create(&user_password).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, user_password)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 3
0
func PostSpaceSetting(db gorm.DB, router *gin.Engine) {
	// POST /space_setting
	// POST new space_setting to database
	router.POST("/space_setting", func(c *gin.Context) {
		var space_settingData model.SpaceSettingData
		if err := c.BindJSON(&space_settingData); err == nil {
			space_setting := &model.SpaceSetting{
				SpaceSettingData: space_settingData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				space_setting.Trace.CreatedBy = x_user
				space_setting.Trace.UpdatedBy = x_user
				if err := checkDataSpaceSetting(space_setting.SpaceSettingData); err {
					if err := db.Create(&space_setting).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, space_setting)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 4
0
func PostActivity(db gorm.DB, router *gin.Engine) {
	// POST /activity
	// POST new activity to database
	router.POST("/activity", func(c *gin.Context) {
		var activityData model.ActivityData
		if err := c.BindJSON(&activityData); err == nil {
			activity := &model.Activity{
				ActivityData: activityData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				activity.Trace.CreatedBy = x_user
				activity.Trace.UpdatedBy = x_user
				if err := checkDataActivity(activity.ActivityData); err {
					if err := db.Create(&activity).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, activity)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 5
0
func RegisterRoutes(r *gin.Engine) {

	r.GET("/", func(c *gin.Context) {
		// c.String(http.StatusOK, "this is our home page")
		c.HTML(http.StatusOK, "index.html", nil)

	})

	// --------------------------- user apis ---------------

	r.POST("/v1/users", controllers.User_new)

	r.GET("/v1/users/:userId", controllers.User_get)

	r.PUT("/v1/users/:userId", controllers.User_update)

	r.DELETE("/v1/users/:userId", controllers.User_delete)

	// --------------------------- system apis ---------------

	r.GET("/sys/install", controllers.Sys_getInstall)

	r.POST("/sys/install", controllers.Sys_install)

}
Esempio n. 6
0
func PostGroupAdmin(db gorm.DB, router *gin.Engine) {
	// POST /group_admin
	// POST new group_admin to database
	router.POST("/group_admin", func(c *gin.Context) {
		var group_adminData model.GroupAdminData
		if err := c.BindJSON(&group_adminData); err == nil {
			group_admin := &model.GroupAdmin{
				GroupAdminData: group_adminData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				group_admin.Trace.CreatedBy = x_user
				group_admin.Trace.UpdatedBy = x_user
				if err := checkDataGroupAdmin(group_admin.GroupAdminData); err {
					if err := db.Create(&group_admin).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, group_admin)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 7
0
File: web.go Progetto: robvdl/gcms
// setupRoutes is an internal method where we setup application routes
func setupRoutes(r *gin.Engine) {
	// TODO: home route "/" is not yet defined.
	// r.GET("/", ...)

	// static files served by application
	r.Static("/static", "./static")

	// auth urls for the login form and logout url
	r.GET("/login", auth.Login)
	r.POST("/login", auth.Login)
	r.GET("/logout", auth.Logout)

	// sessionResource is a special auth api resource, with POST and DELETE
	// endpoints used for logging a user in or out.
	sessionResource := r.Group("/api/session")
	{
		sessionResource.POST("", auth.LoginAPI)
		sessionResource.DELETE("", auth.LogoutAPI)
	}

	// admin urls
	adminRoutes := r.Group("/admin", auth.LoginRequired())
	{
		adminRoutes.GET("", admin.Admin)
		adminRoutes.GET("/json", admin.JSONTest)
	}
}
Esempio n. 8
0
func PostNotification(db gorm.DB, router *gin.Engine) {
	// POST /notification
	// POST new notification to database
	router.POST("/notification", func(c *gin.Context) {
		var notificationData model.NotificationData
		if err := c.BindJSON(&notificationData); err == nil {
			notification := &model.Notification{
				NotificationData: notificationData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				notification.Trace.CreatedBy = x_user
				notification.Trace.UpdatedBy = x_user
				if err := checkDataNotification(notification.NotificationData); err {
					if err := db.Create(&notification).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, notification)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
func PostProfileFieldCategory(db gorm.DB, router *gin.Engine) {
	// POST /profile_field_category
	// POST new profile_field_category to database
	router.POST("/profile_field_category", func(c *gin.Context) {
		var profile_field_categoryData model.ProfileFieldCategoryData
		if err := c.BindJSON(&profile_field_categoryData); err == nil {
			profile_field_category := &model.ProfileFieldCategory{
				ProfileFieldCategoryData: profile_field_categoryData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				profile_field_category.Trace.CreatedBy = x_user
				profile_field_category.Trace.UpdatedBy = x_user
				if err := checkDataProfileFieldCategory(profile_field_category.ProfileFieldCategoryData); err {
					if err := db.Create(&profile_field_category).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, profile_field_category)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 10
0
func PostWallEntry(db gorm.DB, router *gin.Engine) {
	// POST /wall_entry
	// POST new wall_entry to database
	router.POST("/wall_entry", func(c *gin.Context) {
		var wall_entryData model.WallEntryData
		if err := c.BindJSON(&wall_entryData); err == nil {
			wall_entry := &model.WallEntry{
				WallEntryData: wall_entryData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				wall_entry.Trace.CreatedBy = x_user
				wall_entry.Trace.UpdatedBy = x_user
				if err := checkDataWallEntry(wall_entry.WallEntryData); err {
					if err := db.Create(&wall_entry).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, wall_entry)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 11
0
func PostPost(db gorm.DB, router *gin.Engine) {
	// POST /post
	// POST new post to database
	router.POST("/post", func(c *gin.Context) {
		var postData model.PostData
		if err := c.BindJSON(&postData); err == nil {
			post := &model.Post{
				PostData: postData,
			}

			var x_user uint64
			if resp := c.Request.Header.Get(userHeader); resp != "" {
				conv_user, _ := strconv.ParseUint(resp, 10, 64)
				x_user = conv_user
				post.Trace.CreatedBy = x_user
				post.Trace.UpdatedBy = x_user
				if err := checkDataPost(post.PostData); err {
					if err := db.Create(&post).Error; err != nil {
						c.AbortWithError(http.StatusBadRequest, err)
					} else {
						c.JSON(http.StatusCreated, post)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			} else {
				c.AbortWithStatus(http.StatusForbidden)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
func (h *UserHandlers) RegisterHandlers(g *gin.Engine) {
	g.GET("/user", h.All)
	g.GET("/user/:id", h.GetUser)
	g.PUT("/user", h.CreateUser)
	g.POST("/user/:id", h.UpdateUser)
	g.DELETE("/user/:id", h.DeleteUser)
	g.POST("/user/:id/password", h.ChangePassword)
}
Esempio n. 13
0
//Setup gin Engine server
func initGin(ginEngine *gin.Engine) {
	ginEngine.Use(logrusLogger())
	ginEngine.POST("/assignment", putAssignment)
	ginEngine.POST("/submission", putSubmission)
	ginEngine.GET("/plugin/langs", getSupportedLangs)
	ginEngine.GET("/debug/vars", expvarGin.Handler())
	ginEngine.GET("/health", healthCheck)
}
func (h *FrontendHandlers) RegisterHandlers(g *gin.Engine) {
	g.GET("/logout", h.Logout)
	g.GET("/login", h.GetLogin)
	g.POST("/login", h.PostLogin)
	g.GET("/register", h.GetRegister)
	g.POST("/register", h.PostRegister)
	g.GET("/", h.Home)
}
Esempio n. 15
0
// Controller for taxonomies resources
func Controller(r *gin.Engine, db *sql.DB) {
	r.GET("/taxonomies", func(c *gin.Context) {
		taxonomies, err := ListAllTaxonomies(db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.Header("Content-Type", "application/json")
		c.String(200, taxonomies)
	})
	r.POST("/taxonomy", func(c *gin.Context) {
		tax := new(Taxonomy)
		err := c.BindJSON(&tax)
		if err != nil {
			c.Error(err)
			return
		}
		err = CreateTaxonomy(tax, db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.String(200, "")
	})
	r.DELETE("/taxonomy/:id", func(c *gin.Context) {
		defer func() {
			if r := recover(); r != nil {
				c.AbortWithError(400, r.(error))
			}
		}()
		id := getID(c)
		err := DeleteTaxonomy(id, db)
		if err != nil {
			panic(err)
		}
		c.String(200, "")
	})
	r.PUT("/taxonomy/:id", func(c *gin.Context) {
		defer func() {
			if r := recover(); r != nil {
				c.AbortWithError(400, r.(error))
			}
		}()
		id := getID(c)

		tax := new(Taxonomy)
		err := c.BindJSON(&tax)
		if err != nil {
			panic(err)
		}
		err = UpdateTaxonomy(id, tax, db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.String(200, "")
	})
}
Esempio n. 16
0
func main() {
	flag.Parse()
	if *logToFile {
		logWriteTo, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Printf("error opening to log file: %v", err)
		}
		if logWriteTo != nil {
			log.SetOutput(logWriteTo)
		}
	}
	gin.SetMode(*ginMode)
	var route *gin.Engine
	if *useGinLogger {
		route = gin.Default()
	} else {
		route = gin.New()
		route.Use(logger)
	}

	route.GET("/", func(ctx *gin.Context) {
		ctx.JSON(200, gin.H{"message": "Its an entry point :)"})
	})

	route.GET("/token", func(ctx *gin.Context) {
		tokenString := auth.GetToken(secretpassword)
		ctx.JSON(200, gin.H{"token": tokenString})
	})
	route.GET("/dbaccessor", func(ctx *gin.Context) {
		ctx.JSON(200, getFakeDbData())
	})
	route.Use(auth.Auth(secretpassword))
	route.POST("/auth", func(ctx *gin.Context) {
		ak := ctx.Request.FormValue("authkey")
		if ak == "" {
			ctx.JSON(401, "No auth key")
		} else if !auth.VerifyAuthKey(ak) {
			ctx.JSON(401, "Wrong key")
		} else {
			ctx.Redirect(http.StatusFound, "/user")
		}
	})
	route.GET("/user", func(ctx *gin.Context) {
		key := ctx.MustGet("authKey")
		udetails := dbAccessor(key.(string))
		ctx.JSON(200, gin.H{"user": udetails})
	})
	route.GET("/user/:id", func(ctx *gin.Context) {
		id := ctx.Params.ByName("id")
		ctx.JSON(200, find(id))
	})

	if err := route.Run(fmt.Sprintf(":%d", *port)); err != nil {
		logFatal("Http not running: ", err)
	} else {
		logPrintln("shutting down")
	}
}
Esempio n. 17
0
func PProf(router *gin.Engine) {
	router.GET("/debug/pprof/", IndexHandler())
	router.GET("/debug/pprof/heap", HeapHandler())
	router.GET("/debug/pprof/goroutine", GoroutineHandler())
	router.GET("/debug/pprof/block", BlockHandler())
	router.GET("/debug/pprof/threadcreate", ThreadCreateHandler())
	router.GET("/debug/pprof/cmdline", CmdlineHandler())
	router.GET("/debug/pprof/profile", ProfileHandler())
	router.GET("/debug/pprof/symbol", SymbolHandler())
	router.POST("/debug/pprof/symbol", SymbolHandler())
}
Esempio n. 18
0
func setupPages(router *gin.Engine, cache *SiteUsersCache) {
	router.GET("/life", GetRenderLifeGamePage)
	router.GET("/form", GetRenderFormPage)
	router.POST("/form_ajax", func(ctx *gin.Context) {
		PostRenderFormPage(ctx, cache)
	})
	router.GET("/calc", GetRenderCalcPage)
	router.POST("/calc_ajax", func(ctx *gin.Context) {
		PostRenderCalcPage(ctx, cache)
	})
}
func Register(engine *gin.Engine) {
	engine.Use(Recovery)
	engine.Use(Errors)

	engine.GET("/events", eventsGet)
	engine.GET("/profile", profileGet)
	engine.POST("/profile", profilePost)
	engine.DELETE("/profile", profileDel)
	engine.GET("/ping", pingGet)
	engine.POST("/stop", stopPost)
	engine.GET("/status", statusGet)
}
Esempio n. 20
0
func InitApi(engine *gin.Engine, db *gorm.DB) *Api {
	a := &Api{}
	a.db = db

	engine.LoadHTMLGlob("templates/*")

	engine.GET("/", a.WUI)
	engine.POST("/sms", a.AddSMS)
	engine.GET("/sms", a.GetSMS)
	engine.GET("/search", a.SearchSMS)
	engine.GET("/export", a.ExportUI)
	engine.GET("/export/do", a.DoExport)

	return a
}
Esempio n. 21
0
func (tr *TemplatesResource) RegisterRoutes(c *gin.Engine) {
	c.GET("/api/templates", tr.Index)
	c.GET("/api/templates/:id", tr.Show)
	c.POST("/api/templates", tr.Create)
	c.POST("/api/templates/:id", tr.Update)
	c.PUT("/api/templates/:id", tr.Update)
	c.DELETE("/api/templates/:id", tr.Delete)
	c.POST("/api/templates/:id/convert", tr.Convert)
	c.POST("/api/convert", tr.ConvertRaw)
}
Esempio n. 22
0
func Register(r *gin.Engine) {

	r.GET("/", func(c *gin.Context) {
		c.String(200, "Y'all ready for this? \n\nOh no! They were ready for that.")
		//c.JSON(200, gin.H{"Pong": "Ping"})
	})

	// User routes

	userApi := new(api.User)
	r.GET("/user", userApi.Get)
	r.POST("/user", userApi.Post)

	// Event routes

	r.GET("/event", api.GetEvent)
	r.POST("/event", api.PostEvent)
}
Esempio n. 23
0
File: mount.go Progetto: itpkg/chaos
//Mount mount routes
func (p *Engine) Mount(r *gin.Engine) {
	ag := r.Group("/admin", p.Jwt.CurrentUserHandler(true), p.Jwt.MustAdminHandler())
	ag.GET("/site/info", p.getAdminSiteInfo)
	ag.POST("/site/info", web.Rest(p.postAdminSiteInfo))
	ag.DELETE("/cache", web.Rest(p.deleteAdminCache))
	ag.GET("/notices", web.Rest(p.getNotices))
	ag.POST("/notices", web.Rest(p.postNotices))
	ag.DELETE("/notices/:id", web.Rest(p.deleteNotice))

	r.GET("/notices", p.Cache.Page(time.Hour*24, web.Rest(p.getNotices)))

	r.GET("/personal/self", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalSelf))
	r.GET("/personal/logs", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalLogs))
	r.DELETE("/personal/signOut", p.Jwt.CurrentUserHandler(true), p.deleteSignOut)

	r.GET("/locales/:lang", p.Cache.Page(time.Hour*24, p.getLocale))
	r.GET("/site/info", p.Cache.Page(time.Hour*24, p.getSiteInfo))

	r.POST("/oauth2/callback", web.Rest(p.postOauth2Callback))
}
Esempio n. 24
0
func defineRouting(router *gin.Engine) {
	router.POST("/answer/new", CreateAnswer)
	router.POST("/question/new", CreateQuestion)
	router.POST("/survey/new", CreateSurvey)
	router.POST("/person/new", CreatePerson)
	router.GET("/survey/:id", GetSurvey)
}
Esempio n. 25
0
func registerRoutes(e *gin.Engine) {
	controller := rc.ResourceController{}
	controller.DatabaseProvider = Database

	resourceNames := []string{"RecordMatchContext",
		"RecordMatchSystemInterface", "RecordSet"}

	for _, name := range resourceNames {
		e.GET("/"+name+"/:id", controller.GetResource)
		e.POST("/"+name, controller.CreateResource)
		e.PUT("/"+name+"/:id", controller.UpdateResource)
		e.DELETE("/"+name+"/:id", controller.DeleteResource)
		e.GET("/"+name, controller.GetResources)
	}

	e.POST("/AnswerKey", controller.SetAnswerKey)

	name := "RecordMatchRun"
	e.GET("/"+name, controller.GetResources)
	e.GET("/"+name+"/:id", controller.GetResource)
	e.POST("/"+name, rc.CreateRecordMatchRunHandler(Database))
	e.PUT("/"+name+"/:id", controller.UpdateResource)
	e.DELETE("/"+name+"/:id", controller.DeleteResource)

	e.GET("/RecordMatchRunMetrics", rc.GetRecordMatchRunMetricsHandler(Database))
	e.GET("/RecordMatchRunLinks/:id", rc.GetRecordMatchRunLinksHandler(Database))

	e.Static("/ptmatch/api/", "api")
}
Esempio n. 26
0
func PostUserHttpSession(db gorm.DB, router *gin.Engine) {
	// POST /user_http_session
	// POST new user_http_session to database
	router.POST("/user_http_session", func(c *gin.Context) {
		var user_http_sessionData model.UserHttpSessionData
		if err := c.BindJSON(&user_http_sessionData); err == nil {
			user_http_session := &model.UserHttpSession{
				UserHttpSessionData: user_http_sessionData,
			}

			if err := db.Create(&user_http_session).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, err)
			} else {
				c.JSON(http.StatusOK, user_http_session)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 27
0
func PostMigration(db gorm.DB, router *gin.Engine) {
	// POST /migration
	// POST new migration to database
	router.POST("/migration", func(c *gin.Context) {
		var migrationData model.MigrationData
		if err := c.BindJSON(&migrationData); err == nil {
			migration := &model.Migration{
				MigrationData: migrationData,
			}

			if err := db.Create(&migration).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, err)
			} else {
				c.JSON(http.StatusOK, migration)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 28
0
func newSession(engine *gin.Engine, conf AuthConf, store sessions.CookieStore) {
	engine.Use(sessions.Sessions(conf.Session.CookieKey, store))

	options := sessions.Options{
		Path:     "/",
		MaxAge:   conf.Session.MaxAge,
		HttpOnly: true,
	}
	store.Options(options)

	authConf = conf

	gob.Register(conf.LoginUser)

	engine.POST(conf.Login.url, conf.Login.handle)
	engine.POST(conf.Logout.url, conf.Logout.handle)
	engine.GET(conf.LoginSuccess.url, conf.LoginSuccess.handle)
	engine.GET(conf.LoginFailed.url, conf.LoginFailed.handle)
	engine.GET(conf.UnAuthenticated.url, conf.UnAuthenticated.handle)
	engine.GET(conf.IsAuthenticated.url, conf.IsAuthenticated.handle)

}
Esempio n. 29
0
func PostLogging(db gorm.DB, router *gin.Engine) {
	// POST /logging
	// POST new logging to database
	router.POST("/logging", func(c *gin.Context) {
		var loggingData model.LoggingData
		if err := c.BindJSON(&loggingData); err == nil {
			logging := &model.Logging{
				LoggingData: loggingData,
			}

			if err := db.Create(&logging).Error; err != nil {
				c.AbortWithError(http.StatusBadRequest, err)
			} else {
				c.JSON(http.StatusOK, logging)
			}

		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Esempio n. 30
0
File: users.go Progetto: vmalguy/tat
// InitRoutesUsers initialized routes for Users Controller
func InitRoutesUsers(router *gin.Engine) {
	usersCtrl := &controllers.UsersController{}

	gs := router.Group("/users")
	gs.Use(CheckPassword())
	{
		gs.GET("", usersCtrl.List)
	}
	g := router.Group("/user")
	g.Use(CheckPassword())
	{
		g.GET("/me", usersCtrl.Me)
		g.GET("/me/contacts/:sinceSeconds", usersCtrl.Contacts)
		g.POST("/me/contacts/:username", usersCtrl.AddContact)
		g.DELETE("/me/contacts/:username", usersCtrl.RemoveContact)
		g.POST("/me/topics/*topic", usersCtrl.AddFavoriteTopic)
		g.DELETE("/me/topics/*topic", usersCtrl.RemoveFavoriteTopic)
		g.POST("/me/tags/:tag", usersCtrl.AddFavoriteTag)
		g.DELETE("/me/tags/:tag", usersCtrl.RemoveFavoriteTag)

		g.POST("/me/enable/notifications/topics/*topic", usersCtrl.EnableNotificationsTopic)
		g.POST("/me/disable/notifications/topics/*topic", usersCtrl.DisableNotificationsTopic)
	}

	admin := router.Group("/user")
	admin.Use(CheckPassword(), CheckAdmin())
	{
		admin.PUT("/convert", usersCtrl.Convert)
		admin.PUT("/archive", usersCtrl.Archive)
		admin.PUT("/rename", usersCtrl.Rename)
		admin.PUT("/update", usersCtrl.Update)
		admin.PUT("/setadmin", usersCtrl.SetAdmin)
		admin.PUT("/resetsystem", usersCtrl.ResetSystemUser)
	}

	router.GET("/user/verify/:username/:tokenVerify", usersCtrl.Verify)
	router.POST("/user/reset", usersCtrl.Reset)
	router.POST("/user", usersCtrl.Create)
}