2017-05-05 16:39:15 +02:00
package router
2017-05-05 03:53:38 +02:00
import (
2017-05-08 01:46:30 +02:00
"net/http"
2017-05-09 13:31:58 +02:00
"net/url"
2017-05-06 23:16:21 +02:00
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/user"
userForms "github.com/NyaaPantsu/nyaa/service/user/form"
2017-05-06 10:36:37 +02:00
"github.com/gorilla/mux"
2017-05-05 03:53:38 +02:00
)
2017-05-05 06:07:45 +02:00
/ * Each Page should have an object to pass to their own template
2017-05-15 11:08:17 +02:00
* Therefore , we put them in a separate file for better maintenance
*
* MAIN Template Variables
2017-05-05 06:07:45 +02:00
* /
2017-05-05 03:53:38 +02:00
type FaqTemplateVariables struct {
2017-05-07 01:20:13 +02:00
Navigation Navigation
Search SearchForm
2017-05-09 03:36:48 +02:00
User * model . User
2017-05-05 06:07:45 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 10:52:08 +02:00
}
2017-05-07 08:59:45 +02:00
type NotFoundTemplateVariables struct {
Navigation Navigation
Search SearchForm
2017-05-09 03:36:48 +02:00
User * model . User
2017-05-07 08:59:45 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
}
2017-05-05 10:52:08 +02:00
type ViewTemplateVariables struct {
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
Torrent model . TorrentJSON
2017-05-12 11:58:22 +02:00
CaptchaID string
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-09 03:36:48 +02:00
User * model . User
2017-05-06 10:36:37 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 03:53:38 +02:00
}
2017-05-07 00:10:40 +02:00
type UserRegisterTemplateVariables struct {
2017-05-07 01:20:13 +02:00
RegistrationForm userForms . RegistrationForm
2017-05-09 13:31:58 +02:00
FormErrors map [ string ] [ ] string
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-09 13:31:58 +02:00
User * model . User
2017-05-07 01:20:13 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-07 00:10:40 +02:00
}
2017-05-09 17:47:06 +02:00
type UserProfileEditVariables struct {
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
UserProfile * model . User
UserForm userForms . UserForm
FormErrors map [ string ] [ ] string
FormInfos map [ string ] [ ] string
2017-05-10 21:45:39 +02:00
Languages map [ string ] string
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
Search SearchForm
Navigation Navigation
User * model . User
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-09 17:47:06 +02:00
}
2017-05-07 22:00:45 +02:00
type UserVerifyTemplateVariables struct {
2017-05-09 13:31:58 +02:00
FormErrors map [ string ] [ ] string
Search SearchForm
Navigation Navigation
User * model . User
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-07 22:00:45 +02:00
}
2017-05-07 04:02:57 +02:00
type UserLoginFormVariables struct {
2017-05-09 13:31:58 +02:00
LoginForm userForms . LoginForm
FormErrors map [ string ] [ ] string
Search SearchForm
Navigation Navigation
User * model . User
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-09 03:36:48 +02:00
}
type UserProfileVariables struct {
2017-05-09 13:31:58 +02:00
UserProfile * model . User
2017-05-10 11:03:49 +02:00
FormInfos map [ string ] [ ] string
2017-05-09 13:31:58 +02:00
Search SearchForm
Navigation Navigation
User * model . User
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-07 04:02:57 +02:00
}
2017-05-05 03:53:38 +02:00
type HomeTemplateVariables struct {
Consistency, formatting, error checking, cleanup, and a couple bug fixes (#245)
* Checkpoint: it builds
The config, db, model, network, os, and public packages have had some
fixes to glaringly obvious flaws, dead code removed, and stylistic
changes.
* Style changes and old code removal in router
Router needs a lot of work done to its (lack of) error handling.
* Dead code removal and style changes
Now up to util/email/email.go. After I'm finished with the initial sweep
I'll go back and fix error handling and security issues. Then I'll fix
the broken API. Then I'll go through to add documentation and fix code
visibility.
* Finish dead code removal and style changes
Vendored libraries not touched. Everything still needs security fixes
and documentation. There's also one case of broken functionality.
* Fix accidental find-and-replace
* Style, error checking, saftey, bug fix changes
* Redo error checking erased during merge
* Re-add merge-erased fix. Make Safe safe.
2017-05-10 04:34:40 +02:00
ListTorrents [ ] model . TorrentJSON
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-09 13:31:58 +02:00
User * model . User
2017-05-07 01:20:13 +02:00
URL * url . URL // For parsing Url in templates
Route * mux . Route // For getting current route in templates
2017-05-05 03:53:38 +02:00
}
2017-05-06 10:36:37 +02:00
type UploadTemplateVariables struct {
Upload UploadForm
2017-05-07 01:20:13 +02:00
Search SearchForm
Navigation Navigation
2017-05-09 03:36:48 +02:00
User * model . User
2017-05-06 10:36:37 +02:00
URL * url . URL
Route * mux . Route
}
2017-05-07 01:20:13 +02:00
2017-05-13 00:17:34 +02:00
type ChangeLanguageVariables struct {
Search SearchForm
Navigation Navigation
Language string
Languages map [ string ] string
User * model . User
URL * url . URL
Route * mux . Route
}
2017-05-10 17:37:49 +02:00
/* MODERATION Variables */
2017-05-10 05:24:18 +02:00
type PanelIndexVbs struct {
2017-05-10 20:42:20 +02:00
Torrents [ ] model . Torrent
2017-05-12 20:43:38 +02:00
TorrentReports [ ] model . TorrentReportJson
2017-05-10 20:42:20 +02:00
Users [ ] model . User
Comments [ ] model . Comment
Search SearchForm
User * model . User
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
type PanelTorrentListVbs struct {
2017-05-10 20:42:20 +02:00
Torrents [ ] model . Torrent
Search SearchForm
2017-05-10 15:08:38 +02:00
Navigation Navigation
2017-05-10 17:37:49 +02:00
User * model . User
2017-05-10 20:42:20 +02:00
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
type PanelUserListVbs struct {
2017-05-10 20:42:20 +02:00
Users [ ] model . User
Search SearchForm
2017-05-10 15:08:38 +02:00
Navigation Navigation
2017-05-10 17:37:49 +02:00
User * model . User
2017-05-10 20:42:20 +02:00
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
type PanelCommentListVbs struct {
2017-05-10 20:42:20 +02:00
Comments [ ] model . Comment
Search SearchForm
2017-05-10 15:08:38 +02:00
Navigation Navigation
2017-05-10 17:37:49 +02:00
User * model . User
2017-05-10 20:42:20 +02:00
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
2017-05-13 17:29:21 +02:00
2017-05-10 05:24:18 +02:00
type PanelTorrentEdVbs struct {
2017-05-10 23:53:25 +02:00
Upload UploadForm
2017-05-15 11:08:17 +02:00
Search SearchForm
User * model . User
FormErrors map [ string ] [ ] string
FormInfos map [ string ] [ ] string
2017-05-11 00:02:36 +02:00
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
2017-05-10 20:42:20 +02:00
type PanelTorrentReportListVbs struct {
2017-05-10 21:09:37 +02:00
TorrentReports [ ] model . TorrentReportJson
Search SearchForm
Navigation Navigation
User * model . User
URL * url . URL // For parsing Url in templates
2017-05-10 05:24:18 +02:00
}
2017-05-13 17:29:21 +02:00
type PanelTorrentReassignVbs struct {
2017-05-15 11:08:17 +02:00
Reassign ReassignForm
Search SearchForm // unused?
User * model . User // unused?
FormErrors map [ string ] [ ] string
FormInfos map [ string ] [ ] string
URL * url . URL // For parsing Url in templates
2017-05-13 17:29:21 +02:00
}
2017-05-07 01:20:13 +02:00
/ *
2017-05-15 11:08:17 +02:00
* Variables used by the upper ones
2017-05-07 01:20:13 +02:00
* /
type Navigation struct {
TotalItem int
2017-05-17 07:58:40 +02:00
MaxItemPerPage int // FIXME: shouldn't this be in SearchForm?
2017-05-07 01:20:13 +02:00
CurrentPage int
Route string
}
type SearchForm struct {
2017-05-10 11:03:49 +02:00
common . SearchParam
2017-05-14 13:01:59 +02:00
Category string
ShowItemsPerPage bool
2017-05-07 01:20:13 +02:00
}
// Some Default Values to ease things out
2017-05-15 13:55:16 +02:00
func NewNavigation ( ) Navigation {
return Navigation {
MaxItemPerPage : 50 ,
}
}
2017-05-09 13:31:58 +02:00
func NewSearchForm ( ) SearchForm {
return SearchForm {
2017-05-15 11:08:17 +02:00
Category : "_" ,
2017-05-14 13:01:59 +02:00
ShowItemsPerPage : true ,
2017-05-07 01:20:13 +02:00
}
}
2017-05-08 01:46:30 +02:00
2017-05-09 03:36:48 +02:00
func GetUser ( r * http . Request ) * model . User {
2017-05-09 13:31:58 +02:00
user , _ , _ := userService . RetrieveCurrentUser ( r )
2017-05-09 03:36:48 +02:00
return & user
2017-05-08 05:34:12 +02:00
}