2017-11-19 21:10:04 -08:00
|
|
|
// 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.
|
|
|
|
|
2018-08-24 21:51:50 -07:00
|
|
|
package form // import "miniflux.app/ui/form"
|
2017-11-19 21:10:04 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2017-11-27 21:30:04 -08:00
|
|
|
|
2018-08-24 21:51:50 -07:00
|
|
|
"miniflux.app/errors"
|
2017-11-19 21:10:04 -08:00
|
|
|
)
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// SubscriptionForm represents the subscription form.
|
2017-11-19 21:10:04 -08:00
|
|
|
type SubscriptionForm struct {
|
|
|
|
URL string
|
|
|
|
CategoryID int64
|
2017-12-12 19:19:36 -08:00
|
|
|
Crawler bool
|
2018-09-20 03:19:24 +02:00
|
|
|
UserAgent string
|
2018-06-19 22:58:29 -07:00
|
|
|
Username string
|
|
|
|
Password string
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// Validate makes sure the form values are valid.
|
2017-11-19 21:10:04 -08:00
|
|
|
func (s *SubscriptionForm) Validate() error {
|
|
|
|
if s.URL == "" || s.CategoryID == 0 {
|
2018-09-21 18:53:29 -07:00
|
|
|
return errors.NewLocalizedError("error.feed_mandatory_fields")
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// NewSubscriptionForm returns a new SubscriptionForm.
|
2017-11-19 21:10:04 -08:00
|
|
|
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"),
|
2017-12-12 19:19:36 -08:00
|
|
|
Crawler: r.FormValue("crawler") == "1",
|
2017-11-19 21:10:04 -08:00
|
|
|
CategoryID: int64(categoryID),
|
2018-09-20 03:19:24 +02:00
|
|
|
UserAgent: r.FormValue("user_agent"),
|
2018-06-30 18:05:51 -07:00
|
|
|
Username: r.FormValue("feed_username"),
|
|
|
|
Password: r.FormValue("feed_password"),
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
}
|