|
@@ -13,15 +13,15 @@ import (
|
|
|
|
|
|
|
|
"github.com/lib/pq/hstore"
|
|
"github.com/lib/pq/hstore"
|
|
|
|
|
|
|
|
- "github.com/miniflux/miniflux/helper"
|
|
|
|
|
"github.com/miniflux/miniflux/model"
|
|
"github.com/miniflux/miniflux/model"
|
|
|
|
|
+ "github.com/miniflux/miniflux/timer"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// SetLastLogin updates the last login date of a user.
|
|
// SetLastLogin updates the last login date of a user.
|
|
|
func (s *Storage) SetLastLogin(userID int64) error {
|
|
func (s *Storage) SetLastLogin(userID int64) error {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetLastLogin] userID=%d", userID))
|
|
|
query := "UPDATE users SET last_login_at=now() WHERE id=$1"
|
|
query := "UPDATE users SET last_login_at=now() WHERE id=$1"
|
|
|
_, err := s.db.Exec(query, userID)
|
|
_, err := s.db.Exec(query, userID)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -33,7 +33,7 @@ func (s *Storage) SetLastLogin(userID int64) error {
|
|
|
|
|
|
|
|
// UserExists checks if a user exists by using the given username.
|
|
// UserExists checks if a user exists by using the given username.
|
|
|
func (s *Storage) UserExists(username string) bool {
|
|
func (s *Storage) UserExists(username string) bool {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserExists] username=%s", username))
|
|
|
|
|
|
|
|
var result int
|
|
var result int
|
|
|
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE username=LOWER($1)`, username).Scan(&result)
|
|
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE username=LOWER($1)`, username).Scan(&result)
|
|
@@ -42,7 +42,7 @@ func (s *Storage) UserExists(username string) bool {
|
|
|
|
|
|
|
|
// AnotherUserExists checks if another user exists with the given username.
|
|
// AnotherUserExists checks if another user exists with the given username.
|
|
|
func (s *Storage) AnotherUserExists(userID int64, username string) bool {
|
|
func (s *Storage) AnotherUserExists(userID int64, username string) bool {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherUserExists] userID=%d, username=%s", userID, username))
|
|
|
|
|
|
|
|
var result int
|
|
var result int
|
|
|
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE id != $1 AND username=LOWER($2)`, userID, username).Scan(&result)
|
|
s.db.QueryRow(`SELECT count(*) as c FROM users WHERE id != $1 AND username=LOWER($2)`, userID, username).Scan(&result)
|
|
@@ -51,7 +51,7 @@ func (s *Storage) AnotherUserExists(userID int64, username string) bool {
|
|
|
|
|
|
|
|
// CreateUser creates a new user.
|
|
// CreateUser creates a new user.
|
|
|
func (s *Storage) CreateUser(user *model.User) (err error) {
|
|
func (s *Storage) CreateUser(user *model.User) (err error) {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CreateUser] username=%s", user.Username))
|
|
|
password := ""
|
|
password := ""
|
|
|
extra := hstore.Hstore{Map: make(map[string]sql.NullString)}
|
|
extra := hstore.Hstore{Map: make(map[string]sql.NullString)}
|
|
|
|
|
|
|
@@ -114,7 +114,7 @@ func (s *Storage) RemoveExtraField(userID int64, field string) error {
|
|
|
|
|
|
|
|
// UpdateUser updates a user.
|
|
// UpdateUser updates a user.
|
|
|
func (s *Storage) UpdateUser(user *model.User) error {
|
|
func (s *Storage) UpdateUser(user *model.User) error {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UpdateUser] userID=%d", user.ID))
|
|
|
|
|
|
|
|
if user.Password != "" {
|
|
if user.Password != "" {
|
|
|
hashedPassword, err := hashPassword(user.Password)
|
|
hashedPassword, err := hashPassword(user.Password)
|
|
@@ -177,7 +177,7 @@ func (s *Storage) UpdateUser(user *model.User) error {
|
|
|
|
|
|
|
|
// UserByID finds a user by the ID.
|
|
// UserByID finds a user by the ID.
|
|
|
func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
|
func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByID] userID=%d", userID))
|
|
|
query := `SELECT
|
|
query := `SELECT
|
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
|
FROM users
|
|
FROM users
|
|
@@ -188,7 +188,7 @@ func (s *Storage) UserByID(userID int64) (*model.User, error) {
|
|
|
|
|
|
|
|
// UserByUsername finds a user by the username.
|
|
// UserByUsername finds a user by the username.
|
|
|
func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
|
func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByUsername] username=%s", username))
|
|
|
query := `SELECT
|
|
query := `SELECT
|
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
|
FROM users
|
|
FROM users
|
|
@@ -199,7 +199,7 @@ func (s *Storage) UserByUsername(username string) (*model.User, error) {
|
|
|
|
|
|
|
|
// UserByExtraField finds a user by an extra field value.
|
|
// UserByExtraField finds a user by an extra field value.
|
|
|
func (s *Storage) UserByExtraField(field, value string) (*model.User, error) {
|
|
func (s *Storage) UserByExtraField(field, value string) (*model.User, error) {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:UserByExtraField] field=%s", field))
|
|
|
query := `SELECT
|
|
query := `SELECT
|
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
|
FROM users
|
|
FROM users
|
|
@@ -241,7 +241,7 @@ func (s *Storage) fetchUser(query string, args ...interface{}) (*model.User, err
|
|
|
|
|
|
|
|
// RemoveUser deletes a user.
|
|
// RemoveUser deletes a user.
|
|
|
func (s *Storage) RemoveUser(userID int64) error {
|
|
func (s *Storage) RemoveUser(userID int64) error {
|
|
|
- defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID))
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:RemoveUser] userID=%d", userID))
|
|
|
|
|
|
|
|
result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID)
|
|
result, err := s.db.Exec("DELETE FROM users WHERE id = $1", userID)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -262,7 +262,7 @@ func (s *Storage) RemoveUser(userID int64) error {
|
|
|
|
|
|
|
|
// Users returns all users.
|
|
// Users returns all users.
|
|
|
func (s *Storage) Users() (model.Users, error) {
|
|
func (s *Storage) Users() (model.Users, error) {
|
|
|
- defer helper.ExecutionTime(time.Now(), "[Storage:Users]")
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), "[Storage:Users]")
|
|
|
query := `
|
|
query := `
|
|
|
SELECT
|
|
SELECT
|
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
id, username, is_admin, theme, language, timezone, entry_direction, last_login_at, extra
|
|
@@ -309,7 +309,7 @@ func (s *Storage) Users() (model.Users, error) {
|
|
|
|
|
|
|
|
// CheckPassword validate the hashed password.
|
|
// CheckPassword validate the hashed password.
|
|
|
func (s *Storage) CheckPassword(username, password string) error {
|
|
func (s *Storage) CheckPassword(username, password string) error {
|
|
|
- defer helper.ExecutionTime(time.Now(), "[Storage:CheckPassword]")
|
|
|
|
|
|
|
+ defer timer.ExecutionTime(time.Now(), "[Storage:CheckPassword]")
|
|
|
|
|
|
|
|
var hash string
|
|
var hash string
|
|
|
username = strings.ToLower(username)
|
|
username = strings.ToLower(username)
|