diff --git a/README.md b/README.md index 074e476..f1a9abf 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,23 @@ This is a Web Application written in Golang, utilizing only standard [Go librari - [How to use Docker](docs/howToUsewDocker.md) ### User Management: -- User Registration: Users can create new accounts. -- Guest Registration: Allow guest users to access limited features or explore the platform without registration. -- Login System: Users can log in using their email and password credentials. +- **User Registration:** Users can create new accounts. +- **Guest Registration:** Allows guest users to access limited features or explore the platform without registration. +- **Login System:** Users can log in using their email and password credentials. +- The registered user can have types: user, moderator. +- To change the user type, registered users should use a Special Code in their personal cabinet. +#### User Types +- **Moderator:** Has special rights, including the ability to see all messages and change the classification for messages. ### Content Creation: -- Topic Creation: Users can create new discussion topics. - - Topic Creation with Image: Option to include images when creating topics. -- Post Creation: Users can contribute to discussions by creating posts. - - Post Creation with Image: Ability to attach images to posts. +- **Topic Creation:** Users can create new discussion topics. + - **Topic Creation with Image:** Option to include images when creating topics. +- **Post Creation:** Users can contribute to discussions by creating posts. + - **Post Creation with Image:** Ability to attach images to posts. +- Forum messages have classifications: unsorted, obscene, illegal, insulting, approved. +- Users without moderator rights can create unsorted messages. +- Users without moderator rights can see all their own messages and approved messages from other users. + ### Interaction Features: - Like/Dislike System: Users can like or dislike posts. diff --git a/internal/handler/moderPanelHanlder.go b/internal/handler/moderPanelHanlder.go index befc4e6..52f1110 100644 --- a/internal/handler/moderPanelHanlder.go +++ b/internal/handler/moderPanelHanlder.go @@ -39,22 +39,45 @@ func handlePostRequestModerPage(w http.ResponseWriter, r *http.Request, m *Repos } selectedCategory := r.FormValue("btnradio") - topicID, err := strconv.Atoi(r.FormValue("topicID")) - if err != nil { - setErrorAndRedirect(w, r, "Could not convert string into int "+err.Error(), "/error-page") - return - } - topic, err := m.DB.GetThreadByID(topicID) - if err != nil { - setErrorAndRedirect(w, r, "Could not get topic by id "+err.Error(), "/error-page") - return + + if r.FormValue("postID") != "" { + postID, err := strconv.Atoi(r.FormValue("postID")) + if err != nil { + setErrorAndRedirect(w, r, "Could not convert string into int "+err.Error(), "/error-page") + return + } + post, err := m.DB.GetPostByID(postID) + if err != nil { + setErrorAndRedirect(w, r, "Could not get post by id "+err.Error(), "/error-page") + return + } + cat := models.TextClassification(selectedCategory) + + err = m.DB.EditPostClassification(post, cat) + if err != nil { + setErrorAndRedirect(w, r, "Could not edit post classification "+err.Error(), "/error-page") + return + } } - cat := models.TextClassification(selectedCategory) - err = m.DB.EditTopicClassification(topic, cat) - if err != nil { - setErrorAndRedirect(w, r, "Could not edit topic classification "+err.Error(), "/error-page") - return + if r.FormValue("topicID") != "" { + topicID, err := strconv.Atoi(r.FormValue("topicID")) + if err != nil { + setErrorAndRedirect(w, r, "Could not convert string into int "+err.Error(), "/error-page") + return + } + topic, err := m.DB.GetThreadByID(topicID) + if err != nil { + setErrorAndRedirect(w, r, "Could not get topic by id "+err.Error(), "/error-page") + return + } + cat := models.TextClassification(selectedCategory) + + err = m.DB.EditTopicClassification(topic, cat) + if err != nil { + setErrorAndRedirect(w, r, "Could not edit topic classification "+err.Error(), "/error-page") + return + } } // Redirect back to the previous page (referer) diff --git a/internal/handler/themeHandler.go b/internal/handler/themeHandler.go index 365a6e0..16f0865 100644 --- a/internal/handler/themeHandler.go +++ b/internal/handler/themeHandler.go @@ -59,6 +59,8 @@ func (m *Repository) ThemeHandler(w http.ResponseWriter, r *http.Request) { return } + data["loggedAsID"] = visitorID + renderer.RendererTemplate(w, "theme.page.html", &models.TemplateData{ Data: data, }) @@ -250,6 +252,7 @@ func getPostsInfo(m *Repository, w http.ResponseWriter, r *http.Request, threadI info.UserPostsAmmount = userPostsAmount info.Likes = likes info.Dislikes = dislikes + info.Classification = post.Classification postsInfo = append(postsInfo, info) } diff --git a/mainDB.db b/mainDB.db index 738ec73..1829a0e 100644 Binary files a/mainDB.db and b/mainDB.db differ diff --git "a/static/ava/\320\256\321\200\320\270\320\271 \320\237\320\260\320\275\320\260\321\201\321\216\320\272.jpe" "b/static/ava/\320\256\321\200\320\270\320\271 \320\237\320\260\320\275\320\260\321\201\321\216\320\272.jpe" new file mode 100644 index 0000000..ec78b48 Binary files /dev/null and "b/static/ava/\320\256\321\200\320\270\320\271 \320\237\320\260\320\275\320\260\321\201\321\216\320\272.jpe" differ diff --git a/static/post_images/yog.jpeg b/static/post_images/yog.jpeg new file mode 100644 index 0000000..57f19e3 Binary files /dev/null and b/static/post_images/yog.jpeg differ diff --git a/template/home.page.html b/template/home.page.html index 7439f9d..87e4fe3 100644 --- a/template/home.page.html +++ b/template/home.page.html @@ -1,6 +1,7 @@ {{template "body" .}} {{define "centralPart"}} +{{$loggedID := index .Data "loggedAsID"}}
@@ -8,7 +9,9 @@ {{$threadinfo := index .Data "threads"}} - {{$loggedID := index .Data "loggedAsID"}} + {{ range $threadinfo }} {{ if or (eq .UserID $loggedID) (eq .Classification "approved") }} @@ -83,7 +86,7 @@

What this topic will {{ $lastPostShorten := shortenPost .Posts}}
{{ $lastPostShorten}} {{ else }} - Be the first one to add post here... +

Be the first one to add post here...
{{end}} {{ $numOfPosts := numberOfPosts .Posts }} diff --git a/template/moderMain.page.html b/template/moderMain.page.html index 424500e..0eb13c0 100644 --- a/template/moderMain.page.html +++ b/template/moderMain.page.html @@ -1,6 +1,8 @@ {{template "body" .}} {{define "centralPart"}} + {{$posts := index .Data "posts"}} + {{$topics := index .Data "topics"}}
Moderator Main page
+ {{ range $posts }} + {{$postsCategory := .Classification}} + {{$postID := .ID}} + + + + + + + + +
+ + {{ end }} + + + {{ end }} + + {{if $topics}}
@@ -39,7 +97,6 @@

Select Thread Category:


Category: {{ .Category}}
{{ .Subject }} - diff --git a/template/theme.page.html b/template/theme.page.html index 9d052b9..4204bf2 100644 --- a/template/theme.page.html +++ b/template/theme.page.html @@ -5,6 +5,7 @@ {{end}} {{define "centralPart"}} {{$threadID :=index .Data "mainThreadID"}} +{{$loggedID := index .Data "loggedAsID"}}
@@ -13,7 +14,9 @@ {{ if $threadID}}
+ {{ if ne 1 $loggedID}} + {{end}}
{{ end }}
@@ -73,12 +76,13 @@

Topic:

{{ end }}

{{index .Data "mainThreadName"}}
- + {{ if and (ne $loggedID 1) (eq $creatorID $loggedID) }}
+ {{end}}
Created: {{index .Data "mainThreadCreatedTime"}}
@@ -94,44 +98,52 @@

Topic:

{{$postinfo := index .Data "posts"}} {{ range $postinfo }} - - - - + + + - + {{ if .Image }} + post_img + {{ end }}

+ + {{ .Content }}  + {{ if and (ne $loggedID 1) (eq $postCreatorID $loggedID) }} + + + + + {{end}} +
+ Posted: {{ .Created }}
+
+ {{ if ne 1 $loggedID}} +
+ + + +    +
+ + + + {{ end }} +
+
+ + + {{ end }} {{ end }}