Shitty Moderation page
No HTML done, could'nt test with nyaa.exe :/ 1 page with overview of torrents, comments, users 1 page list comments 1 page list torrents 1 page list users 1 route delete torreny 1 route delete comment Users can be deleted and edited by their route user_profile_edit (I think)
Cette révision appartient à :
Parent
95fda5e856
révision
7c5bae175b
10 fichiers modifiés avec 230 ajouts et 37 suppressions
|
@ -3,55 +3,138 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/comment"
|
||||
"github.com/ewhal/nyaa/service/user"
|
||||
"github.com/ewhal/nyaa/service/user/permission"
|
||||
// "github.com/ewhal/nyaa/util/languages"
|
||||
// "github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/gorilla/mux"
|
||||
form "github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/ewhal/nyaa/service/torrent"
|
||||
"github.com/ewhal/nyaa/service/torrent/form"
|
||||
"github.com/ewhal/nyaa/util/languages"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
)
|
||||
|
||||
var panelCommentList *template.Template
|
||||
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
|
||||
func init() {
|
||||
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
|
||||
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
|
||||
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
|
||||
panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html")))
|
||||
panelTorrentEd = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
|
||||
}
|
||||
|
||||
func IndexModPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func UsersListPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||
func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
offset := 10
|
||||
|
||||
torrents, _, _ := torrentService.GetAllTorrents(0, offset)
|
||||
users := userService.RetrieveUsersForAdmin(0, offset)
|
||||
comments := commentService.GetAllComments(0, offset)
|
||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
||||
htv := PanelIndexVbs{torrents, users, comments}
|
||||
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
|
||||
}
|
||||
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||
offset := 100
|
||||
|
||||
comments := commentService.GetAllTorrents(page*offset, offset)
|
||||
torrents, _, _ := torrentService.GetAllTorrents(page*offset, offset)
|
||||
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
||||
htv := PanelTorrentListVbs{torrents}
|
||||
_= panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
}
|
||||
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||
offset := 100
|
||||
|
||||
users := userService.RetrieveUsersForAdmin(page*offset, offset)
|
||||
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
||||
htv := PanelUserListVbs{users}
|
||||
_ = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
}
|
||||
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||
offset := 100
|
||||
|
||||
comments := commentService.GetAllComments(page*offset, offset)
|
||||
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
||||
htv := PanelCommentListVbs{comments}
|
||||
err := panelCommentList.ExecuteTemplate(w, "index.html", htv)
|
||||
_= panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
|
||||
}
|
||||
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
// Todo
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
id := r.URL.Query().Get("id")
|
||||
torrent, _ := torrentService.GetTorrentById(id)
|
||||
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
||||
htv := PanelTorrentEdVbs{torrent}
|
||||
_= panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
|
||||
}
|
||||
func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
b := torrentform.PanelPost{}
|
||||
err := form.NewErrors()
|
||||
infos := form.NewInfos()
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
err = modelHelper.ValidateForm(&b, err)
|
||||
id := r.URL.Query().Get("id")
|
||||
torrent, _ := torrentService.GetTorrentById(id)
|
||||
if (torrent.Id > 0) {
|
||||
modelHelper.AssignValue(&torrent, &b)
|
||||
if (len(err) == 0) {
|
||||
_, errorT := torrentService.UpdateTorrent(torrent)
|
||||
if (errorT != nil) {
|
||||
err["errors"] = append(err["errors"], errorT.Error())
|
||||
}
|
||||
if (len(err) == 0) {
|
||||
infos["infos"] = append(infos["infos"], "torrent_updated")
|
||||
}
|
||||
}
|
||||
}
|
||||
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
||||
htv := PanelTorrentEdVbs{torrent}
|
||||
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
}
|
||||
}
|
||||
|
||||
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (HasAdmin(currentUser)) {
|
||||
err := form.NewErrors()
|
||||
_, _ := userService.DeleteComment(id)
|
||||
url, _ := Router.Get("mod_comment_list")
|
||||
id := r.URL.Query().Get("id")
|
||||
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
_= form.NewErrors()
|
||||
_, _ = userService.DeleteComment(id)
|
||||
url, _ := Router.Get("mod_comment_list").URL()
|
||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (HasAdmin(currentUser)) {
|
||||
err := form.NewErrors()
|
||||
_, _ := torrentService.DeleteTorrent(id)
|
||||
url, _ := Router.Get("mod_torrent_list")
|
||||
id := r.URL.Query().Get("id")
|
||||
if (userPermission.HasAdmin(currentUser)) {
|
||||
_= form.NewErrors()
|
||||
_, _ = torrentService.DeleteTorrent(id)
|
||||
url, _ := Router.Get("mod_torrent_list").URL()
|
||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||
}
|
||||
}
|
|
@ -39,6 +39,18 @@ func init() {
|
|||
gzipUserFollowHandler := handlers.CompressHandler(http.HandlerFunc(UserFollowHandler))
|
||||
gzipUserProfileFormHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileFormHandler))
|
||||
|
||||
|
||||
gzipIndexModPanel := handlers.CompressHandler(http.HandlerFunc(IndexModPanel))
|
||||
gzipTorrentsListPanel := handlers.CompressHandler(http.HandlerFunc(TorrentsListPanel))
|
||||
gzipUsersListPanel := handlers.CompressHandler(http.HandlerFunc(UsersListPanel))
|
||||
gzipCommentsListPanel := handlers.CompressHandler(http.HandlerFunc(CommentsListPanel))
|
||||
gzipTorrentEditModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentEditModPanel))
|
||||
gzipTorrentPostEditModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentPostEditModPanel))
|
||||
gzipCommentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(CommentDeleteModPanel))
|
||||
gzipTorrentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentDeleteModPanel))
|
||||
|
||||
|
||||
|
||||
Router = mux.NewRouter()
|
||||
|
||||
// Routes
|
||||
|
@ -68,6 +80,17 @@ func init() {
|
|||
Router.Handle("/user/{id}/{username}", gzipUserProfileHandler).Name("user_profile").Methods("GET")
|
||||
Router.Handle("/user/{id}/{username}/follow", gzipUserFollowHandler).Name("user_follow").Methods("GET")
|
||||
Router.Handle("/user/{id}/{username}", gzipUserProfileFormHandler).Name("user_profile").Methods("POST")
|
||||
|
||||
Router.Handle("/mod/", gzipIndexModPanel).Name("mod_index")
|
||||
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
||||
Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist")
|
||||
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_clist")
|
||||
Router.Handle("/mod/torrent/", gzipTorrentEditModPanel).Name("mod_tedit")
|
||||
Router.Handle("/mod/torrent/", gzipTorrentPostEditModPanel).Name("mod_ptedit")
|
||||
Router.Handle("/mod/torrent/delete", gzipCommentDeleteModPanel).Name("mod_tdelete")
|
||||
Router.Handle("/mod/comment/delete", gzipTorrentDeleteModPanel).Name("mod_cdelete")
|
||||
|
||||
|
||||
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
|
||||
|
||||
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
|
||||
|
|
|
@ -113,6 +113,25 @@ type UploadTemplateVariables struct {
|
|||
Route *mux.Route
|
||||
}
|
||||
|
||||
type PanelIndexVbs struct {
|
||||
Torrents []model.Torrents
|
||||
Users []model.User
|
||||
Comments []model.Comment
|
||||
}
|
||||
|
||||
type PanelTorrentListVbs struct {
|
||||
Torrents []model.Torrents
|
||||
}
|
||||
type PanelUserListVbs struct {
|
||||
Users []model.User
|
||||
}
|
||||
type PanelCommentListVbs struct {
|
||||
Comments []model.Comment
|
||||
}
|
||||
type PanelTorrentEdVbs struct {
|
||||
Torrent model.Torrents
|
||||
}
|
||||
|
||||
/*
|
||||
* Variables used by the upper ones
|
||||
*/
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package commentService
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/user/permission"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
|
||||
)
|
||||
|
||||
func GetAllComments(limit int, offset int) {
|
||||
func GetAllComments(limit int, offset int) []model.Comment{
|
||||
var comments []model.Comment
|
||||
db.ORM.Limit(limit).Offset(offset).Preload("Uploader").Find(&comments)
|
||||
return comments
|
||||
|
|
11
service/torrent/form/form.go
Fichier normal
11
service/torrent/form/form.go
Fichier normal
|
@ -0,0 +1,11 @@
|
|||
package torrentform
|
||||
|
||||
type PanelPost struct {
|
||||
Name string `form:"name" needed:"true" len_min:"3" len_max:"20"`
|
||||
Hash string `form:"hash" needed:"true"`
|
||||
Category int `form:"cat" needed:"true"`
|
||||
Sub_Category int `form:"subcat"`
|
||||
Status string `form:"status" needed:"true"`
|
||||
Description string `form:"desc"`
|
||||
WebsiteLink string `form:"website"`
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
|
@ -177,7 +178,7 @@ func CreateWhereParams(conditions string, params ...string) WhereParams {
|
|||
return whereParams
|
||||
}
|
||||
|
||||
func DeleteTorrent(id string) {
|
||||
func DeleteTorrent(id string) (int, error) {
|
||||
var torrent model.Torrents
|
||||
if db.ORM.First(&torrent, id).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("Torrent is not found.")
|
||||
|
@ -185,5 +186,13 @@ func DeleteTorrent(id string) {
|
|||
if db.ORM.Delete(&torrent).Error != nil {
|
||||
return http.StatusInternalServerError, errors.New("Torrent is not deleted.")
|
||||
}
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
func UpdateTorrent(torrent model.Torrents) (int, error) {
|
||||
if db.ORM.Save(torrent).Error != nil {
|
||||
return http.StatusInternalServerError, errors.New("Torrent is not updated.")
|
||||
}
|
||||
|
||||
return http.StatusOK, nil
|
||||
}
|
|
@ -271,16 +271,10 @@ func RetrieveUserForAdmin(id string) (model.User, int, error) {
|
|||
}
|
||||
|
||||
// RetrieveUsersForAdmin retrieves users for an administrator.
|
||||
func RetrieveUsersForAdmin() []model.User {
|
||||
func RetrieveUsersForAdmin(limit int, offset int) []model.User {
|
||||
var users []model.User
|
||||
var userArr []model.User
|
||||
db.ORM.Find(&users)
|
||||
for _, user := range users {
|
||||
db.ORM.Model(&user)
|
||||
db.ORM.Model(&user).Related("Torrents").Related("Likings").Related("Liked").Find(&model.Torrents{})
|
||||
userArr = append(userArr, user)
|
||||
}
|
||||
return userArr
|
||||
db.ORM.Preload("Torrents").Find(&users).Limit(limit).Offset(offset)
|
||||
return users
|
||||
}
|
||||
|
||||
// CreateUserAuthentication creates user authentication.
|
||||
|
@ -307,7 +301,7 @@ func RemoveFollow(user *model.User, follower *model.User) {
|
|||
}
|
||||
}
|
||||
|
||||
func DeleteComment(id string) {
|
||||
func DeleteComment(id string) (int, error) {
|
||||
var comment model.Comment
|
||||
if db.ORM.First(&comment, id).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("Comment is not found.")
|
||||
|
|
8
templates/admin/commentlist.html
Fichier normal
8
templates/admin/commentlist.html
Fichier normal
|
@ -0,0 +1,8 @@
|
|||
{{block "content"}}
|
||||
<table>
|
||||
{{ range .Comments}}
|
||||
|
||||
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.Id}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cdelete" }}?id{{ .Id }}">Delete</a></td></tr>
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
8
templates/admin/torrentlist.html
Fichier normal
8
templates/admin/torrentlist.html
Fichier normal
|
@ -0,0 +1,8 @@
|
|||
{{block "content"}}
|
||||
<table>
|
||||
{{ range .Torrents}}
|
||||
|
||||
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Id}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tdelete" }}?id{{ .Id }}">Delete</a></td></tr>
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
42
templates/admin_index.html
Fichier normal
42
templates/admin_index.html
Fichier normal
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<title>Nyaa Pantsu - {{block "title" .}}{{ T "error_404" }}{{end}}</title>
|
||||
<link rel="icon" type="image/png" href="/img/favicon.png?v=3" />
|
||||
|
||||
<!-- RSS Feed with Context -->
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<!-- This should come before website CSS because it can f3ck up the website completely.. Use !important as a workaround -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
|
||||
<!-- Bootstrap -->
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Website CSS -->
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" id="container">
|
||||
{{block "content" .}}{{end}}
|
||||
</div>
|
||||
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
||||
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
|
||||
|
||||
{{block "js_footer" .}}{{end}}
|
||||
</body>
|
||||
</html>
|
Référencer dans un nouveau ticket