mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/kolide/kolide-ose/datastore"
|
|
"github.com/kolide/kolide-ose/kolide"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (svc service) Authenticate(ctx context.Context, username, password string) (*kolide.User, error) {
|
|
user, err := svc.ds.User(username)
|
|
switch err {
|
|
case nil:
|
|
case datastore.ErrNotFound:
|
|
return nil, authError{
|
|
message: fmt.Sprintf("user %s not found", username),
|
|
}
|
|
default:
|
|
return nil, err
|
|
}
|
|
if !user.Enabled {
|
|
return nil, authError{
|
|
message: fmt.Sprintf("account disabled %s", username),
|
|
}
|
|
}
|
|
if err := user.ValidatePassword(password); err != nil {
|
|
return nil, authError{
|
|
message: fmt.Sprintf("invalid password for user %s", username),
|
|
}
|
|
}
|
|
return user, nil
|
|
}
|
|
|
|
func (svc service) NewSessionManager(ctx context.Context, w http.ResponseWriter, r *http.Request) *kolide.SessionManager {
|
|
return &kolide.SessionManager{
|
|
Request: r,
|
|
Writer: w,
|
|
Store: svc.ds,
|
|
JWTKey: svc.jwtKey,
|
|
CookieName: svc.cookieName,
|
|
}
|
|
}
|
|
|
|
func (svc service) GetInfoAboutSessionsForUser(ctx context.Context, id uint) ([]*kolide.Session, error) {
|
|
return svc.ds.FindAllSessionsForUser(id)
|
|
}
|
|
|
|
func (svc service) DeleteSessionsForUser(ctx context.Context, id uint) error {
|
|
return svc.ds.DestroyAllSessionsForUser(id)
|
|
}
|
|
|
|
func (svc service) GetInfoAboutSession(ctx context.Context, id uint) (*kolide.Session, error) {
|
|
return svc.ds.FindSessionByID(id)
|
|
}
|
|
|
|
func (svc service) DeleteSession(ctx context.Context, id uint) error {
|
|
session, err := svc.ds.FindSessionByID(id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return svc.ds.DestroySession(session)
|
|
}
|