From af95cb4d72a8e1070cdd219a31f367e69e737f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 13 Jan 2023 00:03:59 +0100 Subject: [PATCH] change dummy to noauth mode. --- internal/member/manager.go | 6 +-- internal/member/{dummy => noauth}/provider.go | 40 ++++++++++++------- 2 files changed, 28 insertions(+), 18 deletions(-) rename internal/member/{dummy => noauth}/provider.go (65%) diff --git a/internal/member/manager.go b/internal/member/manager.go index e717ecfe..2ba388ea 100644 --- a/internal/member/manager.go +++ b/internal/member/manager.go @@ -8,9 +8,9 @@ import ( "github.com/rs/zerolog/log" "github.com/demodesk/neko/internal/config" - "github.com/demodesk/neko/internal/member/dummy" "github.com/demodesk/neko/internal/member/file" "github.com/demodesk/neko/internal/member/multiuser" + "github.com/demodesk/neko/internal/member/noauth" "github.com/demodesk/neko/internal/member/object" "github.com/demodesk/neko/pkg/types" ) @@ -29,10 +29,10 @@ func New(sessions types.SessionManager, config *config.Member) *MemberManagerCtx manager.provider = object.New(config.Object) case "multiuser": manager.provider = multiuser.New(config.Multiuser) - case "dummy": + case "noauth": fallthrough default: - manager.provider = dummy.New() + manager.provider = noauth.New() } return manager diff --git a/internal/member/dummy/provider.go b/internal/member/noauth/provider.go similarity index 65% rename from internal/member/dummy/provider.go rename to internal/member/noauth/provider.go index 4ab0dd4a..517b0ef3 100644 --- a/internal/member/dummy/provider.go +++ b/internal/member/noauth/provider.go @@ -1,9 +1,11 @@ -package dummy +package noauth import ( "errors" + "fmt" "github.com/demodesk/neko/pkg/types" + "github.com/demodesk/neko/pkg/utils" ) func New() types.MemberProvider { @@ -35,31 +37,39 @@ func (provider *MemberProviderCtx) Disconnect() error { } func (provider *MemberProviderCtx) Authenticate(username string, password string) (string, types.MemberProfile, error) { + // generate random token + token, err := utils.NewUID(5) + if err != nil { + return "", types.MemberProfile{}, err + } + + // id is username with token + id := fmt.Sprintf("%s-%s", username, token) + provider.profile.Name = username - return username, provider.profile, nil + return id, provider.profile, nil } func (provider *MemberProviderCtx) Insert(username string, password string, profile types.MemberProfile) (string, error) { - return "", errors.New("not implemented") -} - -func (provider *MemberProviderCtx) Select(id string) (types.MemberProfile, error) { - provider.profile.Name = id - return provider.profile, nil -} - -func (provider *MemberProviderCtx) SelectAll(limit int, offset int) (map[string]types.MemberProfile, error) { - return map[string]types.MemberProfile{}, nil + return "", errors.New("new user is created on first login in noauth mode") } func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.MemberProfile) error { - return nil + return errors.New("cannot update user profile in noauth mode") } func (provider *MemberProviderCtx) UpdatePassword(id string, password string) error { - return errors.New("not implemented") + return errors.New("password can only be modified in config while in noauth mode") +} + +func (provider *MemberProviderCtx) Select(id string) (types.MemberProfile, error) { + return types.MemberProfile{}, errors.New("cannot select user in noauth mode") +} + +func (provider *MemberProviderCtx) SelectAll(limit int, offset int) (map[string]types.MemberProfile, error) { + return map[string]types.MemberProfile{}, errors.New("cannot select users in noauth mode") } func (provider *MemberProviderCtx) Delete(id string) error { - return nil + return errors.New("cannot delete user in noauth mode") }