change dummy to noauth mode.

This commit is contained in:
Miroslav Šedivý 2023-01-13 00:03:59 +01:00
parent 319bd457f3
commit af95cb4d72
2 changed files with 28 additions and 18 deletions

View File

@ -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

View File

@ -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")
}