Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Added User Registration View

Moved public files in public folder
Cette révision appartient à :
akuma06 2017-05-07 00:10:40 +02:00
Parent 9aafa6befa
révision 052c502b07
31 fichiers modifiés avec 111 ajouts et 22 suppressions

Voir le fichier

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 4,6 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 4,6 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 15 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 15 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 16 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 16 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,4 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,4 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,4 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,4 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,9 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,9 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,8 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,8 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,3 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,3 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 4,1 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 4,1 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 4,1 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 4,1 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,8 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,8 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,3 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,3 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,6 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,6 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,2 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,2 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,9 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,9 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,7 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,7 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 2,5 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 2,5 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 4,5 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 4,5 Kio

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 3,1 Kio

Après

Largeur:  |  Hauteur:  |  Taille: 3,1 Kio

Voir le fichier

Voir le fichier

@ -11,12 +11,12 @@ var Router *mux.Router
func init() {
Router = mux.NewRouter()
cssHandler := http.FileServer(http.Dir("./css/"))
jsHandler := http.FileServer(http.Dir("./js/"))
imgHandler := http.FileServer(http.Dir("./img/"))
http.Handle("/css/", http.StripPrefix("/css/", cssHandler))
http.Handle("/js/", http.StripPrefix("/js/", jsHandler))
http.Handle("/img/", http.StripPrefix("/img/", imgHandler))
cssHandler := http.FileServer(http.Dir("./static/css/"))
jsHandler := http.FileServer(http.Dir("./static/js/"))
imgHandler := http.FileServer(http.Dir("./static/img/"))
http.Handle("/css/", http.StripPrefix("/static/css/", cssHandler))
http.Handle("/js/", http.StripPrefix("/static/js/", jsHandler))
http.Handle("/img/", http.StripPrefix("/static/img/", imgHandler))
// Routes,
Router.HandleFunc("/", HomeHandler).Name("home")
@ -29,4 +29,5 @@ 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")
}

Voir le fichier

@ -5,6 +5,7 @@ import (
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/templates"
userForms "github.com/ewhal/nyaa/service/user/form"
"github.com/gorilla/mux"
)
@ -29,6 +30,14 @@ type ViewTemplateVariables struct {
Route *mux.Route // For getting current route in templates
}
type UserRegisterTemplateVariables struct {
RegistrationForm userForms.RegistrationForm
Search templates.SearchForm
Navigation templates.Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type HomeTemplateVariables struct {
ListTorrents []model.TorrentsJson
ListCategories []model.Categories

Voir le fichier

@ -1,18 +1,30 @@
package router
import(
// "github.com/gorilla/mux"
"html/template"
"net/http"
// "html"
// "strconv"
// "github.com/ewhal/nyaa/model"
// "github.com/ewhal/nyaa/service/user"
"github.com/ewhal/nyaa/templates"
"github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/util/modelHelper"
"github.com/gorilla/mux"
)
var viewRegisterTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.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"))
// Getting View User Registration
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
b := form.RegistrationForm{}
modelHelper.BindValueForm(b, r)
htv := UserRegisterTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
err := viewTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
// Getting View User Login

Voir le fichier

@ -116,7 +116,7 @@ func SetCookieHandler(w http.ResponseWriter, email string, pass string) (int, er
}
// RegisterHanderFromForm sets cookie from a RegistrationForm.
func RegisterHanderFromForm(w http.ResponseWriter, registrationForm RegistrationForm) (int, error) {
func RegisterHanderFromForm(w http.ResponseWriter, registrationForm formStruct.RegistrationForm) (int, error) {
email := registrationForm.Email
pass := registrationForm.Password
log.Debugf("RegisterHandler UserEmail : %s", email)
@ -126,7 +126,7 @@ func RegisterHanderFromForm(w http.ResponseWriter, registrationForm Registration
// RegisterHandler sets a cookie when user registered.
func RegisterHandler(w http.ResponseWriter, r *http.Request) (int, error) {
var registrationForm RegistrationForm
var registrationForm formStruct.RegistrationForm
modelHelper.BindValueForm(&registrationForm, r)
return RegisterHanderFromForm(w, registrationForm)
}

Voir le fichier

@ -1,4 +1,4 @@
package userService
package form
import (
"regexp"

Voir le fichier

@ -10,6 +10,7 @@ import (
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/model"
formStruct "github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/util/crypto"
"github.com/ewhal/nyaa/util/log"
"github.com/ewhal/nyaa/util/modelHelper"
@ -43,7 +44,7 @@ func SuggestUsername(username string) string {
}
// CreateUserFromForm creates a user from a registration form.
func CreateUserFromForm(registrationForm RegistrationForm) (model.User, error) {
func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.User, error) {
var user model.User
log.Debugf("registrationForm %+v\n", registrationForm)
modelHelper.AssignValue(&user, &registrationForm)
@ -64,7 +65,7 @@ func CreateUserFromForm(registrationForm RegistrationForm) (model.User, error) {
// CreateUser creates a user.
func CreateUser(w http.ResponseWriter, r *http.Request) (int, error) {
var user model.User
var registrationForm RegistrationForm
var registrationForm formStruct.RegistrationForm
var status int
var err error
@ -161,7 +162,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request, id string) (*model.User,
}
switch r.FormValue("type") {
case "password":
var passwordForm PasswordForm
var passwordForm formStruct.PasswordForm
modelHelper.BindValueForm(&passwordForm, r)
log.Debugf("form %+v\n", passwordForm)
err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(passwordForm.CurrentPassword))
@ -178,7 +179,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request, id string) (*model.User,
}
}
default:
var form UserForm
var form formStruct.UserForm
modelHelper.BindValueForm(&form, r)
log.Debugf("form %+v\n", form)
modelHelper.AssignValue(&user, &form)
@ -207,7 +208,7 @@ func DeleteUser(w http.ResponseWriter, id string) (int, error) {
// AddRoleToUser adds a role to a user.
func AddRoleToUser(r *http.Request) (int, error) {
var form UserRoleForm
var form formStruct.UserRoleForm
var user model.User
var role model.Role
var roles []model.Role
@ -313,7 +314,7 @@ func RetrieveUsersForAdmin() []model.User {
// ActivateUser toggle activation of a user.
func ActivateUser(r *http.Request, id string) (model.User, int, error) {
var user model.User
var form ActivateForm
var form formStruct.ActivateForm
modelHelper.BindValueForm(&form, r)
if db.ORM.First(&user, id).RecordNotFound() {
return user, http.StatusNotFound, errors.New("User is not found.")
@ -327,7 +328,7 @@ func ActivateUser(r *http.Request, id string) (model.User, int, error) {
// CreateUserAuthentication creates user authentication.
func CreateUserAuthentication(w http.ResponseWriter, r *http.Request) (int, error) {
var form LoginForm
var form formStruct.LoginForm
modelHelper.BindValueForm(&form, r)
email := form.Email
pass := form.Password

Voir le fichier

@ -67,7 +67,7 @@ func SendVerification(r *http.Request) (int, error) {
// EmailVerification verifies an email of user.
func EmailVerification(w http.ResponseWriter, r *http.Request) (int, error) {
var user model.User
var verifyEmailForm VerifyEmailForm
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() {

66
templates/user/register.html Fichier normal
Voir le fichier

@ -0,0 +1,66 @@
{{define "title"}}{{.Torrent.Name}}{{end}}
{{define "contclass"}}cont-view{{end}}
{{define "content"}}
<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">
<h2>Please Sign Up <small>It's free and always will be.</small></h2>
<hr class="colorgraph">
<div class="form-group">
<input type="text" name="username" id="display_name" class="form-control input-lg" placeholder="Display Name" tabindex="3">
</div>
<div class="form-group">
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address" tabindex="4">
</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="Password" tabindex="5">
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-lg" placeholder="Confirm Password" tabindex="6">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-4 col-sm-3 col-md-3">
<span class="button-checkbox">
<button type="button" class="btn" data-color="info" tabindex="7">I Agree</button>
<input type="checkbox" name="t_and_c" id="t_and_c" class="hidden" value="1">
</span>
</div>
<div class="col-xs-8 col-sm-9 col-md-9">
By clicking <strong class="label label-primary">Register</strong>, you agree to the <a href="#" data-toggle="modal" data-target="#t_and_c_m">Terms and Conditions</a> set out by this site, including our Cookie Use.
</div>
</div>
<hr class="colorgraph">
<div class="row">
<div class="col-xs-12 col-md-6"><input type="submit" value="Register" class="btn btn-primary btn-block btn-lg" tabindex="7"></div>
<div class="col-xs-12 col-md-6">or <a href="#" class="">Sign In</a></div>
</div>
</form>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="t_and_c_m" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Terms & Conditions</h4>
</div>
<div class="modal-body">
<p>Some shit.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">I Agree</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
{{end}}