// ShowAdminPage either shows the login page or the admin panel, depending // on whether the user is logged in and has access to the group func (gc AdminController) ShowAdminPage(c *gin.Context) { gname := c.Param("gname") if auth.IsLoggedIn(c) && auth.HasAccessToGroup(auth.GetUserIDFromCookie(c), gname, gc.db) { // user has admin access http.ServeFile(c.Writer, c.Request, "views/admin_panel.html") } else { // show login page http.ServeFile(c.Writer, c.Request, "views/admin_login.html") } }
// UseAuth rejects unauthorized api requests func UseAuth(c *gin.Context) { if !auth.IsLoggedIn(c) { c.JSON(http.StatusUnauthorized, resp.APIResponse{IsError: false, Message: "User is not logged in"}) c.Abort() } }