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 form // import "miniflux.app/ui/form"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-11-28 00:30:04 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/errors"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// AuthForm represents the authentication form.
|
2017-11-20 00:10:04 -05:00
|
|
|
type AuthForm struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// Validate makes sure the form values are valid.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (a AuthForm) Validate() error {
|
|
|
|
if a.Username == "" || a.Password == "" {
|
2018-09-21 21:53:29 -04:00
|
|
|
return errors.NewLocalizedError("error.fields_mandatory")
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// NewAuthForm returns a new AuthForm.
|
2017-11-20 00:10:04 -05:00
|
|
|
func NewAuthForm(r *http.Request) *AuthForm {
|
|
|
|
return &AuthForm{
|
|
|
|
Username: r.FormValue("username"),
|
|
|
|
Password: r.FormValue("password"),
|
|
|
|
}
|
|
|
|
}
|