c9b72206a5
* 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.
142 lignes
3,6 Kio
Go
142 lignes
3,6 Kio
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/ewhal/nyaa/model"
|
|
"github.com/ewhal/nyaa/service/captcha"
|
|
"github.com/ewhal/nyaa/service/user"
|
|
userForms "github.com/ewhal/nyaa/service/user/form"
|
|
"github.com/ewhal/nyaa/util/search"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
/* Each Page should have an object to pass to their own template
|
|
* Therefore, we put them in a separate file for better maintenance
|
|
*
|
|
* MAIN Template Variables
|
|
*/
|
|
|
|
type FaqTemplateVariables struct {
|
|
Navigation Navigation
|
|
Search SearchForm
|
|
User *model.User
|
|
URL *url.URL // For parsing Url in templates
|
|
Route *mux.Route // For getting current route in templates
|
|
}
|
|
|
|
type NotFoundTemplateVariables struct {
|
|
Navigation Navigation
|
|
Search SearchForm
|
|
User *model.User
|
|
URL *url.URL // For parsing Url in templates
|
|
Route *mux.Route // For getting current route in templates
|
|
}
|
|
|
|
type ViewTemplateVariables struct {
|
|
Torrent model.TorrentJSON
|
|
Captcha captcha.Captcha
|
|
Search SearchForm
|
|
Navigation Navigation
|
|
User *model.User
|
|
URL *url.URL // For parsing Url in templates
|
|
Route *mux.Route // For getting current route in templates
|
|
}
|
|
|
|
type UserRegisterTemplateVariables struct {
|
|
RegistrationForm userForms.RegistrationForm
|
|
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
|
|
}
|
|
|
|
type UserProfileEditVariables struct {
|
|
UserProfile *model.User
|
|
UserForm userForms.UserForm
|
|
FormErrors map[string][]string
|
|
FormInfos 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
|
|
}
|
|
|
|
type UserVerifyTemplateVariables struct {
|
|
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
|
|
}
|
|
|
|
type UserLoginFormVariables struct {
|
|
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
|
|
}
|
|
|
|
type UserProfileVariables struct {
|
|
UserProfile *model.User
|
|
FormInfos 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
|
|
}
|
|
|
|
type HomeTemplateVariables struct {
|
|
ListTorrents []model.TorrentJSON
|
|
Search SearchForm
|
|
Navigation Navigation
|
|
User *model.User
|
|
URL *url.URL // For parsing Url in templates
|
|
Route *mux.Route // For getting current route in templates
|
|
}
|
|
|
|
type UploadTemplateVariables struct {
|
|
Upload UploadForm
|
|
Search SearchForm
|
|
Navigation Navigation
|
|
User *model.User
|
|
URL *url.URL
|
|
Route *mux.Route
|
|
}
|
|
|
|
/*
|
|
* Variables used by the upper ones
|
|
*/
|
|
type Navigation struct {
|
|
TotalItem int
|
|
MaxItemPerPage int
|
|
CurrentPage int
|
|
Route string
|
|
}
|
|
|
|
type SearchForm struct {
|
|
search.SearchParam
|
|
Category string
|
|
HideAdvancedSearch bool
|
|
}
|
|
|
|
// Some Default Values to ease things out
|
|
func NewSearchForm() SearchForm {
|
|
return SearchForm{
|
|
Category: "_",
|
|
}
|
|
}
|
|
|
|
func GetUser(r *http.Request) *model.User {
|
|
user, _, _ := userService.RetrieveCurrentUser(r)
|
|
return &user
|
|
}
|