mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-22 23:06:31 +00:00
8538877f52
* extract auth into provider * bump go version * use pointer * rebase
30 lines
667 B
Go
30 lines
667 B
Go
package providers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/core/services"
|
|
)
|
|
|
|
type LocalProvider struct {
|
|
service *services.UserService
|
|
}
|
|
|
|
func NewLocalProvider(service *services.UserService) *LocalProvider {
|
|
return &LocalProvider{
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
func (p *LocalProvider) Name() string {
|
|
return "local"
|
|
}
|
|
|
|
func (p *LocalProvider) Authenticate(w http.ResponseWriter, r *http.Request) (services.UserAuthTokenDetail, error) {
|
|
loginForm, err := getLoginForm(r)
|
|
if err != nil {
|
|
return services.UserAuthTokenDetail{}, err
|
|
}
|
|
|
|
return p.service.Login(r.Context(), loginForm.Username, loginForm.Password, loginForm.StayLoggedIn)
|
|
}
|