Merge branch 'master' into compression
Cette révision appartient à :
révision
d7a93d0235
8 fichiers modifiés avec 49 ajouts et 6 suppressions
|
@ -3,4 +3,6 @@ package config
|
|||
const (
|
||||
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
|
||||
TorrentFileStorage = ""
|
||||
//disable uploads by default
|
||||
UploadsDisabled = 1
|
||||
)
|
||||
|
|
|
@ -55,6 +55,7 @@ type UserVerifyTemplateVariables struct {
|
|||
|
||||
type UserLoginFormVariables struct {
|
||||
LoginForm userForms.LoginForm
|
||||
FormErrors map[string][]string
|
||||
Search SearchForm
|
||||
Navigation Navigation
|
||||
URL *url.URL // For parsing Url in templates
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/captcha"
|
||||
|
@ -14,6 +15,10 @@ import (
|
|||
)
|
||||
|
||||
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 uploadForm UploadForm
|
||||
if r.Method == "POST" {
|
||||
|
|
|
@ -36,8 +36,10 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
|||
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
b := form.LoginForm{}
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -114,6 +116,26 @@ func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Post Login controller
|
||||
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.
|
||||
type LoginForm struct {
|
||||
Email string `form:"email"`
|
||||
Password string `form:"password"`
|
||||
Username string `form:"username" needed="true"`
|
||||
Password string `form:"password" needed="true"`
|
||||
}
|
||||
|
||||
// UserForm is used when updating a user.
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
"id":"username",
|
||||
"translation": "Username"
|
||||
},
|
||||
{
|
||||
"id":"email_address_or_username",
|
||||
"translation": "Email Address or Username"
|
||||
},
|
||||
{
|
||||
"id":"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) {
|
||||
var form formStruct.LoginForm
|
||||
modelHelper.BindValueForm(&form, r)
|
||||
email := form.Email
|
||||
username := form.Username
|
||||
pass := form.Password
|
||||
status, err := SetCookieHandler(w, email, pass)
|
||||
status, err := SetCookieHandler(w, username, pass)
|
||||
return status, err
|
||||
}
|
||||
|
|
|
@ -8,11 +8,20 @@
|
|||
<fieldset>
|
||||
<h2>{{T "sign_in_box_title"}}</h2>
|
||||
<hr class="colorgraph">
|
||||
{{ range (index $.FormErrors "errors")}}
|
||||
<div class="alert alert-danger">{{ . }}</div>
|
||||
{{end}}
|
||||
<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 class="form-group">
|
||||
<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>
|
||||
<span class="button-checkbox">
|
||||
<button type="button" class="btn hidden" data-color="info">{{ T "remember_me"}}</button>
|
||||
|
|
Référencer dans un nouveau ticket