2020-01-15 04:22:34 +01:00
|
|
|
package model
|
2020-01-14 22:11:27 +01:00
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
type User struct {
|
2021-08-01 07:21:20 +02:00
|
|
|
ID string `structs:"id" json:"id" orm:"column(id)"`
|
|
|
|
UserName string `structs:"user_name" json:"userName"`
|
|
|
|
Name string `structs:"name" json:"name"`
|
|
|
|
Email string `structs:"email" json:"email"`
|
|
|
|
IsAdmin bool `structs:"is_admin" json:"isAdmin"`
|
|
|
|
LastLoginAt time.Time `structs:"last_login_at" json:"lastLoginAt"`
|
|
|
|
LastAccessAt time.Time `structs:"last_access_at" json:"lastAccessAt"`
|
|
|
|
CreatedAt time.Time `structs:"created_at" json:"createdAt"`
|
|
|
|
UpdatedAt time.Time `structs:"updated_at" json:"updatedAt"`
|
2021-05-02 00:03:45 +02:00
|
|
|
|
|
|
|
// This is only available on the backend, and it is never sent over the wire
|
2021-08-01 07:21:20 +02:00
|
|
|
Password string `structs:"-" json:"-"`
|
2021-05-02 00:03:45 +02:00
|
|
|
// This is used to set or change a password when calling Put. If it is empty, the password is not changed.
|
|
|
|
// It is received from the UI with the name "password"
|
2021-08-01 07:21:20 +02:00
|
|
|
NewPassword string `structs:"password,omitempty" json:"password,omitempty"`
|
2021-05-03 21:03:34 +02:00
|
|
|
// If changing the password, this is also required
|
2021-08-01 07:21:20 +02:00
|
|
|
CurrentPassword string `structs:"current_password,omitempty" json:"currentPassword,omitempty"`
|
2020-01-14 22:11:27 +01:00
|
|
|
}
|
2020-01-20 04:36:15 +01:00
|
|
|
|
2020-01-28 14:22:17 +01:00
|
|
|
type Users []User
|
|
|
|
|
2020-01-20 04:36:15 +01:00
|
|
|
type UserRepository interface {
|
|
|
|
CountAll(...QueryOptions) (int64, error)
|
|
|
|
Get(id string) (*User, error)
|
|
|
|
Put(*User) error
|
2021-06-19 00:38:38 +02:00
|
|
|
UpdateLastLoginAt(id string) error
|
|
|
|
UpdateLastAccessAt(id string) error
|
2020-07-11 20:38:17 +02:00
|
|
|
FindFirstAdmin() (*User, error)
|
2020-03-01 21:45:41 +01:00
|
|
|
// FindByUsername must be case-insensitive
|
2020-01-20 15:54:29 +01:00
|
|
|
FindByUsername(username string) (*User, error)
|
2021-06-19 00:38:38 +02:00
|
|
|
// FindByUsernameWithPassword is the same as above, but also returns the decrypted password
|
|
|
|
FindByUsernameWithPassword(username string) (*User, error)
|
2020-01-20 04:36:15 +01:00
|
|
|
}
|