From e3a271cca7e4a51419bc9adc5408af2f1658bd52 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 8 May 2017 22:50:25 +0200 Subject: [PATCH] Revert "Added Profile page" This reverts commit 5860cf1d79cc0a05e301483688d0249acaf72482. --- model/torrent.go | 1 - model/user.go | 22 +++--- public/css/style.css | 105 -------------------------- router/template.go | 7 +- router/templateFunctions.go | 6 -- router/templateVariables.go | 30 +++----- router/userHandler.go | 19 ----- service/user/locale/en-us.all.json | 20 ----- service/user/permission/permission.go | 15 +++- service/user/user.go | 4 +- templates/_badgemenu.html | 2 +- templates/_user_list_torrents.html | 48 ------------ templates/user/profile.html | 62 --------------- util/languages/translation.go | 5 +- 14 files changed, 38 insertions(+), 308 deletions(-) delete mode 100644 templates/_user_list_torrents.html delete mode 100644 templates/user/profile.html diff --git a/model/torrent.go b/model/torrent.go index 68c654a8..e3ab1c1e 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -31,7 +31,6 @@ type Torrents struct { Downloads int `gorm:"column:downloads"` Filesize int64 `gorm:"column:filesize"` Description string `gorm:"column:description"` - OwnerId int `gorm:"column:owner_id"` OldComments []byte `gorm:"column:comments"` Comments []Comment `gorm:"ForeignKey:TorrentId"` } diff --git a/model/user.go b/model/user.go index e67ec74b..3a041fcc 100644 --- a/model/user.go +++ b/model/user.go @@ -11,10 +11,10 @@ type omit bool type User struct { Id uint `json:"id"` - Email string `json:"email" sql:"size:255;unique"` - Password string `json:"password" sql:"size:255"` - Username string `json:"username" sql:"size:255;unique"` - Description string `json:"description" sql:"size:100"` + Email string `json:"email",sql:"size:255;unique"` + Password string `json:"password",sql:"size:255"` + Username string `json:"username",sql:"size:255;unique"` + Description string `json:"description",sql:"size:100"` Token string `json:"token"` TokenExpiration time.Time `json:"tokenExperiation"` @@ -33,8 +33,8 @@ type User struct { DeletedAt *time.Time `json:"deletedAt"` LastLoginAt time.Time `json:"lastLoginAt"` CurrentLoginAt time.Time `json:"currentLoginAt"` - LastLoginIp string `json:"lastLoginIp" sql:"size:100"` - CurrentLoginIp string `json:"currentLoginIp" sql:"size:100"` + LastLoginIp string `json:"lastLoginIp",sql:"size:100"` + CurrentLoginIp string `json:"currentLoginIp",sql:"size:100"` // Liking LikingCount int `json:"likingCount"` @@ -46,7 +46,7 @@ type User struct { Languages string Roles []Role `gorm:"many2many:users_roles;"` // Many To Many, users_roles - Torrents []Torrents `gorm:"ForeignKey:owner_id"` + Torrents []Torrents } // UsersFollowers is a relation table to relate users each other. @@ -58,8 +58,8 @@ type UsersFollowers struct { // PublicUser is a public user model that contains only a few information for everyone. type PublicUser struct { *User - Email omit `json:"email,omitempty" sql:"size:255;unique"` - Password omit `json:"password,omitempty" sql:"size:255"` + Email omit `json:"email,omitempty",sql:"size:255;unique"` + Password omit `json:"password,omitempty",sql:"size:255"` Token omit `json:"token,omitempty"` TokenExpiration omit `json:"tokenExperiation,omitempty"` @@ -74,8 +74,8 @@ type PublicUser struct { DeletedAt omit `json:"deletedAt,omitempty"` LastLoginAt omit `json:"lastLoginAt,omitempty"` CurrentLoginAt omit `json:"currentLoginAt,omitempty"` - LastLoginIp omit `json:"lastLoginIp,omitempty" sql:"size:100"` - CurrentLoginIp omit `json:"currentLoginIp,omitempty" sql:"size:100"` + LastLoginIp omit `json:"lastLoginIp,omitempty",sql:"size:100"` + CurrentLoginIp omit `json:"currentLoginIp,omitempty",sql:"size:100"` //Connections omit `json:"connections,omitempty"` Languages omit `json:"languages,omitempty"` diff --git a/public/css/style.css b/public/css/style.css index df22d219..14f84911 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -217,109 +217,4 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ #mainmenu .badgemenu { padding-top: 0; -} - -/* PROFILE PAGE */ -/* Profile container */ -.profile { - margin: 20px 0; -} - -/* Profile sidebar */ -.profile-sidebar { - padding: 20px 0 10px 0; - background: #182430; -} - -.profile-userpic img { - float: none; - margin: 0 auto; - width: 50%; - height: 50%; - -webkit-border-radius: 50% !important; - -moz-border-radius: 50% !important; - border-radius: 50% !important; -} - -.profile-usertitle { - text-align: center; - margin-top: 20px; -} - -.profile-usertitle-name { - color: #5a7391; - font-size: 16px; - font-weight: 600; - margin-bottom: 7px; -} - -.profile-usertitle-job { - text-transform: uppercase; - color: #5b9bd1; - font-size: 12px; - font-weight: 600; - margin-bottom: 15px; -} - -.profile-userbuttons { - text-align: center; - margin-top: 10px; -} - -.profile-userbuttons .btn { - text-transform: uppercase; - font-size: 11px; - font-weight: 600; - padding: 6px 15px; - margin-right: 5px; -} - -.profile-userbuttons .btn:last-child { - margin-right: 0px; -} - -.profile-usermenu { - margin-top: 30px; -} - -.profile-usermenu ul li { - border-bottom: 1px solid #f0f4f7; -} - -.profile-usermenu ul li:last-child { - border-bottom: none; -} - -.profile-usermenu ul li a { - color: #93a3b5; - font-size: 14px; - font-weight: 400; -} - -.profile-usermenu ul li a i { - margin-right: 8px; - font-size: 14px; -} - -.profile-usermenu ul li a:hover { - background-color: #fafcfd; - color: #5b9bd1; -} - -.profile-usermenu ul li.active { - border-bottom: none; -} - -.profile-usermenu ul li.active a { - color: #5b9bd1; - background-color: #f6f9fb; - border-left: 2px solid #5b9bd1; - margin-left: -2px; -} - -/* Profile Content */ -.profile-content { - padding: 20px; - background: #fff; - min-height: 460px; } \ No newline at end of file diff --git a/router/template.go b/router/template.go index 4a26fdb4..678a4ab2 100644 --- a/router/template.go +++ b/router/template.go @@ -7,7 +7,7 @@ import ( var TemplateDir = "templates" -var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate, viewProfileTemplate *template.Template +var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate *template.Template type templateLoader struct { templ **template.Template @@ -63,11 +63,6 @@ func ReloadTemplates() { name: "user_login", file: "user/login.html", }, - templateLoader{ - templ: &viewProfileTemplate, - name: "user_profile", - file: "user/profile.html", - }, } for _, templ := range templs { t := template.Must(template.New(templ.name).Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "index.html"), filepath.Join(TemplateDir, templ.file))) diff --git a/router/templateFunctions.go b/router/templateFunctions.go index be7a5d9d..67536f61 100644 --- a/router/templateFunctions.go +++ b/router/templateFunctions.go @@ -7,7 +7,6 @@ import ( "net/url" "strconv" "github.com/nicksnyder/go-i18n/i18n" - "github.com/ewhal/nyaa/service/user/permission" ) var FuncMap = template.FuncMap{ @@ -60,9 +59,4 @@ var FuncMap = template.FuncMap{ return template.HTML(ret) }, "T": i18n.IdentityTfunc, - "getAvatar": func (hash string, size int) string { - return "https://www.gravatar.com/avatar/"+hash+"?s="+strconv.Itoa(size) - }, - "CurrentOrAdmin": userPermission.CurrentOrAdmin, - "CurrentUserIdentical": userPermission.CurrentUserIdentical, } diff --git a/router/templateVariables.go b/router/templateVariables.go index 9edccc65..e73bcf15 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -20,7 +20,7 @@ import ( type FaqTemplateVariables struct { Navigation Navigation Search SearchForm - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -28,7 +28,7 @@ type FaqTemplateVariables struct { type NotFoundTemplateVariables struct { Navigation Navigation Search SearchForm - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -38,7 +38,7 @@ type ViewTemplateVariables struct { Captcha captcha.Captcha Search SearchForm Navigation Navigation - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -48,7 +48,7 @@ type UserRegisterTemplateVariables struct { FormErrors map[string][]string Search SearchForm Navigation Navigation - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -57,7 +57,7 @@ type UserVerifyTemplateVariables struct { FormErrors map[string][]string Search SearchForm Navigation Navigation - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -67,17 +67,7 @@ type UserLoginFormVariables struct { FormErrors map[string][]string Search SearchForm Navigation Navigation - User *model.User - URL *url.URL // For parsing Url in templates - Route *mux.Route // For getting current route in templates -} - -type UserProfileVariables struct { - UserProfile *model.User - FormErrors map[string][]string - Search SearchForm - Navigation Navigation - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -86,7 +76,7 @@ type HomeTemplateVariables struct { ListTorrents []model.TorrentsJson Search SearchForm Navigation Navigation - User *model.User + User model.User URL *url.URL // For parsing Url in templates Route *mux.Route // For getting current route in templates } @@ -95,7 +85,7 @@ type UploadTemplateVariables struct { Upload UploadForm Search SearchForm Navigation Navigation - User *model.User + User model.User URL *url.URL Route *mux.Route } @@ -146,7 +136,7 @@ func NewSearchForm(params ...string) (searchForm SearchForm) { return } -func GetUser(r *http.Request) *model.User { +func GetUser(r *http.Request) model.User { user, _ , _ := userService.RetrieveCurrentUser(r) - return &user + return user } diff --git a/router/userHandler.go b/router/userHandler.go index 482041de..862db76b 100644 --- a/router/userHandler.go +++ b/router/userHandler.go @@ -5,7 +5,6 @@ import ( "github.com/ewhal/nyaa/service/captcha" "github.com/ewhal/nyaa/service/user" - "github.com/ewhal/nyaa/service/user/permission" "github.com/ewhal/nyaa/service/user/form" "github.com/ewhal/nyaa/util/languages" "github.com/ewhal/nyaa/util/modelHelper" @@ -49,25 +48,7 @@ func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) { // Getting User Profile func UserProfileHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - id := vars["id"] - userProfile, _, errorUser := userService.RetrieveUserForAdmin(id) - currentUser := GetUser(r) - view := r.URL.Query().Get("view") - if (errorUser == nil) { - if ((view == "edit")&&(userPermission.CurrentOrAdmin(currentUser, userProfile.Id))) { - } else { - languages.SetTranslationFromRequest(viewProfileTemplate, r, "en-us") - htv := UserProfileVariables{&userProfile, form.NewErrors(), NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} - err := viewProfileTemplate.ExecuteTemplate(w, "index.html", htv) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - } - } else { - NotFoundHandler(w, r) - } } // Getting View User Profile Update diff --git a/service/user/locale/en-us.all.json b/service/user/locale/en-us.all.json index 1998a873..df97f877 100644 --- a/service/user/locale/en-us.all.json +++ b/service/user/locale/en-us.all.json @@ -102,25 +102,5 @@ { "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!" - }, - { - "id":"settings", - "translation": "Account Settings" - }, - { - "id":"torrents", - "translation": "Torrents" - }, - { - "id":"follow", - "translation": "Follow" - }, - { - "id":"profile_page", - "translation": "%s Profile Page" - }, - { - "id":"see_more_torrents_from", - "translation": "See more torrents from %s " } ] diff --git a/service/user/permission/permission.go b/service/user/permission/permission.go index 312d1cf3..2bc83650 100644 --- a/service/user/permission/permission.go +++ b/service/user/permission/permission.go @@ -1,7 +1,10 @@ package userPermission import ( + "errors" + "net/http" "github.com/ewhal/nyaa/model" + "github.com/ewhal/nyaa/service/user" "github.com/ewhal/nyaa/util/log" ) @@ -24,10 +27,14 @@ func CurrentOrAdmin(user *model.User, userId uint) bool { } // CurrentUserIdentical check that userId is same as current user's Id. -func CurrentUserIdentical(user *model.User, userId uint) (bool) { - if user.Id != userId { - return false +func CurrentUserIdentical(r *http.Request, userId uint) (bool, error) { + currentUser, err := userService.CurrentUser(r) + if err != nil { + return false, errors.New("Auth failed.") + } + if currentUser.Id != userId { + return false, errors.New("User is not identical.") } - return true + return true, nil } diff --git a/service/user/user.go b/service/user/user.go index f38ee335..24645344 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -307,7 +307,7 @@ func RetrieveUserForAdmin(id string) (model.User, int, error) { if db.ORM.First(&user, id).RecordNotFound() { return user, http.StatusNotFound, errors.New("User is not found.") } - db.ORM.Model(&user).Related("Torrents").Find(&model.Torrents{}) + db.ORM.Model(&user).Association("Languages").Find(&user.Languages) db.ORM.Model(&user).Association("Roles").Find(&user.Roles) return user, http.StatusOK, nil } @@ -318,7 +318,7 @@ func RetrieveUsersForAdmin() []model.User { var userArr []model.User db.ORM.Find(&users) for _, user := range users { - db.ORM.Model(&user).Related("Torrents").Find(&model.Torrents{}) + db.ORM.Model(&user).Association("Languages").Find(&user.Languages) db.ORM.Model(&user).Association("Roles").Find(&user.Roles) userArr = append(userArr, user) } diff --git a/templates/_badgemenu.html b/templates/_badgemenu.html index d295ab17..bb22fb99 100644 --- a/templates/_badgemenu.html +++ b/templates/_badgemenu.html @@ -4,7 +4,7 @@