neko/internal/member/noauth/provider.go

76 lines
2.0 KiB
Go
Raw Permalink Normal View History

2023-01-13 12:03:59 +13:00
package noauth
2021-03-15 00:57:19 +13:00
import (
2021-08-30 03:09:13 +12:00
"errors"
2023-01-13 12:03:59 +13:00
"fmt"
2021-03-15 01:06:33 +13:00
"github.com/demodesk/neko/pkg/types"
2023-01-13 12:03:59 +13:00
"github.com/demodesk/neko/pkg/utils"
2021-03-15 00:57:19 +13:00
)
2021-03-15 04:58:18 +13:00
func New() types.MemberProvider {
2021-03-17 03:38:51 +13:00
return &MemberProviderCtx{
profile: types.MemberProfile{
2021-11-04 09:59:38 +13:00
IsAdmin: true,
CanLogin: true,
CanConnect: true,
CanWatch: true,
CanHost: true,
2021-12-10 09:48:02 +13:00
CanShareMedia: true,
2021-11-04 09:59:38 +13:00
CanAccessClipboard: true,
SendsInactiveCursor: true,
CanSeeInactiveCursors: true,
2021-03-17 03:38:51 +13:00
},
}
2021-03-15 00:57:19 +13:00
}
2021-03-17 03:38:51 +13:00
type MemberProviderCtx struct {
profile types.MemberProfile
}
2021-03-15 00:57:19 +13:00
2021-03-15 04:58:18 +13:00
func (provider *MemberProviderCtx) Connect() error {
2021-03-15 00:57:19 +13:00
return nil
}
2021-03-15 04:58:18 +13:00
func (provider *MemberProviderCtx) Disconnect() error {
2021-03-15 00:57:19 +13:00
return nil
}
2021-03-15 04:58:18 +13:00
func (provider *MemberProviderCtx) Authenticate(username string, password string) (string, types.MemberProfile, error) {
2023-01-13 12:03:59 +13:00
// 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)
2021-03-17 03:38:51 +13:00
provider.profile.Name = username
2023-01-13 12:03:59 +13:00
return id, provider.profile, nil
2021-03-15 00:57:19 +13:00
}
2021-03-15 04:58:18 +13:00
func (provider *MemberProviderCtx) Insert(username string, password string, profile types.MemberProfile) (string, error) {
2023-01-13 12:03:59 +13:00
return "", errors.New("new user is created on first login in noauth mode")
2021-03-15 00:57:19 +13:00
}
2023-01-13 12:03:59 +13:00
func (provider *MemberProviderCtx) UpdateProfile(id string, profile types.MemberProfile) error {
2023-01-13 12:11:00 +13:00
return nil
2021-03-15 00:57:19 +13:00
}
2023-01-13 12:03:59 +13:00
func (provider *MemberProviderCtx) UpdatePassword(id string, password string) error {
2023-01-13 12:11:00 +13:00
return errors.New("noauth mode does not have password")
2021-03-15 00:57:19 +13:00
}
2023-01-13 12:03:59 +13:00
func (provider *MemberProviderCtx) Select(id string) (types.MemberProfile, error) {
return types.MemberProfile{}, errors.New("cannot select user in noauth mode")
2021-03-15 00:57:19 +13:00
}
2023-01-13 12:03:59 +13:00
func (provider *MemberProviderCtx) SelectAll(limit int, offset int) (map[string]types.MemberProfile, error) {
2023-01-13 12:11:00 +13:00
return map[string]types.MemberProfile{}, nil
2021-03-15 00:57:19 +13:00
}
2021-03-15 04:58:18 +13:00
func (provider *MemberProviderCtx) Delete(id string) error {
2023-01-13 12:03:59 +13:00
return errors.New("cannot delete user in noauth mode")
2021-03-15 00:57:19 +13:00
}