Added post method for registration
Don't know if create user work
Cette révision appartient à :
Parent
723135e2e5
révision
6209494c19
7 fichiers modifiés avec 85 ajouts et 13 suppressions
|
@ -29,6 +29,7 @@ func init() {
|
|||
Router.HandleFunc("/feed", RssHandler).Name("feed")
|
||||
Router.HandleFunc("/view/{id}", ViewHandler).Name("view_torrent")
|
||||
Router.HandleFunc("/upload", UploadHandler).Name("upload")
|
||||
Router.HandleFunc("/user/register", UserRegisterFormHandler).Name("user_register")
|
||||
Router.HandleFunc("/user/login", UserLoginFormHandler).Name("user_login")
|
||||
Router.HandleFunc("/user/register", UserRegisterFormHandler).Name("user_register").Methods("GET")
|
||||
Router.HandleFunc("/user/login", UserLoginFormHandler).Name("user_login").Methods("GET")
|
||||
Router.HandleFunc("/user/register", UserRegisterPostHandler).Name("user_register").Methods("POST")
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/service/user/form"
|
||||
"github.com/ewhal/nyaa/service/user"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/ewhal/nyaa/util/languages"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -12,12 +13,14 @@ import (
|
|||
|
||||
var viewRegisterTemplate = template.Must(template.New("userRegister").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.html"))
|
||||
var viewLoginTemplate = template.Must(template.New("userLogin").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/login.html"))
|
||||
var viewRegisterSuccessTemplate = template.Must(template.New("userRegisterSuccess").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/signup_success.html"))
|
||||
//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"))
|
||||
|
||||
func init() {
|
||||
template.Must(viewRegisterTemplate.ParseGlob("templates/_*.html"))
|
||||
template.Must(viewLoginTemplate.ParseGlob("templates/_*.html"))
|
||||
template.Must(viewRegisterSuccessTemplate.ParseGlob("templates/_*.html"))
|
||||
}
|
||||
|
||||
// Getting View User Registration
|
||||
|
@ -57,7 +60,26 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Post Registration controller
|
||||
func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Check same Password
|
||||
if ((r.PostFormValue("password") == r.PostFormValue("password_confirm"))&&(r.PostFormValue("password") != "")) {
|
||||
if ((form.EmailValidation(r.PostFormValue("email")))&&(form.ValidateUsername(r.PostFormValue("username")))) {
|
||||
_ , 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
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
)
|
||||
|
||||
const EMAIL_REGEX = `(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})`
|
||||
const USERNAME_REGEX = `(\W)`
|
||||
|
||||
func EmailValidation(email string) bool {
|
||||
exp, err := regexp.Compile(EMAIL_REGEX)
|
||||
|
@ -16,18 +17,37 @@ func EmailValidation(email string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
func ValidateUsername(username string) bool {
|
||||
exp, err := regexp.Compile(USERNAME_REGEX)
|
||||
|
||||
if (username == "") {
|
||||
return false;
|
||||
|
||||
}
|
||||
if ((len(username) < 3) || (len(username) > 15)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
if regexpCompiled := log.CheckError(err); regexpCompiled {
|
||||
if exp.MatchString(username) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
// RegistrationForm is used when creating a user.
|
||||
type RegistrationForm struct {
|
||||
Username string `form:"registrationUsername" binding:"required"`
|
||||
Email string `form:"registrationEmail" binding:"required"`
|
||||
Password string `form:"registrationPassword" binding:"required"`
|
||||
Username string `form:"username" binding:"required"`
|
||||
Email string `form:"email" binding:"required"`
|
||||
Password string `form:"password" binding:"required"`
|
||||
}
|
||||
|
||||
// RegistrationForm is used when creating a user authentication.
|
||||
type LoginForm struct {
|
||||
Email string `form:"loginEmail" binding:"required"`
|
||||
Password string `form:"loginPassword" binding:"required"`
|
||||
Email string `form:"email" binding:"required"`
|
||||
Password string `form:"password" binding:"required"`
|
||||
}
|
||||
|
||||
// UserForm is used when updating a user.
|
||||
|
|
|
@ -82,5 +82,17 @@
|
|||
{
|
||||
"id":"sign_in_title",
|
||||
"translation": "Sign In"
|
||||
},
|
||||
{
|
||||
"id":"register_success_title",
|
||||
"translation": "Sign Up Successful"
|
||||
},
|
||||
{
|
||||
"id":"sign_up_success",
|
||||
"translation": "Almost Signed Up!"
|
||||
},
|
||||
{
|
||||
"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!"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<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">
|
||||
<form role="form">
|
||||
<form role="form" method="POST">
|
||||
<fieldset>
|
||||
<h2>{{T "sign_in_box_title"}}</h2>
|
||||
<hr class="colorgraph">
|
||||
|
|
|
@ -4,19 +4,20 @@
|
|||
<div class="blockBody">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
|
||||
<form role="form">
|
||||
{{ with .RegistrationForm }}
|
||||
<form role="form" method="POST">
|
||||
<h2>{{T "signup_box_title" }}</h2>
|
||||
<hr class="colorgraph">
|
||||
<div class="form-group">
|
||||
<input type="text" name="username" id="display_name" class="form-control input-lg" placeholder="{{T "username" }}" tabindex="1">
|
||||
<input type="text" name="username" id="display_name" class="form-control input-lg" placeholder="{{T "username" }}" tabindex="1" value="{{ .Username }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="{{T "email_address" }}" tabindex="2">
|
||||
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="{{T "email_address" }}" tabindex="2" value="{{ .Email }}">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6 col-md-6">
|
||||
<div class="form-group">
|
||||
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="{{T "password" }}" tabindex="3">
|
||||
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="{{T "password" }}" tabindex="3" value="{{ .Password }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6 col-md-6">
|
||||
|
@ -43,6 +44,7 @@
|
|||
<div class="col-xs-12 col-md-6">or <a href="{{ genRoute "user_login" }}" class="">{{T "signin" }}</a></div>
|
||||
</div>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal -->
|
||||
|
|
15
templates/user/signup_success.html
Fichier normal
15
templates/user/signup_success.html
Fichier normal
|
@ -0,0 +1,15 @@
|
|||
{{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 "sign_up_success"}}</h2>
|
||||
<hr class="colorgraph">
|
||||
<p>{{ T "signup_verification_email" }}</p>
|
||||
</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