Skip to content

Commit

Permalink
moderator
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Jan 7, 2024
1 parent 2171b24 commit da7488e
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 63 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 37 additions & 14 deletions internal/handler/moderPanelHanlder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/handler/themeHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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)
}

Expand Down
Binary file modified mainDB.db
Binary file not shown.
Binary file added static/ava/Юрий Панасюк.jpe
Binary file not shown.
Binary file added static/post_images/yog.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions template/home.page.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{{template "body" .}}

{{define "centralPart"}}
{{$loggedID := index .Data "loggedAsID"}}
<div class="container custom-container">
<table class="table-borderless forumTable whiteLink mt-3">
<thead class="containerHead">
<tr>
<!-- modal starts -->
<th class="forumFirstCol" scope="col">
<div class="d-flex justify-content-start align-items-center">
{{ if ne 1 $loggedID}}
<button type="button" class="btn btn-light me-2" data-bs-toggle="modal" data-bs-target="#createNewTopicModal">Create New Topic</button>
{{end}}
</div>
<div class="d-flex justify-content-center">
<h3>Created Topics</h3>
Expand Down Expand Up @@ -53,7 +56,7 @@ <h1 class="modal-title fs-5" id="createNewTopicModalLabel">What this topic will
</thead>
<tbody class="containerBody">
{{$threadinfo := index .Data "threads"}}
{{$loggedID := index .Data "loggedAsID"}}

{{ range $threadinfo }}
{{ if or (eq .UserID $loggedID) (eq .Classification "approved") }}
<tr>
Expand Down Expand Up @@ -83,7 +86,7 @@ <h1 class="modal-title fs-5" id="createNewTopicModalLabel">What this topic will
{{ $lastPostShorten := shortenPost .Posts}}
<br><em>{{ $lastPostShorten}}</em></td>
{{ else }}
<h8><em>Be the first one to add post here...</em></h8>
<h6><em>Be the first one to add post here...</em></h6>
{{end}}
{{ $numOfPosts := numberOfPosts .Posts }}

Expand Down
63 changes: 60 additions & 3 deletions template/moderMain.page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{template "body" .}}

{{define "centralPart"}}
{{$posts := index .Data "posts"}}
{{$topics := index .Data "topics"}}
<div class="content">
Moderator Main page
<div class="navbar" id="navbarSupportedContent">
Expand All @@ -21,10 +23,66 @@ <h2>Select Thread Category:</h2>
{{end}}
</ul>
</li>

<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
<h2>Select Posts Category:</h2>
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
{{$categories := index .Data "categories"}}
{{range $categories}}
{{$route := printf "/moder_panel?post=%s" . }}
<li><a class="dropdown-item" href={{$route}}>{{ . }}</a></li>
{{end}}
</ul>
</li>
</ul>
<!-- ends -->
{{$posts := index .Data "posts"}}
{{$topics := index .Data "topics"}}


{{if $posts}}
<div>
<tbody class="containerBody">
{{ range $posts }}
{{$postsCategory := .Classification}}
{{$postID := .ID}}
<tr>
<td>
<br>Created by user with ID: {{ .UserID}}
<br>Topic created: {{convertTime . }}
<br>Category: {{ .Classification}}
<br><em>{{ .Subject }} </em>
<br><strong>{{ .Content }} </strong>
</td>
<tbody class="containerBody">
<tr>
<td>
<form method="post" action="">
{{range $index, $category := $categories}}
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio{{$index}}"
autocomplete="off" value="{{$category}}" {{ if eq $category $postsCategory }}
checked {{end}}>
<label class="btn btn-outline-primary" for="btnradio{{$index}}"> {{$category}} </label>
<input type="hidden" name="postID" value="{{ $postID }}">
</div>
{{end}}
<input type="submit" value="Submit">
</form>

</td>
</tr>

</tbody>
<hr>
</tr>
{{ end }}
</tbody>

{{ end }}


{{if $topics}}
<div>
<tbody class="containerBody">
Expand All @@ -39,7 +97,6 @@ <h2>Select Thread Category:</h2>
<br>Category: {{ .Category}}
<br><strong>{{ .Subject }} </strong>


</td>
<tbody class="containerBody">
<tr>
Expand Down
86 changes: 49 additions & 37 deletions template/theme.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{end}}
{{define "centralPart"}}
{{$threadID :=index .Data "mainThreadID"}}
{{$loggedID := index .Data "loggedAsID"}}
<div class="container custom-container">

<table class="table-borderless forumTable whiteLink mt-3">
Expand All @@ -13,7 +14,9 @@
<!-- Colling Modal -->
{{ if $threadID}}
<div class="d-flex justify-content-start align-items-center">
{{ if ne 1 $loggedID}}
<button type="button" class="btn btn-secondary me-2" data-bs-toggle="modal" data-bs-target="#createNewPostModal">Create New Post</button>
{{end}}
</div>
{{ end }}
<div class="d-flex justify-content-center">
Expand Down Expand Up @@ -73,12 +76,13 @@ <h3>Topic:</h3>
{{ end }} <br><br>
{{index .Data "mainThreadName"}} <br>


{{ if and (ne $loggedID 1) (eq $creatorID $loggedID) }}
<form method="POST" action="/edit_topic?topicID={{$threadID}}">
<input type="hidden" name="topic_id" value="{{$threadID }}">
<button type="submit" style="background: none; border: none; padding: 0; font: inherit; cursor: pointer;
text-decoration: underline; color:inherit;">✍🏻 Edit</button>
</form>
{{end}}
<hr>
Created: {{index .Data "mainThreadCreatedTime"}}
</div>
Expand All @@ -94,44 +98,52 @@ <h3>Topic:</h3>
<tbody class="containerBody">
{{$postinfo := index .Data "posts"}}
{{ range $postinfo }}
<tr>
<td>
<img src="{{ .PictureUserWhoCreatedPost }}" class="ava_img" alt="ava">
<br><a href="/personal_cabinet?userID={{ .UserIDWhoCreatedPost}}"><strong>&nbsp;{{ .UserNameWhoCreatedPost }}</strong></a><br>
Date of Registration:<br>{{ .UserRegistrationDate}} <br>
Total Messages: {{ .UserPostsAmmount}}
</td>
<td>
</td>
<td>
<em>{{ .Subject}}</em> <br><br>
{{$postCreatorID := .UserIDWhoCreatedPost}}
{{ if or (eq $postCreatorID $loggedID) (eq .Classification "approved") }}

{{ if .Image }}
<img src="{{ .Image }}" class="post_img" alt="post_img">
{{ end }} <br><br>
<tr>
<td>
<img src="{{ .PictureUserWhoCreatedPost }}" class="ava_img" alt="ava">
<br><a href="/personal_cabinet?userID={{ .UserIDWhoCreatedPost}}"><strong>&nbsp;{{ .UserNameWhoCreatedPost }}</strong></a><br>
Date of Registration:<br>{{ .UserRegistrationDate}} <br>
Total Messages: {{ .UserPostsAmmount}}
</td>
<td>
</td>
<td>
<em>{{ .Subject}}</em> <br><br>

{{ .Content }}&nbsp;
<form method="POST" action="/edit_post?postID={{ .ID}}">
<input type="hidden" name="topic_id" value="{{ .ID }}">
<button type="submit" style="background: none; border: none; padding: 0; font: inherit; cursor: pointer;
text-decoration: underline; color:inherit;">✍🏻 Edit / Delete</button>
</form>
<br>
Posted: {{ .Created }}<br>
<div class="d-flex justify-content-start align-items-center">
<form method="POST" action="">
<input type="hidden" name="like" value="{{ .ID }}">
<button type="submit" class="btn btn-success btn-sm mr-2">Like👍&nbsp;{{ .Likes }}</button>
</form>
&nbsp;&nbsp;
<form method="POST" action="">
<input type="hidden" name="dislike" value="{{ .ID }}">
<button type="submit" class="btn btn-danger btn-sm">Dislike👎&nbsp;{{ .Dislikes }}</button>
</form>
</div>
<hr>
</td>
</tr>
{{ if .Image }}
<img src="{{ .Image }}" class="post_img" alt="post_img">
{{ end }} <br><br>

{{ .Content }}&nbsp;
{{ if and (ne $loggedID 1) (eq $postCreatorID $loggedID) }}
<form method="POST" action="/edit_post?postID={{ .ID}}">
<input type="hidden" name="topic_id" value="{{ .ID }}">
<button type="submit" style="background: none; border: none; padding: 0; font: inherit; cursor: pointer;
text-decoration: underline; color:inherit;">✍🏻 Edit / Delete</button>
</form>
{{end}}
<br>
Posted: {{ .Created }}<br>
<div class="d-flex justify-content-start align-items-center">
{{ if ne 1 $loggedID}}
<form method="POST" action="">
<input type="hidden" name="like" value="{{ .ID }}">
<button type="submit" class="btn btn-success btn-sm mr-2">Like👍&nbsp;{{ .Likes }}</button>
</form>
&nbsp;&nbsp;
<form method="POST" action="">
<input type="hidden" name="dislike" value="{{ .ID }}">
<button type="submit" class="btn btn-danger btn-sm">Dislike👎&nbsp;{{ .Dislikes }}</button>
</form>
{{ end }}
</div>
<hr>
</td>
</tr>
{{ end }}
{{ end }}
<!-- posts end here -->
</tbody>
Expand Down

0 comments on commit da7488e

Please sign in to comment.