2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
package model // import "miniflux.app/model"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2018-03-04 20:04:31 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/timezone"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// User represents a user in the system.
|
|
|
|
type User struct {
|
2022-10-25 23:00:56 -04:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"-"`
|
|
|
|
IsAdmin bool `json:"is_admin"`
|
|
|
|
Theme string `json:"theme"`
|
|
|
|
Language string `json:"language"`
|
|
|
|
Timezone string `json:"timezone"`
|
|
|
|
EntryDirection string `json:"entry_sorting_direction"`
|
|
|
|
EntryOrder string `json:"entry_sorting_order"`
|
|
|
|
Stylesheet string `json:"stylesheet"`
|
|
|
|
GoogleID string `json:"google_id"`
|
|
|
|
OpenIDConnectID string `json:"openid_connect_id"`
|
|
|
|
EntriesPerPage int `json:"entries_per_page"`
|
|
|
|
KeyboardShortcuts bool `json:"keyboard_shortcuts"`
|
|
|
|
ShowReadingTime bool `json:"show_reading_time"`
|
|
|
|
EntrySwipe bool `json:"entry_swipe"`
|
2022-09-30 01:37:57 -04:00
|
|
|
GestureNav string `json:"gesture_nav"`
|
2022-10-25 23:00:56 -04:00
|
|
|
LastLoginAt *time.Time `json:"last_login_at"`
|
|
|
|
DisplayMode string `json:"display_mode"`
|
|
|
|
DefaultReadingSpeed int `json:"default_reading_speed"`
|
|
|
|
CJKReadingSpeed int `json:"cjk_reading_speed"`
|
|
|
|
DefaultHomePage string `json:"default_home_page"`
|
|
|
|
CategoriesSortingOrder string `json:"categories_sorting_order"`
|
2017-11-23 01:22:33 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
// UserCreationRequest represents the request to create a user.
|
|
|
|
type UserCreationRequest struct {
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
IsAdmin bool `json:"is_admin"`
|
|
|
|
GoogleID string `json:"google_id"`
|
|
|
|
OpenIDConnectID string `json:"openid_connect_id"`
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
// UserModificationRequest represents the request to update a user.
|
|
|
|
type UserModificationRequest struct {
|
2022-10-25 23:00:56 -04:00
|
|
|
Username *string `json:"username"`
|
|
|
|
Password *string `json:"password"`
|
|
|
|
Theme *string `json:"theme"`
|
|
|
|
Language *string `json:"language"`
|
|
|
|
Timezone *string `json:"timezone"`
|
|
|
|
EntryDirection *string `json:"entry_sorting_direction"`
|
|
|
|
EntryOrder *string `json:"entry_sorting_order"`
|
|
|
|
Stylesheet *string `json:"stylesheet"`
|
|
|
|
GoogleID *string `json:"google_id"`
|
|
|
|
OpenIDConnectID *string `json:"openid_connect_id"`
|
|
|
|
EntriesPerPage *int `json:"entries_per_page"`
|
|
|
|
IsAdmin *bool `json:"is_admin"`
|
|
|
|
KeyboardShortcuts *bool `json:"keyboard_shortcuts"`
|
|
|
|
ShowReadingTime *bool `json:"show_reading_time"`
|
|
|
|
EntrySwipe *bool `json:"entry_swipe"`
|
2022-09-30 01:37:57 -04:00
|
|
|
GestureNav *string `json:"gesture_nav"`
|
2022-10-25 23:00:56 -04:00
|
|
|
DisplayMode *string `json:"display_mode"`
|
|
|
|
DefaultReadingSpeed *int `json:"default_reading_speed"`
|
|
|
|
CJKReadingSpeed *int `json:"cjk_reading_speed"`
|
|
|
|
DefaultHomePage *string `json:"default_home_page"`
|
|
|
|
CategoriesSortingOrder *string `json:"categories_sorting_order"`
|
2021-01-04 00:20:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Patch updates the User object with the modification request.
|
|
|
|
func (u *UserModificationRequest) Patch(user *User) {
|
|
|
|
if u.Username != nil {
|
|
|
|
user.Username = *u.Username
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.Password != nil {
|
|
|
|
user.Password = *u.Password
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.IsAdmin != nil {
|
|
|
|
user.IsAdmin = *u.IsAdmin
|
2017-11-25 22:06:02 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.Theme != nil {
|
|
|
|
user.Theme = *u.Theme
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.Language != nil {
|
|
|
|
user.Language = *u.Language
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.Timezone != nil {
|
|
|
|
user.Timezone = *u.Timezone
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.EntryDirection != nil {
|
|
|
|
user.EntryDirection = *u.EntryDirection
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-05-14 07:51:51 -04:00
|
|
|
if u.EntryOrder != nil {
|
|
|
|
user.EntryOrder = *u.EntryOrder
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.Stylesheet != nil {
|
|
|
|
user.Stylesheet = *u.Stylesheet
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.GoogleID != nil {
|
|
|
|
user.GoogleID = *u.GoogleID
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:20:21 -05:00
|
|
|
if u.OpenIDConnectID != nil {
|
|
|
|
user.OpenIDConnectID = *u.OpenIDConnectID
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.EntriesPerPage != nil {
|
|
|
|
user.EntriesPerPage = *u.EntriesPerPage
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.KeyboardShortcuts != nil {
|
|
|
|
user.KeyboardShortcuts = *u.KeyboardShortcuts
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.ShowReadingTime != nil {
|
|
|
|
user.ShowReadingTime = *u.ShowReadingTime
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.EntrySwipe != nil {
|
|
|
|
user.EntrySwipe = *u.EntrySwipe
|
|
|
|
}
|
2021-02-28 16:29:51 -05:00
|
|
|
|
2022-09-30 01:37:57 -04:00
|
|
|
if u.GestureNav != nil {
|
|
|
|
user.GestureNav = *u.GestureNav
|
2023-01-14 19:49:21 -05:00
|
|
|
}
|
|
|
|
|
2021-02-28 16:29:51 -05:00
|
|
|
if u.DisplayMode != nil {
|
|
|
|
user.DisplayMode = *u.DisplayMode
|
|
|
|
}
|
2021-08-30 10:53:05 -04:00
|
|
|
|
|
|
|
if u.DefaultReadingSpeed != nil {
|
|
|
|
user.DefaultReadingSpeed = *u.DefaultReadingSpeed
|
|
|
|
}
|
|
|
|
|
|
|
|
if u.CJKReadingSpeed != nil {
|
|
|
|
user.CJKReadingSpeed = *u.CJKReadingSpeed
|
|
|
|
}
|
2022-07-20 16:07:55 -04:00
|
|
|
|
|
|
|
if u.DefaultHomePage != nil {
|
|
|
|
user.DefaultHomePage = *u.DefaultHomePage
|
|
|
|
}
|
2022-10-16 01:36:59 -04:00
|
|
|
|
2022-10-25 23:00:56 -04:00
|
|
|
if u.CategoriesSortingOrder != nil {
|
|
|
|
user.CategoriesSortingOrder = *u.CategoriesSortingOrder
|
2022-10-16 01:36:59 -04:00
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2018-03-04 20:04:31 -05:00
|
|
|
// UseTimezone converts last login date to the given timezone.
|
|
|
|
func (u *User) UseTimezone(tz string) {
|
|
|
|
if u.LastLoginAt != nil {
|
|
|
|
*u.LastLoginAt = timezone.Convert(tz, *u.LastLoginAt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 00:10:04 -05:00
|
|
|
// Users represents a list of users.
|
|
|
|
type Users []*User
|
2018-03-04 20:04:31 -05:00
|
|
|
|
|
|
|
// UseTimezone converts last login timestamp of all users to the given timezone.
|
|
|
|
func (u Users) UseTimezone(tz string) {
|
|
|
|
for _, user := range u {
|
|
|
|
user.UseTimezone(tz)
|
|
|
|
}
|
|
|
|
}
|