Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-08 00:21:31 +02:00
Parent d3de3fb2ee
révision d34823c422
7 fichiers modifiés avec 42 ajouts et 7 suppressions

Voir le fichier

@ -33,7 +33,8 @@ func init() {
Router.HandleFunc("/user/register", UserRegisterFormHandler).Name("user_register").Methods("GET")
Router.HandleFunc("/user/login", UserLoginFormHandler).Name("user_login").Methods("GET")
Router.HandleFunc("/verify/email/{token}", UserVerifyEmailHandler).Name("user_verify").Methods("GET")
Router.HandleFunc("/user/register", UserRegisterPostHandler).Name("user_register").Methods("POST")
Router.HandleFunc("/user/register", UserRegisterPostHandler).Name("user_register_post").Methods("POST")
Router.HandleFunc("/user/login", UserLoginPostHandler).Name("user_login_post").Methods("POST")
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)

Voir le fichier

@ -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

Voir le fichier

@ -37,7 +37,7 @@ func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
b := form.LoginForm{}
modelHelper.BindValueForm(&b, r)
languages.SetTranslation("en-us", viewLoginTemplate)
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 +114,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.SetTranslation("en-us", viewLoginTemplate)
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)
}
}
}

Voir le fichier

@ -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.

Voir le fichier

@ -31,6 +31,10 @@
"id":"username",
"translation": "Username"
},
{
"id":"email_address_or_username",
"translation": "Email Address or Username"
},
{
"id":"email_address",
"translation": "Email Address"

Voir le fichier

@ -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
}

Voir le fichier

@ -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>