1
0
Fork 0
miniflux/ui/form/auth.go

35 lines
748 B
Go
Raw Normal View History

2017-11-20 00:10:04 -05: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"
2017-11-28 00:30:04 -05:00
2017-12-13 00:48:13 -05:00
"github.com/miniflux/miniflux/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 == "" {
2017-11-28 00:30:04 -05:00
return errors.NewLocalizedError("All fields are 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"),
}
}