Make login work
Cette révision appartient à :
Parent
71f659ad00
révision
a0f4989fc4
5 fichiers modifiés avec 8 ajouts et 20 suppressions
|
@ -1,6 +0,0 @@
|
|||
package config
|
||||
|
||||
// Constants for public models.
|
||||
const (
|
||||
UserPublicFields = "id, username, md5, description, created_at, liking_count, liked_count"
|
||||
)
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
<ul class="nav navbar-nav navbar-right badgemenu">
|
||||
<li class="dropdown">
|
||||
{{if gt .Id 0}}
|
||||
<a href="{{ genRoute "user_profile" "id" (print .Id) "username" .Username }}" class="dropdown-toggle profile-image" data-toggle="dropdown">
|
||||
<img src="https://www.gravatar.com/avatar/{{ .Md5 }}?s=50" class="img-circle special-img"> {{ .Username }} <b class="caret"></b></a>
|
||||
<a href="{{ genRoute "user_profile" "id" (print .Id) "username" .Username }}" class="dropdown-toggle" data-toggle="dropdown">{{ .Username }} <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="{{ genRoute "user_profile" "id" (print .Id) "username" .Username }}"><i class="fa fa-cog"></i> Profile</a></li>
|
||||
<li class="divider"></li>
|
||||
|
|
Référencer dans un nouveau ticket