Added verify email view and route
Now you should be able to register and activate your account
Cette révision appartient à :
Parent
830c824fbc
révision
04a17db739
7 fichiers modifiés avec 68 ajouts et 21 suppressions
|
@ -32,6 +32,7 @@ func init() {
|
|||
Router.HandleFunc("/upload", UploadHandler).Name("upload")
|
||||
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.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
var TemplateDir = "templates"
|
||||
|
||||
var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate *template.Template
|
||||
var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate *template.Template
|
||||
|
||||
type templateLoader struct {
|
||||
templ **template.Template
|
||||
|
@ -53,6 +53,11 @@ func ReloadTemplates() {
|
|||
name: "user_register_success",
|
||||
file: "user/signup_success.html",
|
||||
},
|
||||
templateLoader{
|
||||
templ: &viewVerifySuccessTemplate,
|
||||
name: "user_verify_success",
|
||||
file: "user/verify_success.html",
|
||||
},
|
||||
templateLoader{
|
||||
templ: &viewLoginTemplate,
|
||||
name: "user_login",
|
||||
|
|
|
@ -45,6 +45,14 @@ type UserRegisterTemplateVariables struct {
|
|||
Route *mux.Route // For getting current route in templates
|
||||
}
|
||||
|
||||
type UserVerifyTemplateVariables struct {
|
||||
FormErrors map[string][]string
|
||||
Search SearchForm
|
||||
Navigation Navigation
|
||||
URL *url.URL // For parsing Url in templates
|
||||
Route *mux.Route // For getting current route in templates
|
||||
}
|
||||
|
||||
type UserLoginFormVariables struct {
|
||||
LoginForm userForms.LoginForm
|
||||
Search SearchForm
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/ewhal/nyaa/service/user"
|
||||
"github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/ewhal/nyaa/util/languages"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -17,14 +16,19 @@ import (
|
|||
|
||||
// Getting View User Registration
|
||||
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
b := form.RegistrationForm{}
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
b.CaptchaID = captcha.GetID()
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
htv := UserRegisterTemplateVariables{b, form.NewErrors(), NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
_, errorUser := userService.CurrentUser(r)
|
||||
if (errorUser != nil) {
|
||||
b := form.RegistrationForm{}
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
b.CaptchaID = captcha.GetID()
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
htv := UserRegisterTemplateVariables{b, form.NewErrors(), NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
HomeHandler(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,17 +65,14 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if (len(err) == 0) {
|
||||
_, err = form.EmailValidation(r.PostFormValue("email"), err)
|
||||
_, err = form.ValidateUsername(r.PostFormValue("username"), err)
|
||||
log.Info("test lets see 3")
|
||||
if (len(err) == 0) {
|
||||
modelHelper.BindValueForm(&b, r)
|
||||
err = modelHelper.ValidateForm(&b, err)
|
||||
log.Info("test lets see 1")
|
||||
if (len(err) == 0) {
|
||||
_, errorUser := userService.CreateUser(w, r)
|
||||
if (errorUser != nil) {
|
||||
err["errors"] = append(err["errors"], errorUser.Error())
|
||||
}
|
||||
log.Info("test lets see 2")
|
||||
if (len(err) == 0) {
|
||||
b := form.RegistrationForm{}
|
||||
languages.SetTranslation("en-us", viewRegisterSuccessTemplate)
|
||||
|
@ -85,7 +86,6 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
if (len(err) > 0) {
|
||||
log.Info("test lets see 4")
|
||||
b.CaptchaID = captcha.GetID()
|
||||
languages.SetTranslation("en-us", viewRegisterTemplate)
|
||||
htv := UserRegisterTemplateVariables{b, err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
|
@ -96,6 +96,22 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
token := vars["token"]
|
||||
err := form.NewErrors()
|
||||
_, errEmail := userService.EmailVerification(token, w)
|
||||
if (errEmail != nil) {
|
||||
err["errors"] = append(err["errors"], errEmail.Error())
|
||||
}
|
||||
languages.SetTranslation("en-us", viewVerifySuccessTemplate)
|
||||
htv := UserVerifyTemplateVariables{err, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
|
||||
errorTmpl := viewVerifySuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||
if errorTmpl != nil {
|
||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// Post Login controller
|
||||
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
|
|
@ -91,6 +91,10 @@
|
|||
"id":"sign_up_success",
|
||||
"translation": "Almost Signed Up!"
|
||||
},
|
||||
{
|
||||
"id":"verify_success",
|
||||
"translation": "<i style=\"color:limegreen\" class=\"glyphicon glyphicon-ok-circle\"></i>Your account is now activated!"
|
||||
},
|
||||
{
|
||||
"id":"signup_verification_email",
|
||||
"translation": "Now, you are one step left before being part of our community! Check your emails (inbox or spam folder) and click the link provided for activating your account!"
|
||||
|
|
|
@ -8,12 +8,10 @@ import (
|
|||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/ewhal/nyaa/util/crypto"
|
||||
"github.com/ewhal/nyaa/util/email"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/util/timeHelper"
|
||||
formStruct "github.com/ewhal/nyaa/service/user/form"
|
||||
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
@ -66,12 +64,10 @@ func SendVerification(r *http.Request) (int, error) {
|
|||
}
|
||||
|
||||
// EmailVerification verifies an email of user.
|
||||
func EmailVerification(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
func EmailVerification(token string,w http.ResponseWriter) (int, error) {
|
||||
var user model.User
|
||||
var verifyEmailForm formStruct.VerifyEmailForm
|
||||
modelHelper.BindValueForm(&verifyEmailForm, r)
|
||||
log.Debugf("verifyEmailForm.ActivationToken : %s", verifyEmailForm.ActivationToken)
|
||||
if db.ORM.Where(&model.User{ActivationToken: verifyEmailForm.ActivationToken}).First(&user).RecordNotFound() {
|
||||
log.Debugf("verifyEmailForm.ActivationToken : %s", token)
|
||||
if db.ORM.Where(&model.User{ActivationToken: token}).First(&user).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("User is not found.")
|
||||
}
|
||||
isExpired := timeHelper.IsExpired(user.ActivateUntil)
|
||||
|
|
17
templates/user/verify_success.html
Fichier normal
17
templates/user/verify_success.html
Fichier normal
|
@ -0,0 +1,17 @@
|
|||
{{define "title"}}{{ T "register_success_title" }}{{end}}
|
||||
{{define "contclass"}}cont-view{{end}}
|
||||
{{define "content"}}
|
||||
<div class="blockBody">
|
||||
<div class="row" style="margin-top:20px">
|
||||
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
|
||||
|
||||
<h2>{{T "verify_success"}}</h2>
|
||||
<hr class="colorgraph">
|
||||
{{ range (index $.FormErrors "errors")}}
|
||||
<div class="alert alert-danger">{{ . }}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{define "js_footer"}}<script type="text/javascript" charset="utf-8" src="{{.URL.Parse "/js/registerPage.js"}}"></script>{{end}}
|
Référencer dans un nouveau ticket