Merge branch 'master' into compression
Cette révision appartient à :
révision
d7a93d0235
|
@ -3,4 +3,6 @@ package config
|
||||||
const (
|
const (
|
||||||
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
|
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
|
||||||
TorrentFileStorage = ""
|
TorrentFileStorage = ""
|
||||||
|
//disable uploads by default
|
||||||
|
UploadsDisabled = 1
|
||||||
)
|
)
|
||||||
|
|
|
@ -55,6 +55,7 @@ type UserVerifyTemplateVariables struct {
|
||||||
|
|
||||||
type UserLoginFormVariables struct {
|
type UserLoginFormVariables struct {
|
||||||
LoginForm userForms.LoginForm
|
LoginForm userForms.LoginForm
|
||||||
|
FormErrors map[string][]string
|
||||||
Search SearchForm
|
Search SearchForm
|
||||||
Navigation Navigation
|
Navigation Navigation
|
||||||
URL *url.URL // For parsing Url in templates
|
URL *url.URL // For parsing Url in templates
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ewhal/nyaa/config"
|
||||||
"github.com/ewhal/nyaa/db"
|
"github.com/ewhal/nyaa/db"
|
||||||
"github.com/ewhal/nyaa/model"
|
"github.com/ewhal/nyaa/model"
|
||||||
"github.com/ewhal/nyaa/service/captcha"
|
"github.com/ewhal/nyaa/service/captcha"
|
||||||
|
@ -14,6 +15,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if config.UploadsDisabled == 1 {
|
||||||
|
http.Error(w, "Error uploads are disabled", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
var uploadForm UploadForm
|
var uploadForm UploadForm
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
|
|
|
@ -36,8 +36,10 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
b := form.LoginForm{}
|
b := form.LoginForm{}
|
||||||
modelHelper.BindValueForm(&b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
|
|
||||||
languages.SetTranslationFromRequest(viewLoginTemplate, r, "en-us")
|
languages.SetTranslationFromRequest(viewLoginTemplate, r, "en-us")
|
||||||
htv := UserLoginFormVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
htv := UserLoginFormVariables{b, form.NewErrors(), NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||||
|
|
||||||
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -114,6 +116,26 @@ func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Post Login controller
|
// Post Login controller
|
||||||
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
b := form.LoginForm{}
|
||||||
|
modelHelper.BindValueForm(&b, r)
|
||||||
|
err := form.NewErrors()
|
||||||
|
err = modelHelper.ValidateForm(&b, err)
|
||||||
|
if (len(err) == 0) {
|
||||||
|
_, errorUser := userService.CreateUserAuthentication(w, r)
|
||||||
|
if (errorUser != nil) {
|
||||||
|
err["errors"] = append(err["errors"], errorUser.Error())
|
||||||
|
languages.SetTranslationFromRequest(viewLoginTemplate, r, "en-us")
|
||||||
|
htv := UserLoginFormVariables{b, err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||||
|
errorTmpl := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
|
if errorTmpl != nil {
|
||||||
|
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
url, _ := Router.Get("home").URL()
|
||||||
|
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ type RegistrationForm struct {
|
||||||
|
|
||||||
// RegistrationForm is used when creating a user authentication.
|
// RegistrationForm is used when creating a user authentication.
|
||||||
type LoginForm struct {
|
type LoginForm struct {
|
||||||
Email string `form:"email"`
|
Username string `form:"username" needed="true"`
|
||||||
Password string `form:"password"`
|
Password string `form:"password" needed="true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserForm is used when updating a user.
|
// UserForm is used when updating a user.
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
"id":"username",
|
"id":"username",
|
||||||
"translation": "Username"
|
"translation": "Username"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id":"email_address_or_username",
|
||||||
|
"translation": "Email Address or Username"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id":"email_address",
|
"id":"email_address",
|
||||||
"translation": "Email Address"
|
"translation": "Email Address"
|
||||||
|
|
|
@ -344,8 +344,8 @@ func ActivateUser(r *http.Request, id string) (model.User, int, error) {
|
||||||
func CreateUserAuthentication(w http.ResponseWriter, r *http.Request) (int, error) {
|
func CreateUserAuthentication(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
var form formStruct.LoginForm
|
var form formStruct.LoginForm
|
||||||
modelHelper.BindValueForm(&form, r)
|
modelHelper.BindValueForm(&form, r)
|
||||||
email := form.Email
|
username := form.Username
|
||||||
pass := form.Password
|
pass := form.Password
|
||||||
status, err := SetCookieHandler(w, email, pass)
|
status, err := SetCookieHandler(w, username, pass)
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,20 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<h2>{{T "sign_in_box_title"}}</h2>
|
<h2>{{T "sign_in_box_title"}}</h2>
|
||||||
<hr class="colorgraph">
|
<hr class="colorgraph">
|
||||||
|
{{ range (index $.FormErrors "errors")}}
|
||||||
|
<div class="alert alert-danger">{{ . }}</div>
|
||||||
|
{{end}}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="{{ T "email_address"}}">
|
<input type="text" name="username" id="username" class="form-control input-lg" placeholder="{{ T "email_address_or_username"}}">
|
||||||
|
{{ range (index $.FormErrors "username")}}
|
||||||
|
<p class="bg-danger">{{ . }}</p>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="{{ T "password"}}">
|
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="{{ T "password"}}">
|
||||||
|
{{ range (index $.FormErrors "password")}}
|
||||||
|
<p class="bg-danger">{{ . }}</p>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<span class="button-checkbox">
|
<span class="button-checkbox">
|
||||||
<button type="button" class="btn hidden" data-color="info">{{ T "remember_me"}}</button>
|
<button type="button" class="btn hidden" data-color="info">{{ T "remember_me"}}</button>
|
||||||
|
|
Référencer dans un nouveau ticket