Use best naming practices
This commit is contained in:
parent
ce81c36e9f
commit
c82cdb4f13
@ -62,7 +62,7 @@ func CreateSession(app *app.App, w http.ResponseWriter, userId int64, remember b
|
|||||||
return session, nil
|
return session, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSessionByAuthToken(app *app.App, authToken string) (Session, error) {
|
func SessionByAuthToken(app *app.App, authToken string) (Session, error) {
|
||||||
session := Session{}
|
session := Session{}
|
||||||
|
|
||||||
err := app.Db.QueryRow(selectSessionByAuthToken, authToken).Scan(&session.Id, &session.UserId, &session.AuthToken, &session.RememberMe, &session.CreatedAt)
|
err := app.Db.QueryRow(selectSessionByAuthToken, authToken).Scan(&session.Id, &session.UserId, &session.AuthToken, &session.RememberMe, &session.CreatedAt)
|
||||||
|
@ -27,23 +27,23 @@ const (
|
|||||||
insertUser = "INSERT INTO " + userTable + " (" + userColumnsNoId + ") VALUES ($1, $2, $3, $4) RETURNING \"Id\""
|
insertUser = "INSERT INTO " + userTable + " (" + userColumnsNoId + ") VALUES ($1, $2, $3, $4) RETURNING \"Id\""
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetCurrentUser finds the currently logged-in user by session cookie
|
// CurrentUser finds the currently logged-in user by session cookie
|
||||||
func GetCurrentUser(app *app.App, r *http.Request) (User, error) {
|
func CurrentUser(app *app.App, r *http.Request) (User, error) {
|
||||||
cookie, err := r.Cookie("session")
|
cookie, err := r.Cookie("session")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return User{}, err
|
return User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := GetSessionByAuthToken(app, cookie.Value)
|
session, err := SessionByAuthToken(app, cookie.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return User{}, err
|
return User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetUserById(app, session.UserId)
|
return UserById(app, session.UserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserById finds a User table row in the database by id and returns a struct representing this row
|
// UserById finds a User table row in the database by id and returns a struct representing this row
|
||||||
func GetUserById(app *app.App, id int64) (User, error) {
|
func UserById(app *app.App, id int64) (User, error) {
|
||||||
user := User{}
|
user := User{}
|
||||||
|
|
||||||
err := app.Db.QueryRow(selectUserById, id).Scan(&user.Id, &user.Username, &user.Password, &user.CreatedAt, &user.UpdatedAt)
|
err := app.Db.QueryRow(selectUserById, id).Scan(&user.Id, &user.Username, &user.Password, &user.CreatedAt, &user.UpdatedAt)
|
||||||
@ -54,8 +54,8 @@ func GetUserById(app *app.App, id int64) (User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByUsername finds a User table row in the database by username and returns a struct representing this row
|
// UserByUsername finds a User table row in the database by username and returns a struct representing this row
|
||||||
func GetUserByUsername(app *app.App, username string) (User, error) {
|
func UserByUsername(app *app.App, username string) (User, error) {
|
||||||
user := User{}
|
user := User{}
|
||||||
|
|
||||||
err := app.Db.QueryRow(selectUserByUsername, username).Scan(&user.Id, &user.Username, &user.Password, &user.CreatedAt, &user.UpdatedAt)
|
err := app.Db.QueryRow(selectUserByUsername, username).Scan(&user.Id, &user.Username, &user.Password, &user.CreatedAt, &user.UpdatedAt)
|
||||||
@ -82,7 +82,7 @@ func CreateUser(app *app.App, username string, password string, createdAt time.T
|
|||||||
return User{}, err
|
return User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetUserById(app, lastInsertId)
|
return UserById(app, lastInsertId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthenticateUser validates the password for the specified user
|
// AuthenticateUser validates the password for the specified user
|
||||||
|
Loading…
Reference in New Issue
Block a user