Fix accept cookie button and reestyle the reply button
parent
13b0821eef
commit
6e6eba2ca1
|
|
@ -1,46 +1,46 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"github.com/gorilla/sessions"
|
||||||
"log"
|
"html/template"
|
||||||
"net/http"
|
"io/ioutil"
|
||||||
"github.com/gorilla/sessions"
|
"log"
|
||||||
"html/template"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AboutHandler(app *App) http.HandlerFunc {
|
func AboutHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
loggedIn := session.Values["user_id"] != nil
|
loggedIn := session.Values["user_id"] != nil
|
||||||
cookie, _ := r.Cookie("threadr_cookie_banner")
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
||||||
|
|
||||||
aboutContent, err := ioutil.ReadFile("config/about_page.htmlbody")
|
aboutContent, err := ioutil.ReadFile("config/about_page.htmlbody")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading about_page.htmlbody: %v", err)
|
log.Printf("Error reading about_page.htmlbody: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
AboutContent template.HTML
|
AboutContent template.HTML
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - About",
|
Title: "ThreadR - About",
|
||||||
Navbar: "about",
|
Navbar: "about",
|
||||||
LoggedIn: loggedIn,
|
LoggedIn: loggedIn,
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
AboutContent: template.HTML(aboutContent),
|
AboutContent: template.HTML(aboutContent),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "about", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "about", data); err != nil {
|
||||||
log.Printf("Error executing template in AboutHandler: %v", err)
|
log.Printf("Error executing template in AboutHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,131 +1,131 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"strconv"
|
"net/http"
|
||||||
"threadr/models"
|
"strconv"
|
||||||
"github.com/gorilla/sessions"
|
"threadr/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BoardHandler(app *App) http.HandlerFunc {
|
func BoardHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
loggedIn := session.Values["user_id"] != nil
|
loggedIn := session.Values["user_id"] != nil
|
||||||
userID, _ := session.Values["user_id"].(int)
|
userID, _ := session.Values["user_id"].(int)
|
||||||
cookie, _ := r.Cookie("threadr_cookie_banner")
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
||||||
|
|
||||||
boardIDStr := r.URL.Query().Get("id")
|
boardIDStr := r.URL.Query().Get("id")
|
||||||
boardID, err := strconv.Atoi(boardIDStr)
|
boardID, err := strconv.Atoi(boardIDStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Invalid board ID", http.StatusBadRequest)
|
http.Error(w, "Invalid board ID", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
board, err := models.GetBoardByID(app.DB, boardID)
|
board, err := models.GetBoardByID(app.DB, boardID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching board: %v", err)
|
log.Printf("Error fetching board: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if board == nil {
|
if board == nil {
|
||||||
http.Error(w, "Board not found", http.StatusNotFound)
|
http.Error(w, "Board not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if board.Type == "chat" {
|
if board.Type == "chat" {
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/chat/?id="+boardIDStr, http.StatusFound)
|
http.Redirect(w, r, app.Config.ThreadrDir+"/chat/?id="+boardIDStr, http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if board.Private {
|
if board.Private {
|
||||||
if !loggedIn {
|
if !loggedIn {
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hasPerm, err := models.HasBoardPermission(app.DB, userID, boardID, models.PermViewBoard)
|
hasPerm, err := models.HasBoardPermission(app.DB, userID, boardID, models.PermViewBoard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error checking permission: %v", err)
|
log.Printf("Error checking permission: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !hasPerm {
|
if !hasPerm {
|
||||||
http.Error(w, "You do not have permission to view this board", http.StatusForbidden)
|
http.Error(w, "You do not have permission to view this board", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method == http.MethodPost && loggedIn {
|
if r.Method == http.MethodPost && loggedIn {
|
||||||
action := r.URL.Query().Get("action")
|
action := r.URL.Query().Get("action")
|
||||||
if action == "create_thread" {
|
if action == "create_thread" {
|
||||||
title := r.FormValue("title")
|
title := r.FormValue("title")
|
||||||
if title == "" {
|
if title == "" {
|
||||||
http.Error(w, "Thread title is required", http.StatusBadRequest)
|
http.Error(w, "Thread title is required", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if board.Private {
|
if board.Private {
|
||||||
hasPerm, err := models.HasBoardPermission(app.DB, userID, boardID, models.PermPostInBoard)
|
hasPerm, err := models.HasBoardPermission(app.DB, userID, boardID, models.PermPostInBoard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error checking permission: %v", err)
|
log.Printf("Error checking permission: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !hasPerm {
|
if !hasPerm {
|
||||||
http.Error(w, "You do not have permission to post in this board", http.StatusForbidden)
|
http.Error(w, "You do not have permission to post in this board", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread := models.Thread{
|
thread := models.Thread{
|
||||||
BoardID: boardID,
|
BoardID: boardID,
|
||||||
Title: title,
|
Title: title,
|
||||||
CreatedByUserID: userID,
|
CreatedByUserID: userID,
|
||||||
}
|
}
|
||||||
err = models.CreateThread(app.DB, thread)
|
err = models.CreateThread(app.DB, thread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error creating thread: %v", err)
|
log.Printf("Error creating thread: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var threadID int
|
var threadID int
|
||||||
err = app.DB.QueryRow("SELECT LAST_INSERT_ID()").Scan(&threadID)
|
err = app.DB.QueryRow("SELECT LAST_INSERT_ID()").Scan(&threadID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error getting last insert id: %v", err)
|
log.Printf("Error getting last insert id: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/thread/?id="+strconv.Itoa(threadID), http.StatusFound)
|
http.Redirect(w, r, app.Config.ThreadrDir+"/thread/?id="+strconv.Itoa(threadID), http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
threads, err := models.GetThreadsByBoardID(app.DB, boardID)
|
threads, err := models.GetThreadsByBoardID(app.DB, boardID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching threads: %v", err)
|
log.Printf("Error fetching threads: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
Board models.Board
|
Board models.Board
|
||||||
Threads []models.Thread
|
Threads []models.Thread
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - " + board.Name,
|
Title: "ThreadR - " + board.Name,
|
||||||
Navbar: "boards",
|
Navbar: "boards",
|
||||||
LoggedIn: loggedIn,
|
LoggedIn: loggedIn,
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Board: *board,
|
Board: *board,
|
||||||
Threads: threads,
|
Threads: threads,
|
||||||
}
|
}
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "board", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "board", data); err != nil {
|
||||||
log.Printf("Error executing template in BoardHandler: %v", err)
|
log.Printf("Error executing template in BoardHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,120 +1,120 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"strconv"
|
"net/http"
|
||||||
"threadr/models"
|
"strconv"
|
||||||
"github.com/gorilla/sessions"
|
"threadr/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BoardsHandler(app *App) http.HandlerFunc {
|
func BoardsHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
loggedIn := session.Values["user_id"] != nil
|
loggedIn := session.Values["user_id"] != nil
|
||||||
cookie, _ := r.Cookie("threadr_cookie_banner")
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
||||||
userID, _ := session.Values["user_id"].(int)
|
userID, _ := session.Values["user_id"].(int)
|
||||||
isAdmin := false
|
isAdmin := false
|
||||||
|
|
||||||
if loggedIn {
|
|
||||||
user, err := models.GetUserByID(app.DB, userID)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error fetching user: %v", err)
|
|
||||||
} else if user != nil {
|
|
||||||
isAdmin = models.HasGlobalPermission(user, models.PermCreateBoard)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Method == http.MethodPost && loggedIn && isAdmin {
|
if loggedIn {
|
||||||
name := r.FormValue("name")
|
user, err := models.GetUserByID(app.DB, userID)
|
||||||
description := r.FormValue("description")
|
if err != nil {
|
||||||
boardType := r.FormValue("type")
|
log.Printf("Error fetching user: %v", err)
|
||||||
|
} else if user != nil {
|
||||||
|
isAdmin = models.HasGlobalPermission(user, models.PermCreateBoard)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if name == "" {
|
if r.Method == http.MethodPost && loggedIn && isAdmin {
|
||||||
http.Error(w, "Board name is required", http.StatusBadRequest)
|
name := r.FormValue("name")
|
||||||
return
|
description := r.FormValue("description")
|
||||||
}
|
boardType := r.FormValue("type")
|
||||||
if boardType != "classic" && boardType != "chat" {
|
|
||||||
boardType = "classic"
|
|
||||||
}
|
|
||||||
|
|
||||||
board := models.Board{
|
if name == "" {
|
||||||
Name: name,
|
http.Error(w, "Board name is required", http.StatusBadRequest)
|
||||||
Description: description,
|
return
|
||||||
Private: false,
|
}
|
||||||
PublicVisible: true,
|
if boardType != "classic" && boardType != "chat" {
|
||||||
Type: boardType,
|
boardType = "classic"
|
||||||
}
|
}
|
||||||
query := "INSERT INTO boards (name, description, private, public_visible, type) VALUES (?, ?, ?, ?, ?)"
|
|
||||||
result, err := app.DB.Exec(query, board.Name, board.Description, board.Private, board.PublicVisible, board.Type)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error creating board: %v", err)
|
|
||||||
http.Error(w, "Failed to create board", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
boardID, _ := result.LastInsertId()
|
|
||||||
|
|
||||||
var redirectURL string
|
|
||||||
if boardType == "chat" {
|
|
||||||
redirectURL = app.Config.ThreadrDir + "/chat/?id=" + strconv.FormatInt(boardID, 10)
|
|
||||||
} else {
|
|
||||||
redirectURL = app.Config.ThreadrDir + "/board/?id=" + strconv.FormatInt(boardID, 10)
|
|
||||||
}
|
|
||||||
http.Redirect(w, r, redirectURL, http.StatusFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
publicBoards, err := models.GetAllBoards(app.DB, false)
|
board := models.Board{
|
||||||
if err != nil {
|
Name: name,
|
||||||
log.Printf("Error fetching public boards: %v", err)
|
Description: description,
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
Private: false,
|
||||||
return
|
PublicVisible: true,
|
||||||
}
|
Type: boardType,
|
||||||
var privateBoards []models.Board
|
}
|
||||||
if loggedIn {
|
query := "INSERT INTO boards (name, description, private, public_visible, type) VALUES (?, ?, ?, ?, ?)"
|
||||||
privateBoards, err = models.GetAllBoards(app.DB, true)
|
result, err := app.DB.Exec(query, board.Name, board.Description, board.Private, board.PublicVisible, board.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching private boards: %v", err)
|
log.Printf("Error creating board: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Failed to create board", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var accessiblePrivateBoards []models.Board
|
boardID, _ := result.LastInsertId()
|
||||||
for _, board := range privateBoards {
|
|
||||||
hasPerm, err := models.HasBoardPermission(app.DB, userID, board.ID, models.PermViewBoard)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error checking permission: %v", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if hasPerm {
|
|
||||||
accessiblePrivateBoards = append(accessiblePrivateBoards, board)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
privateBoards = accessiblePrivateBoards
|
|
||||||
}
|
|
||||||
|
|
||||||
data := struct {
|
var redirectURL string
|
||||||
PageData
|
if boardType == "chat" {
|
||||||
PublicBoards []models.Board
|
redirectURL = app.Config.ThreadrDir + "/chat/?id=" + strconv.FormatInt(boardID, 10)
|
||||||
PrivateBoards []models.Board
|
} else {
|
||||||
IsAdmin bool
|
redirectURL = app.Config.ThreadrDir + "/board/?id=" + strconv.FormatInt(boardID, 10)
|
||||||
}{
|
}
|
||||||
PageData: PageData{
|
http.Redirect(w, r, redirectURL, http.StatusFound)
|
||||||
Title: "ThreadR - Boards",
|
return
|
||||||
Navbar: "boards",
|
}
|
||||||
LoggedIn: loggedIn,
|
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
publicBoards, err := models.GetAllBoards(app.DB, false)
|
||||||
BasePath: app.Config.ThreadrDir,
|
if err != nil {
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
log.Printf("Error fetching public boards: %v", err)
|
||||||
CurrentURL: r.URL.Path,
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
},
|
return
|
||||||
PublicBoards: publicBoards,
|
}
|
||||||
PrivateBoards: privateBoards,
|
var privateBoards []models.Board
|
||||||
IsAdmin: isAdmin,
|
if loggedIn {
|
||||||
}
|
privateBoards, err = models.GetAllBoards(app.DB, true)
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "boards", data); err != nil {
|
if err != nil {
|
||||||
log.Printf("Error executing template in BoardsHandler: %v", err)
|
log.Printf("Error fetching private boards: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
var accessiblePrivateBoards []models.Board
|
||||||
}
|
for _, board := range privateBoards {
|
||||||
|
hasPerm, err := models.HasBoardPermission(app.DB, userID, board.ID, models.PermViewBoard)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error checking permission: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if hasPerm {
|
||||||
|
accessiblePrivateBoards = append(accessiblePrivateBoards, board)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
privateBoards = accessiblePrivateBoards
|
||||||
|
}
|
||||||
|
|
||||||
|
data := struct {
|
||||||
|
PageData
|
||||||
|
PublicBoards []models.Board
|
||||||
|
PrivateBoards []models.Board
|
||||||
|
IsAdmin bool
|
||||||
|
}{
|
||||||
|
PageData: PageData{
|
||||||
|
Title: "ThreadR - Boards",
|
||||||
|
Navbar: "boards",
|
||||||
|
LoggedIn: loggedIn,
|
||||||
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
|
BasePath: app.Config.ThreadrDir,
|
||||||
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
|
CurrentURL: r.URL.RequestURI(),
|
||||||
|
},
|
||||||
|
PublicBoards: publicBoards,
|
||||||
|
PrivateBoards: privateBoards,
|
||||||
|
IsAdmin: isAdmin,
|
||||||
|
}
|
||||||
|
if err := app.Tmpl.ExecuteTemplate(w, "boards", data); err != nil {
|
||||||
|
log.Printf("Error executing template in BoardsHandler: %v", err)
|
||||||
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ func ChatHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
ContentTemplate: "chat-content",
|
ContentTemplate: "chat-content",
|
||||||
BodyClass: "chat-page",
|
BodyClass: "chat-page",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,34 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"path/filepath"
|
"net/http"
|
||||||
"github.com/gorilla/sessions"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HomeHandler(app *App) http.HandlerFunc {
|
func HomeHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
loggedIn := session.Values["user_id"] != nil
|
loggedIn := session.Values["user_id"] != nil
|
||||||
cookie, _ := r.Cookie("threadr_cookie_banner")
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - Home",
|
Title: "ThreadR - Home",
|
||||||
Navbar: "home",
|
Navbar: "home",
|
||||||
LoggedIn: loggedIn,
|
LoggedIn: loggedIn,
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: filepath.Join(app.Config.ThreadrDir, "static"),
|
StaticPath: filepath.Join(app.Config.ThreadrDir, "static"),
|
||||||
CurrentURL: r.URL.String(),
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "home", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "home", data); err != nil {
|
||||||
log.Printf("Error executing template in HomeHandler: %v", err)
|
log.Printf("Error executing template in HomeHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func LoginHandler(app *App) http.HandlerFunc {
|
||||||
LoggedIn: false,
|
LoggedIn: false,
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
178
handlers/news.go
178
handlers/news.go
|
|
@ -1,98 +1,98 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"strconv"
|
"net/http"
|
||||||
"threadr/models"
|
"strconv"
|
||||||
"github.com/gorilla/sessions"
|
"threadr/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewsHandler(app *App) http.HandlerFunc {
|
func NewsHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
loggedIn := session.Values["user_id"] != nil
|
loggedIn := session.Values["user_id"] != nil
|
||||||
cookie, _ := r.Cookie("threadr_cookie_banner")
|
cookie, _ := r.Cookie("threadr_cookie_banner")
|
||||||
userID, _ := session.Values["user_id"].(int)
|
userID, _ := session.Values["user_id"].(int)
|
||||||
isAdmin := false
|
isAdmin := false
|
||||||
|
|
||||||
if loggedIn {
|
|
||||||
user, err := models.GetUserByID(app.DB, userID)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error fetching user: %v", err)
|
|
||||||
} else if user != nil {
|
|
||||||
isAdmin = models.HasGlobalPermission(user, models.PermManageUsers)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Method == http.MethodPost && loggedIn && isAdmin {
|
if loggedIn {
|
||||||
if action := r.URL.Query().Get("action"); action == "delete" {
|
user, err := models.GetUserByID(app.DB, userID)
|
||||||
newsIDStr := r.URL.Query().Get("id")
|
if err != nil {
|
||||||
newsID, err := strconv.Atoi(newsIDStr)
|
log.Printf("Error fetching user: %v", err)
|
||||||
if err != nil {
|
} else if user != nil {
|
||||||
http.Error(w, "Invalid news ID", http.StatusBadRequest)
|
isAdmin = models.HasGlobalPermission(user, models.PermManageUsers)
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
err = models.DeleteNews(app.DB, newsID)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error deleting news item: %v", err)
|
|
||||||
http.Error(w, "Failed to delete news item", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/news/", http.StatusFound)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
title := r.FormValue("title")
|
|
||||||
content := r.FormValue("content")
|
|
||||||
if title != "" && content != "" {
|
|
||||||
news := models.News{
|
|
||||||
Title: title,
|
|
||||||
Content: content,
|
|
||||||
PostedBy: userID,
|
|
||||||
}
|
|
||||||
err := models.CreateNews(app.DB, news)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error creating news item: %v", err)
|
|
||||||
http.Error(w, "Failed to create news item", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/news/", http.StatusFound)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
http.Error(w, "Title and content are required", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newsItems, err := models.GetAllNews(app.DB)
|
if r.Method == http.MethodPost && loggedIn && isAdmin {
|
||||||
if err != nil {
|
if action := r.URL.Query().Get("action"); action == "delete" {
|
||||||
log.Printf("Error fetching news items: %v", err)
|
newsIDStr := r.URL.Query().Get("id")
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
newsID, err := strconv.Atoi(newsIDStr)
|
||||||
return
|
if err != nil {
|
||||||
}
|
http.Error(w, "Invalid news ID", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = models.DeleteNews(app.DB, newsID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error deleting news item: %v", err)
|
||||||
|
http.Error(w, "Failed to delete news item", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, app.Config.ThreadrDir+"/news/", http.StatusFound)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
title := r.FormValue("title")
|
||||||
|
content := r.FormValue("content")
|
||||||
|
if title != "" && content != "" {
|
||||||
|
news := models.News{
|
||||||
|
Title: title,
|
||||||
|
Content: content,
|
||||||
|
PostedBy: userID,
|
||||||
|
}
|
||||||
|
err := models.CreateNews(app.DB, news)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error creating news item: %v", err)
|
||||||
|
http.Error(w, "Failed to create news item", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, app.Config.ThreadrDir+"/news/", http.StatusFound)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
http.Error(w, "Title and content are required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data := struct {
|
newsItems, err := models.GetAllNews(app.DB)
|
||||||
PageData
|
if err != nil {
|
||||||
News []models.News
|
log.Printf("Error fetching news items: %v", err)
|
||||||
IsAdmin bool
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
}{
|
return
|
||||||
PageData: PageData{
|
}
|
||||||
Title: "ThreadR - News",
|
|
||||||
Navbar: "news",
|
data := struct {
|
||||||
LoggedIn: loggedIn,
|
PageData
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
News []models.News
|
||||||
BasePath: app.Config.ThreadrDir,
|
IsAdmin bool
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
}{
|
||||||
CurrentURL: r.URL.Path,
|
PageData: PageData{
|
||||||
},
|
Title: "ThreadR - News",
|
||||||
News: newsItems,
|
Navbar: "news",
|
||||||
IsAdmin: isAdmin,
|
LoggedIn: loggedIn,
|
||||||
}
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "news", data); err != nil {
|
BasePath: app.Config.ThreadrDir,
|
||||||
log.Printf("Error executing template in NewsHandler: %v", err)
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
CurrentURL: r.URL.RequestURI(),
|
||||||
return
|
},
|
||||||
}
|
News: newsItems,
|
||||||
}
|
IsAdmin: isAdmin,
|
||||||
}
|
}
|
||||||
|
if err := app.Tmpl.ExecuteTemplate(w, "news", data); err != nil {
|
||||||
|
log.Printf("Error executing template in NewsHandler: %v", err)
|
||||||
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func PreferencesHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: false,
|
ShowCookieBanner: false,
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
ContentTemplate: "preferences-content",
|
ContentTemplate: "preferences-content",
|
||||||
},
|
},
|
||||||
Preferences: prefs,
|
Preferences: prefs,
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,55 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"threadr/models"
|
"net/http"
|
||||||
"github.com/gorilla/sessions"
|
"threadr/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProfileHandler(app *App) http.HandlerFunc {
|
func ProfileHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
userID, ok := session.Values["user_id"].(int)
|
userID, ok := session.Values["user_id"].(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := models.GetUserByID(app.DB, userID)
|
user, err := models.GetUserByID(app.DB, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching user in ProfileHandler: %v", err)
|
log.Printf("Error fetching user in ProfileHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
http.Error(w, "User not found", http.StatusNotFound)
|
http.Error(w, "User not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
displayName := user.DisplayName
|
displayName := user.DisplayName
|
||||||
if displayName == "" {
|
if displayName == "" {
|
||||||
displayName = user.Username
|
displayName = user.Username
|
||||||
}
|
}
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
User models.User
|
User models.User
|
||||||
DisplayName string
|
DisplayName string
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - Profile",
|
Title: "ThreadR - Profile",
|
||||||
Navbar: "profile",
|
Navbar: "profile",
|
||||||
LoggedIn: true,
|
LoggedIn: true,
|
||||||
ShowCookieBanner: false,
|
ShowCookieBanner: false,
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
User: *user,
|
User: *user,
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
}
|
}
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "profile", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "profile", data); err != nil {
|
||||||
log.Printf("Error executing template in ProfileHandler: %v", err)
|
log.Printf("Error executing template in ProfileHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ func ProfileEditHandler(app *App) http.HandlerFunc {
|
||||||
|
|
||||||
// Create file record in the database
|
// Create file record in the database
|
||||||
fileRecord := models.File{
|
fileRecord := models.File{
|
||||||
OriginalName: handler.Filename,
|
OriginalName: handler.Filename,
|
||||||
Hash: fileHash,
|
Hash: fileHash,
|
||||||
HashAlgorithm: "sha256",
|
HashAlgorithm: "sha256",
|
||||||
}
|
}
|
||||||
fileID, err := models.CreateFile(app.DB, fileRecord)
|
fileID, err := models.CreateFile(app.DB, fileRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -95,36 +95,36 @@ func ProfileEditHandler(app *App) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := models.GetUserByID(app.DB, userID)
|
user, err := models.GetUserByID(app.DB, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching user: %v", err)
|
log.Printf("Error fetching user: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
http.Error(w, "User not found", http.StatusNotFound)
|
http.Error(w, "User not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
User models.User
|
User models.User
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - Edit Profile",
|
Title: "ThreadR - Edit Profile",
|
||||||
Navbar: "profile",
|
Navbar: "profile",
|
||||||
LoggedIn: true,
|
LoggedIn: true,
|
||||||
ShowCookieBanner: false,
|
ShowCookieBanner: false,
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
User: *user,
|
User: *user,
|
||||||
}
|
}
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "profile_edit", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "profile_edit", data); err != nil {
|
||||||
log.Printf("Error executing template in ProfileEditHandler: %v", err)
|
log.Printf("Error executing template in ProfileEditHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func SignupHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Error: "Passwords do not match. Please try again.",
|
Error: "Passwords do not match. Please try again.",
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ func SignupHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Error: "An error occurred during sign up. Please try again.",
|
Error: "An error occurred during sign up. Please try again.",
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ func SignupHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Error: "",
|
Error: "",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ func ThreadHandler(app *App) http.HandlerFunc {
|
||||||
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
ShowCookieBanner: cookie == nil || cookie.Value != "accepted",
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Thread: *thread,
|
Thread: *thread,
|
||||||
Board: *board,
|
Board: *board,
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,49 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"github.com/gorilla/sessions"
|
||||||
"net/http"
|
"log"
|
||||||
"threadr/models"
|
"net/http"
|
||||||
"github.com/gorilla/sessions"
|
"threadr/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserHomeHandler(app *App) http.HandlerFunc {
|
func UserHomeHandler(app *App) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session := r.Context().Value("session").(*sessions.Session)
|
session := r.Context().Value("session").(*sessions.Session)
|
||||||
userID, ok := session.Values["user_id"].(int)
|
userID, ok := session.Values["user_id"].(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
http.Redirect(w, r, app.Config.ThreadrDir+"/login/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := models.GetUserByID(app.DB, userID)
|
user, err := models.GetUserByID(app.DB, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error fetching user in UserHomeHandler: %v", err)
|
log.Printf("Error fetching user in UserHomeHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
http.Error(w, "User not found", http.StatusNotFound)
|
http.Error(w, "User not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := struct {
|
data := struct {
|
||||||
PageData
|
PageData
|
||||||
Username string
|
Username string
|
||||||
}{
|
}{
|
||||||
PageData: PageData{
|
PageData: PageData{
|
||||||
Title: "ThreadR - User Home",
|
Title: "ThreadR - User Home",
|
||||||
Navbar: "userhome",
|
Navbar: "userhome",
|
||||||
LoggedIn: true,
|
LoggedIn: true,
|
||||||
ShowCookieBanner: false,
|
ShowCookieBanner: false,
|
||||||
BasePath: app.Config.ThreadrDir,
|
BasePath: app.Config.ThreadrDir,
|
||||||
StaticPath: app.Config.ThreadrDir + "/static",
|
StaticPath: app.Config.ThreadrDir + "/static",
|
||||||
CurrentURL: r.URL.Path,
|
CurrentURL: r.URL.RequestURI(),
|
||||||
},
|
},
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
}
|
}
|
||||||
if err := app.Tmpl.ExecuteTemplate(w, "userhome", data); err != nil {
|
if err := app.Tmpl.ExecuteTemplate(w, "userhome", data); err != nil {
|
||||||
log.Printf("Error executing template in UserHomeHandler: %v", err)
|
log.Printf("Error executing template in UserHomeHandler: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -551,6 +551,26 @@ p.thread-info {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chat-message .post-actions {
|
||||||
|
position: absolute;
|
||||||
|
top: -12px;
|
||||||
|
right: 0;
|
||||||
|
margin: 0;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
background-color: #fef6e4;
|
||||||
|
border: 1px solid #001858;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 2px 4px;
|
||||||
|
z-index: 10;
|
||||||
|
transition: opacity 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-message:hover .post-actions {
|
||||||
|
opacity: 1;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.chat-message-header {
|
.chat-message-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
@ -622,20 +642,16 @@ p.thread-info {
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-message:hover .post-actions {
|
.chat-message .post-actions a {
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-actions a {
|
|
||||||
color: #001858;
|
color: #001858;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
border: 1px solid #001858;
|
border: none;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-actions a:hover {
|
.chat-message .post-actions a:hover {
|
||||||
background-color: #8bd3dd;
|
background-color: #8bd3dd;
|
||||||
color: #fef6e4;
|
color: #fef6e4;
|
||||||
}
|
}
|
||||||
|
|
@ -851,12 +867,16 @@ p.thread-info {
|
||||||
background-color: #555;
|
background-color: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-actions a {
|
.chat-message .post-actions {
|
||||||
color: #fef6e4;
|
background-color: #444;
|
||||||
border-color: #fef6e4;
|
border-color: #fef6e4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-actions a:hover {
|
.chat-message .post-actions a {
|
||||||
|
color: #fef6e4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-message .post-actions a:hover {
|
||||||
background-color: #8bd3dd;
|
background-color: #8bd3dd;
|
||||||
color: #001858;
|
color: #001858;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue