2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-19 21:10:04 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package form // import "miniflux.app/v2/internal/ui/form"
|
2017-11-19 21:10:04 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-09-08 20:11:48 -07:00
|
|
|
"strings"
|
2017-11-27 21:30:04 -08:00
|
|
|
|
2023-10-21 19:50:29 -07:00
|
|
|
"miniflux.app/v2/internal/locale"
|
2017-11-19 21:10:04 -08:00
|
|
|
)
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// AuthForm represents the authentication form.
|
2017-11-19 21:10:04 -08:00
|
|
|
type AuthForm struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// Validate makes sure the form values are valid.
|
2023-10-21 19:50:29 -07:00
|
|
|
func (a AuthForm) Validate() *locale.LocalizedError {
|
2017-11-19 21:10:04 -08:00
|
|
|
if a.Username == "" || a.Password == "" {
|
2023-10-21 19:50:29 -07:00
|
|
|
return locale.NewLocalizedError("error.fields_mandatory")
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-27 21:30:04 -08:00
|
|
|
// NewAuthForm returns a new AuthForm.
|
2017-11-19 21:10:04 -08:00
|
|
|
func NewAuthForm(r *http.Request) *AuthForm {
|
|
|
|
return &AuthForm{
|
2023-09-08 20:11:48 -07:00
|
|
|
Username: strings.TrimSpace(r.FormValue("username")),
|
|
|
|
Password: strings.TrimSpace(r.FormValue("password")),
|
2017-11-19 21:10:04 -08:00
|
|
|
}
|
|
|
|
}
|