From a0f4989fc4d7e4883abfa191af955fb6d8d25c38 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 8 May 2017 22:33:40 +0200 Subject: [PATCH] Make login work --- config/user.go | 6 ------ public/css/style.css | 6 +----- service/user/cookieHelper.go | 3 +-- service/user/user.go | 10 +++++----- templates/_badgemenu.html | 3 +-- 5 files changed, 8 insertions(+), 20 deletions(-) delete mode 100644 config/user.go diff --git a/config/user.go b/config/user.go deleted file mode 100644 index 88b482de..00000000 --- a/config/user.go +++ /dev/null @@ -1,6 +0,0 @@ -package config - -// Constants for public models. -const ( - UserPublicFields = "id, username, md5, description, created_at, liking_count, liked_count" -) diff --git a/public/css/style.css b/public/css/style.css index 14f84911..c0e7e449 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -207,14 +207,10 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ left: -5px; } -#mainmenu .badgemenu .profile-image { - line-height: 35px; -} - #mainmenu .navbar-header, #mainmenu .navbar-nav, #mainmenu .navbar-form { padding-top: 10px; } #mainmenu .badgemenu { padding-top: 0; -} \ No newline at end of file +} diff --git a/service/user/cookieHelper.go b/service/user/cookieHelper.go index 55a1b811..96bf3791 100644 --- a/service/user/cookieHelper.go +++ b/service/user/cookieHelper.go @@ -8,7 +8,6 @@ import ( "golang.org/x/crypto/bcrypt" formStruct "github.com/ewhal/nyaa/service/user/form" - "github.com/ewhal/nyaa/config" "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/model" "github.com/ewhal/nyaa/util/log" @@ -147,7 +146,7 @@ func CurrentUser(r *http.Request) (model.User, error) { return user, err } } - if db.ORM.Select(config.UserPublicFields+", email").Where("token = ?", token).First(&user).RecordNotFound() { + if db.ORM.Where("api_token = ?", token).First(&user).RecordNotFound() { return user, errors.New("User is not found.") } db.ORM.Model(&user) diff --git a/service/user/user.go b/service/user/user.go index 6440a4fd..a942afa8 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -111,7 +111,7 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in var isAuthor bool // var publicUser *model.PublicUser // publicUser.User = &user - if db.ORM.Select(config.UserPublicFields).First(&user, id).RecordNotFound() { + if db.ORM.First(&user, id).RecordNotFound() { return nil, isAuthor, currentUserId, http.StatusNotFound, errors.New("User is not found.") } currentUser, err := CurrentUser(r) @@ -127,7 +127,7 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in func RetrieveUsers() []*model.PublicUser { var users []*model.User var userArr []*model.PublicUser - db.ORM.Select(config.UserPublicFields).Find(&users) + db.ORM.Find(&users) for _, user := range users { userArr = append(userArr, &model.PublicUser{User: user}) } @@ -213,7 +213,7 @@ func RetrieveCurrentUser(r *http.Request) (model.User, int, error) { // RetrieveUserByEmail retrieves a user by an email func RetrieveUserByEmail(email string) (*model.PublicUser, string, int, error) { var user model.User - if db.ORM.Unscoped().Select(config.UserPublicFields).Where("email like ?", "%"+email+"%").First(&user).RecordNotFound() { + if db.ORM.Unscoped().Where("email = ?", email).First(&user).RecordNotFound() { return &model.PublicUser{User: &user}, email, http.StatusNotFound, errors.New("User is not found.") } return &model.PublicUser{User: &user}, email, http.StatusOK, nil @@ -223,7 +223,7 @@ func RetrieveUserByEmail(email string) (*model.PublicUser, string, int, error) { func RetrieveUsersByEmail(email string) []*model.PublicUser { var users []*model.User var userArr []*model.PublicUser - db.ORM.Select(config.UserPublicFields).Where("email like ?", "%"+email+"%").Find(&users) + db.ORM.Where("email = ?", email).Find(&users) for _, user := range users { userArr = append(userArr, &model.PublicUser{User: user}) } @@ -233,7 +233,7 @@ func RetrieveUsersByEmail(email string) []*model.PublicUser { // RetrieveUserByUsername retrieves a user by username. func RetrieveUserByUsername(username string) (*model.PublicUser, string, int, error) { var user model.User - if db.ORM.Unscoped().Select(config.UserPublicFields).Where("username like ?", "%"+username+"%").First(&user).RecordNotFound() { + if db.ORM.Where("username = ?", username).First(&user).RecordNotFound() { return &model.PublicUser{User: &user}, username, http.StatusNotFound, errors.New("User is not found.") } return &model.PublicUser{User: &user}, username, http.StatusOK, nil diff --git a/templates/_badgemenu.html b/templates/_badgemenu.html index bb22fb99..6baafbc4 100644 --- a/templates/_badgemenu.html +++ b/templates/_badgemenu.html @@ -3,8 +3,7 @@