2024-02-14 00:07:24 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/account"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/api/middleware"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/api/registry"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.sia.tech/jape"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ registry.API = (*AccountAPI)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountAPI struct {
|
|
|
|
config *viper.Viper
|
|
|
|
accounts *account.AccountServiceDefault
|
|
|
|
httpHandler *HttpHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountAPIParams struct {
|
|
|
|
fx.In
|
|
|
|
Config *viper.Viper
|
|
|
|
Accounts *account.AccountServiceDefault
|
|
|
|
HttpHandler *HttpHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewS5(params AccountAPIParams) AccountApiResult {
|
|
|
|
api := &AccountAPI{
|
|
|
|
config: params.Config,
|
|
|
|
accounts: params.Accounts,
|
|
|
|
httpHandler: params.HttpHandler,
|
|
|
|
}
|
|
|
|
|
|
|
|
return AccountApiResult{
|
|
|
|
API: api,
|
|
|
|
AccountAPI: api,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitAPI(api *AccountAPI) error {
|
|
|
|
return api.Init()
|
|
|
|
}
|
|
|
|
|
|
|
|
var Module = fx.Module("s5_api",
|
|
|
|
fx.Provide(NewS5),
|
|
|
|
fx.Provide(NewHttpHandler),
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountApiResult struct {
|
|
|
|
fx.Out
|
|
|
|
API registry.API `group:"api"`
|
|
|
|
AccountAPI *AccountAPI
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AccountAPI) Name() string {
|
|
|
|
return "account"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AccountAPI) Init() error {
|
|
|
|
middleware.RegisterProtocolSubdomain(a.config, jape.Mux(getRoutes(a)), "s5")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AccountAPI) Start(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a AccountAPI) Stop(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRoutes(a *AccountAPI) map[string]jape.Handler {
|
|
|
|
return map[string]jape.Handler{
|
2024-02-14 04:23:01 +00:00
|
|
|
"/api/auth/login": a.httpHandler.login,
|
|
|
|
"/api/auth/register": a.httpHandler.register,
|
|
|
|
"/api/auth/otp/generate": a.httpHandler.otpGenerate,
|
|
|
|
"/api/auth/otp/verify": a.httpHandler.otpVerify,
|
|
|
|
"/api/auth/otp/validate": a.httpHandler.otpValidate,
|
|
|
|
"/api/auth/otp/disable": a.httpHandler.otpDisable,
|
2024-02-14 00:07:24 +00:00
|
|
|
}
|
|
|
|
}
|