2017-11-20 06:10:04 +01: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.
|
|
|
|
|
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2017-11-28 06:30:04 +01:00
|
|
|
|
2017-12-13 06:48:13 +01:00
|
|
|
"github.com/miniflux/miniflux/errors"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// SubscriptionForm represents the subscription form.
|
2017-11-20 06:10:04 +01:00
|
|
|
type SubscriptionForm struct {
|
|
|
|
URL string
|
|
|
|
CategoryID int64
|
2017-12-13 04:19:36 +01:00
|
|
|
Crawler bool
|
2018-06-20 07:58:29 +02:00
|
|
|
Username string
|
|
|
|
Password string
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// Validate makes sure the form values are valid.
|
2017-11-20 06:10:04 +01:00
|
|
|
func (s *SubscriptionForm) Validate() error {
|
|
|
|
if s.URL == "" || s.CategoryID == 0 {
|
2017-11-28 06:30:04 +01:00
|
|
|
return errors.NewLocalizedError("The URL and the category are mandatory.")
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// NewSubscriptionForm returns a new SubscriptionForm.
|
2017-11-20 06:10:04 +01: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-13 04:19:36 +01:00
|
|
|
Crawler: r.FormValue("crawler") == "1",
|
2017-11-20 06:10:04 +01:00
|
|
|
CategoryID: int64(categoryID),
|
2018-06-20 07:58:29 +02:00
|
|
|
Username: r.FormValue("username"),
|
|
|
|
Password: r.FormValue("password"),
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
}
|