mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
First commit
This commit is contained in:
commit
8ffb773f43
2121 changed files with 1118910 additions and 0 deletions
30
server/ui/form/auth.go
Normal file
30
server/ui/form/auth.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AuthForm struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (a AuthForm) Validate() error {
|
||||
if a.Username == "" || a.Password == "" {
|
||||
return errors.New("All fields are mandatory.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAuthForm(r *http.Request) *AuthForm {
|
||||
return &AuthForm{
|
||||
Username: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
}
|
||||
}
|
34
server/ui/form/category.go
Normal file
34
server/ui/form/category.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// CategoryForm represents a feed form in the UI
|
||||
type CategoryForm struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
func (c CategoryForm) Validate() error {
|
||||
if c.Title == "" {
|
||||
return errors.New("The title is mandatory.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c CategoryForm) Merge(category *model.Category) *model.Category {
|
||||
category.Title = c.Title
|
||||
return category
|
||||
}
|
||||
|
||||
func NewCategoryForm(r *http.Request) *CategoryForm {
|
||||
return &CategoryForm{
|
||||
Title: r.FormValue("title"),
|
||||
}
|
||||
}
|
53
server/ui/form/feed.go
Normal file
53
server/ui/form/feed.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// FeedForm represents a feed form in the UI
|
||||
type FeedForm struct {
|
||||
FeedURL string
|
||||
SiteURL string
|
||||
Title string
|
||||
CategoryID int64
|
||||
}
|
||||
|
||||
// ValidateModification validates FeedForm fields
|
||||
func (f FeedForm) ValidateModification() error {
|
||||
if f.FeedURL == "" || f.SiteURL == "" || f.Title == "" || f.CategoryID == 0 {
|
||||
return errors.New("All fields are mandatory.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
|
||||
feed.Category.ID = f.CategoryID
|
||||
feed.Title = f.Title
|
||||
feed.SiteURL = f.SiteURL
|
||||
feed.FeedURL = f.FeedURL
|
||||
feed.ParsingErrorCount = 0
|
||||
feed.ParsingErrorMsg = ""
|
||||
return feed
|
||||
}
|
||||
|
||||
// NewFeedForm parses the HTTP request and returns a FeedForm
|
||||
func NewFeedForm(r *http.Request) *FeedForm {
|
||||
categoryID, err := strconv.Atoi(r.FormValue("category_id"))
|
||||
if err != nil {
|
||||
categoryID = 0
|
||||
}
|
||||
|
||||
return &FeedForm{
|
||||
FeedURL: r.FormValue("feed_url"),
|
||||
SiteURL: r.FormValue("site_url"),
|
||||
Title: r.FormValue("title"),
|
||||
CategoryID: int64(categoryID),
|
||||
}
|
||||
}
|
62
server/ui/form/settings.go
Normal file
62
server/ui/form/settings.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type SettingsForm struct {
|
||||
Username string
|
||||
Password string
|
||||
Confirmation string
|
||||
Theme string
|
||||
Language string
|
||||
Timezone string
|
||||
}
|
||||
|
||||
func (s *SettingsForm) Merge(user *model.User) *model.User {
|
||||
user.Username = s.Username
|
||||
user.Theme = s.Theme
|
||||
user.Language = s.Language
|
||||
user.Timezone = s.Timezone
|
||||
|
||||
if s.Password != "" {
|
||||
user.Password = s.Password
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
func (s *SettingsForm) Validate() error {
|
||||
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" {
|
||||
return errors.New("The username, theme, language and timezone fields are mandatory.")
|
||||
}
|
||||
|
||||
if s.Password != "" {
|
||||
if s.Password != s.Confirmation {
|
||||
return errors.New("Passwords are not the same.")
|
||||
}
|
||||
|
||||
if len(s.Password) < 6 {
|
||||
return errors.New("You must use at least 6 characters")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSettingsForm(r *http.Request) *SettingsForm {
|
||||
return &SettingsForm{
|
||||
Username: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
Confirmation: r.FormValue("confirmation"),
|
||||
Theme: r.FormValue("theme"),
|
||||
Language: r.FormValue("language"),
|
||||
Timezone: r.FormValue("timezone"),
|
||||
}
|
||||
}
|
36
server/ui/form/subscription.go
Normal file
36
server/ui/form/subscription.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SubscriptionForm struct {
|
||||
URL string
|
||||
CategoryID int64
|
||||
}
|
||||
|
||||
func (s *SubscriptionForm) Validate() error {
|
||||
if s.URL == "" || s.CategoryID == 0 {
|
||||
return errors.New("The URL and the category are mandatory.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSubscriptionForm(r *http.Request) *SubscriptionForm {
|
||||
categoryID, err := strconv.Atoi(r.FormValue("category_id"))
|
||||
if err != nil {
|
||||
categoryID = 0
|
||||
}
|
||||
|
||||
return &SubscriptionForm{
|
||||
URL: r.FormValue("url"),
|
||||
CategoryID: int64(categoryID),
|
||||
}
|
||||
}
|
80
server/ui/form/user.go
Normal file
80
server/ui/form/user.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package form
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UserForm struct {
|
||||
Username string
|
||||
Password string
|
||||
Confirmation string
|
||||
IsAdmin bool
|
||||
}
|
||||
|
||||
func (u UserForm) ValidateCreation() error {
|
||||
if u.Username == "" || u.Password == "" || u.Confirmation == "" {
|
||||
return errors.New("All fields are mandatory.")
|
||||
}
|
||||
|
||||
if u.Password != u.Confirmation {
|
||||
return errors.New("Passwords are not the same.")
|
||||
}
|
||||
|
||||
if len(u.Password) < 6 {
|
||||
return errors.New("You must use at least 6 characters.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u UserForm) ValidateModification() error {
|
||||
if u.Username == "" {
|
||||
return errors.New("The username is mandatory.")
|
||||
}
|
||||
|
||||
if u.Password != "" {
|
||||
if u.Password != u.Confirmation {
|
||||
return errors.New("Passwords are not the same.")
|
||||
}
|
||||
|
||||
if len(u.Password) < 6 {
|
||||
return errors.New("You must use at least 6 characters.")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u UserForm) ToUser() *model.User {
|
||||
return &model.User{
|
||||
Username: u.Username,
|
||||
Password: u.Password,
|
||||
IsAdmin: u.IsAdmin,
|
||||
}
|
||||
}
|
||||
|
||||
func (u UserForm) Merge(user *model.User) *model.User {
|
||||
user.Username = u.Username
|
||||
user.IsAdmin = u.IsAdmin
|
||||
|
||||
if u.Password != "" {
|
||||
user.Password = u.Password
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
func NewUserForm(r *http.Request) *UserForm {
|
||||
return &UserForm{
|
||||
Username: r.FormValue("username"),
|
||||
Password: r.FormValue("password"),
|
||||
Confirmation: r.FormValue("confirmation"),
|
||||
IsAdmin: r.FormValue("is_admin") == "1",
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue