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
|
||||
*.db-journal
|
||||
*.db
|
||||
*.sql
|
||||
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))
|
||||
gzipUserProfileHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileHandler))
|
||||
gzipUserFollowHandler := handlers.CompressHandler(http.HandlerFunc(UserFollowHandler))
|
||||
gzipUserDetailsHandler := handlers.CompressHandler(http.HandlerFunc(UserDetailsHandler))
|
||||
gzipUserProfileFormHandler := handlers.CompressHandler(http.HandlerFunc(UserProfileFormHandler))
|
||||
|
||||
gzipIndexModPanel := handlers.CompressHandler(http.HandlerFunc(IndexModPanel))
|
||||
|
@ -81,7 +82,8 @@ func init() {
|
|||
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}/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/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
||||
|
|
|
@ -54,25 +54,12 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
||||
if errorUser == nil {
|
||||
currentUser := GetUser(r)
|
||||
view := r.URL.Query()["edit"]
|
||||
follow := r.URL.Query()["followed"]
|
||||
unfollow := r.URL.Query()["unfollowed"]
|
||||
infosForm := form.NewInfos()
|
||||
deleteVar := r.URL.Query()["delete"]
|
||||
|
||||
if (view != 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)) {
|
||||
if (deleteVar != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
||||
err := form.NewErrors()
|
||||
_, errUser := userService.DeleteUser(w, currentUser, id)
|
||||
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
|
||||
func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
|
|
@ -41,16 +41,13 @@
|
|||
<div class="profile-usermenu">
|
||||
<ul class="nav">
|
||||
<li class="active">
|
||||
<a href="#">
|
||||
<i class="glyphicon glyphicon-home"></i>
|
||||
{{T "torrents"}} </a>
|
||||
<a href="{{ genRoute "user_profile" "id" ( print .ID ) "username" .Username }}"><i class="glyphicon glyphicon-home"></i>{{T "torrents"}}</a>
|
||||
</li>
|
||||
{{if gt $.User.ID 0 }}
|
||||
{{if CurrentOrAdmin $.User .ID }}
|
||||
<li>
|
||||
<a href="?edit">
|
||||
<i class="glyphicon glyphicon-user"></i>
|
||||
{{T "settings"}} </a>
|
||||
<a href="{{ genRoute "user_profile_details" "id" ( print .ID ) "username" .Username }}"><i class="glyphicon glyphicon-user"></i>{{T "settings"}}</a>
|
||||
|
||||
</li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
12
templates/user/profile_edit.html
Fichier normal → Fichier exécutable
12
templates/user/profile_edit.html
Fichier normal → Fichier exécutable
|
@ -25,9 +25,9 @@
|
|||
{{if gt $.User.ID 0 }}
|
||||
{{if not (CurrentUserIdentical $.User .ID) }}
|
||||
{{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}}
|
||||
<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}}
|
||||
|
@ -38,16 +38,12 @@
|
|||
<div class="profile-usermenu">
|
||||
<ul class="nav">
|
||||
<li>
|
||||
<a href="#">
|
||||
<i class="glyphicon glyphicon-home"></i>
|
||||
{{T "torrents"}} </a>
|
||||
<a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}"><i class="glyphicon glyphicon-home"></i>{{T "torrents"}}</a>
|
||||
</li>
|
||||
{{if gt $.User.ID 0 }}
|
||||
{{if CurrentOrAdmin $.User .ID }}
|
||||
<li class="active">
|
||||
<a href="?edit">
|
||||
<i class="glyphicon glyphicon-user"></i>
|
||||
{{T "settings"}} </a>
|
||||
<a href="{{ genRoute "user_profile_edit" "id" (print .ID) "username" .Username }}"><i class="glyphicon glyphicon-user"></i>{{T "settings"}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
Référencer dans un nouveau ticket