Add a route for the user settings form: /edit,called UserDetailsHandler
Cette révision appartient à :
Parent
f0a82c52cf
révision
aae25274c1
5 fichiers modifiés avec 44 ajouts et 42 suppressions
1
.gitignore
externe
Fichier normal → Fichier exécutable
1
.gitignore
externe
Fichier normal → Fichier exécutable
|
@ -1,4 +1,5 @@
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
*.db-journal
|
||||||
*.db
|
*.db
|
||||||
*.sql
|
*.sql
|
||||||
main
|
main
|
||||||
|
|
4
router/router.go
Fichier normal → Fichier exécutable
4
router/router.go
Fichier normal → Fichier exécutable
|
@ -37,6 +37,7 @@ func init() {
|
||||||
gzipUserLogoutHandler := handlers.CompressHandler(http.HandlerFunc(UserLogoutHandler))
|
gzipUserLogoutHandler := handlers.CompressHandler(http.HandlerFunc(UserLogoutHandler))
|
||||||
gzipUserProfileHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileHandler))
|
gzipUserProfileHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileHandler))
|
||||||
gzipUserFollowHandler := handlers.CompressHandler(http.HandlerFunc(UserFollowHandler))
|
gzipUserFollowHandler := handlers.CompressHandler(http.HandlerFunc(UserFollowHandler))
|
||||||
|
gzipUserDetailsHandler := handlers.CompressHandler(http.HandlerFunc(UserDetailsHandler))
|
||||||
gzipUserProfileFormHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileFormHandler))
|
gzipUserProfileFormHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileFormHandler))
|
||||||
|
|
||||||
gzipIndexModPanel := handlers.CompressHandler(http.HandlerFunc(IndexModPanel))
|
gzipIndexModPanel := handlers.CompressHandler(http.HandlerFunc(IndexModPanel))
|
||||||
|
@ -81,7 +82,8 @@ func init() {
|
||||||
Router.Handle("/user/logout", gzipUserLogoutHandler).Name("user_logout")
|
Router.Handle("/user/logout", gzipUserLogoutHandler).Name("user_logout")
|
||||||
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileHandler)).Name("user_profile").Methods("GET")
|
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileHandler)).Name("user_profile").Methods("GET")
|
||||||
Router.Handle("/user/{id}/{username}/follow", gzipUserFollowHandler).Name("user_follow").Methods("GET")
|
Router.Handle("/user/{id}/{username}/follow", gzipUserFollowHandler).Name("user_follow").Methods("GET")
|
||||||
Router.Handle("/user/{id}/{username}", wrapHandler(gzipUserProfileFormHandler)).Name("user_profile").Methods("POST")
|
Router.Handle("/user/{id}/{username}/edit", wrapHandler(gzipUserDetailsHandler)).Name("user_profile_details").Methods("GET")
|
||||||
|
Router.Handle("/user/{id}/{username}/edit", wrapHandler(gzipUserProfileFormHandler)).Name("user_profile_edit").Methods("POST")
|
||||||
|
|
||||||
Router.Handle("/mod", gzipIndexModPanel).Name("mod_index")
|
Router.Handle("/mod", gzipIndexModPanel).Name("mod_index")
|
||||||
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
||||||
|
|
|
@ -54,25 +54,12 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
||||||
if errorUser == nil {
|
if errorUser == nil {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
view := r.URL.Query()["edit"]
|
|
||||||
follow := r.URL.Query()["followed"]
|
follow := r.URL.Query()["followed"]
|
||||||
unfollow := r.URL.Query()["unfollowed"]
|
unfollow := r.URL.Query()["unfollowed"]
|
||||||
infosForm := form.NewInfos()
|
infosForm := form.NewInfos()
|
||||||
deleteVar := r.URL.Query()["delete"]
|
deleteVar := r.URL.Query()["delete"]
|
||||||
|
|
||||||
if (view != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
if (deleteVar != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
||||||
b := form.UserForm{}
|
|
||||||
modelHelper.BindValueForm(&b, r)
|
|
||||||
languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us")
|
|
||||||
searchForm := NewSearchForm()
|
|
||||||
searchForm.HideAdvancedSearch = true
|
|
||||||
htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
|
|
||||||
|
|
||||||
err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
} else if (deleteVar != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
|
||||||
err := form.NewErrors()
|
err := form.NewErrors()
|
||||||
_, errUser := userService.DeleteUser(w, currentUser, id)
|
_, errUser := userService.DeleteUser(w, currentUser, id)
|
||||||
if errUser != nil {
|
if errUser != nil {
|
||||||
|
@ -115,6 +102,25 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Getting User Profile Details View
|
||||||
|
func UserDetailsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
id := vars["id"]
|
||||||
|
b := form.UserForm{}
|
||||||
|
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
||||||
|
if errorUser == nil {
|
||||||
|
currentUser := GetUser(r)
|
||||||
|
modelHelper.BindValueForm(&b, r)
|
||||||
|
languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us")
|
||||||
|
searchForm := NewSearchForm()
|
||||||
|
searchForm.HideAdvancedSearch = true
|
||||||
|
htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
|
||||||
|
err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Getting View User Profile Update
|
// Getting View User Profile Update
|
||||||
func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
|
@ -41,18 +41,15 @@
|
||||||
<div class="profile-usermenu">
|
<div class="profile-usermenu">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="#">
|
<a href="{{ genRoute "user_profile" "id" ( print .ID ) "username" .Username }}"><i class="glyphicon glyphicon-home"></i>{{T "torrents"}}</a>
|
||||||
<i class="glyphicon glyphicon-home"></i>
|
|
||||||
{{T "torrents"}} </a>
|
|
||||||
</li>
|
</li>
|
||||||
{{if gt $.User.ID 0 }}
|
{{if gt $.User.ID 0 }}
|
||||||
{{if CurrentOrAdmin $.User .ID }}
|
{{if CurrentOrAdmin $.User .ID }}
|
||||||
<li>
|
<li>
|
||||||
<a href="?edit">
|
<a href="{{ genRoute "user_profile_details" "id" ( print .ID ) "username" .Username }}"><i class="glyphicon glyphicon-user"></i>{{T "settings"}}</a>
|
||||||
<i class="glyphicon glyphicon-user"></i>
|
|
||||||
{{T "settings"}} </a>
|
</li>
|
||||||
</li>
|
{{end}}
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
30
templates/user/profile_edit.html
Fichier normal → Fichier exécutable
30
templates/user/profile_edit.html
Fichier normal → Fichier exécutable
|
@ -23,13 +23,13 @@
|
||||||
<!-- SIDEBAR BUTTONS -->
|
<!-- SIDEBAR BUTTONS -->
|
||||||
<div class="profile-userbuttons">
|
<div class="profile-userbuttons">
|
||||||
{{if gt $.User.ID 0 }}
|
{{if gt $.User.ID 0 }}
|
||||||
{{if not (CurrentUserIdentical $.User .ID) }}
|
{{if not (CurrentUserIdentical $.User .ID) }}
|
||||||
{{if not (IsFollower . $.User)}}
|
{{if not (IsFollower . $.User)}}
|
||||||
<a href="{{ genRoute "user_follow" "id" (print .ID)}}" class="btn btn-success btn-sm">{{ T "follow"}}</a>
|
<a href="{{ genRoute "user_follow" "id" (print .ID) "username" .Username }}" class="btn btn-success btn-sm">{{ T "follow"}}</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{ genRoute "user_follow" "id" (print .ID)}}" class="btn btn-danger btn-sm">{{ T "unfollow"}}</a>
|
<a href="{{ genRoute "user_follow" "id" (print .ID) "username" .Username }}" class="btn btn-danger btn-sm">{{ T "unfollow"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
<!-- <button type="button" class="btn btn-danger btn-sm">Message</button> -->
|
<!-- <button type="button" class="btn btn-danger btn-sm">Message</button> -->
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,18 +38,14 @@
|
||||||
<div class="profile-usermenu">
|
<div class="profile-usermenu">
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li>
|
<li>
|
||||||
<a href="#">
|
<a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}"><i class="glyphicon glyphicon-home"></i>{{T "torrents"}}</a>
|
||||||
<i class="glyphicon glyphicon-home"></i>
|
|
||||||
{{T "torrents"}} </a>
|
|
||||||
</li>
|
</li>
|
||||||
{{if gt $.User.ID 0 }}
|
{{if gt $.User.ID 0 }}
|
||||||
{{if CurrentOrAdmin $.User .ID }}
|
{{if CurrentOrAdmin $.User .ID }}
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<a href="?edit">
|
<a href="{{ genRoute "user_profile_edit" "id" (print .ID) "username" .Username }}"><i class="glyphicon glyphicon-user"></i>{{T "settings"}}</a>
|
||||||
<i class="glyphicon glyphicon-user"></i>
|
</li>
|
||||||
{{T "settings"}} </a>
|
{{end}}
|
||||||
</li>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Référencer dans un nouveau ticket