Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/userHandler.go

92 lignes
3 Kio
Go
Brut Vue normale Historique

package router
2017-05-07 01:20:13 +02:00
import (
"net/http"
"github.com/ewhal/nyaa/service/captcha"
"github.com/ewhal/nyaa/service/user"
"github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/util/languages"
"github.com/ewhal/nyaa/util/modelHelper"
"github.com/gorilla/mux"
)
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
// Getting View User Registration
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
b := form.RegistrationForm{}
modelHelper.BindValueForm(&b, r)
2017-05-07 16:08:45 +02:00
b.CaptchaID = captcha.GetID()
languages.SetTranslation("en-us", viewRegisterTemplate)
2017-05-07 01:20:13 +02:00
htv := UserRegisterTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
2017-05-07 03:00:05 +02:00
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// Getting View User Login
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)}
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// Getting User Profile
func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
}
2017-05-07 01:20:13 +02:00
// Getting View User Profile Update
func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
}
// Post Registration controller, we do some check on the form here, the rest on user service
func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
// Check same Password
if !captcha.Authenticate(captcha.Extract(r)) {
2017-05-07 16:08:45 +02:00
// TODO: Prettier passing of mistyoed captcha errors
http.Error(w, captcha.ErrInvalidCaptcha.Error(), 403)
return
}
if (r.PostFormValue("password") == r.PostFormValue("password_confirm")) && (r.PostFormValue("password") != "") {
2017-05-07 16:08:45 +02:00
if (form.EmailValidation(r.PostFormValue("email"))) &&
(form.ValidateUsername(r.PostFormValue("username"))) &&
(form.IsAgreed(r.PostFormValue("t_and_c"))) {
_, err := userService.CreateUser(w, r)
if err == nil {
b := form.RegistrationForm{}
htv := UserRegisterTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err = viewRegisterSuccessTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
} else {
UserRegisterFormHandler(w, r)
}
} else {
UserRegisterFormHandler(w, r)
}
} else {
UserRegisterFormHandler(w, r)
}
}
// Post Login controller
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
}
// Post Profule Update controller
func UserProfilePostHandler(w http.ResponseWriter, r *http.Request) {
}