mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 16:45:43 +00:00
0c535aa8d8
* extract auth into provider
* bump go version
* use pointer
* rebase
Former-commit-id: 8538877f52
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)
|
|
}
|