feat: allow disable registration (#71)

This commit is contained in:
Hayden 2022-10-14 14:02:16 -08:00 committed by GitHub
parent ba8367f637
commit dea2dcfde8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 12 deletions

View file

@ -44,6 +44,7 @@ func (a *app) newRouter(repos *repo.AllRepos) *chi.Mux {
v1Base := v1.BaseUrlFunc(prefix) v1Base := v1.BaseUrlFunc(prefix)
v1Ctrl := v1.NewControllerV1(a.services, v1Ctrl := v1.NewControllerV1(a.services,
v1.WithMaxUploadSize(a.conf.Web.MaxUploadSize), v1.WithMaxUploadSize(a.conf.Web.MaxUploadSize),
v1.WithRegistration(a.conf.AllowRegistration),
v1.WithDemoStatus(a.conf.Demo), // Disable Password Change in Demo Mode v1.WithDemoStatus(a.conf.Demo), // Disable Password Change in Demo Mode
) )
r.Get(v1Base("/status"), v1Ctrl.HandleBase(func() bool { return true }, v1.Build{ r.Get(v1Base("/status"), v1Ctrl.HandleBase(func() bool { return true }, v1.Build{

View file

@ -19,10 +19,17 @@ func WithDemoStatus(demoStatus bool) func(*V1Controller) {
} }
} }
func WithRegistration(allowRegistration bool) func(*V1Controller) {
return func(ctrl *V1Controller) {
ctrl.allowRegistration = allowRegistration
}
}
type V1Controller struct { type V1Controller struct {
svc *services.AllServices svc *services.AllServices
maxUploadSize int64 maxUploadSize int64
isDemo bool isDemo bool
allowRegistration bool
} }
type ( type (
@ -54,6 +61,7 @@ func BaseUrlFunc(prefix string) func(s string) string {
func NewControllerV1(svc *services.AllServices, options ...func(*V1Controller)) *V1Controller { func NewControllerV1(svc *services.AllServices, options ...func(*V1Controller)) *V1Controller {
ctrl := &V1Controller{ ctrl := &V1Controller{
svc: svc, svc: svc,
allowRegistration: true,
} }
for _, opt := range options { for _, opt := range options {

View file

@ -27,6 +27,11 @@ func (ctrl *V1Controller) HandleUserRegistration() http.HandlerFunc {
return return
} }
if !ctrl.allowRegistration && regData.GroupToken == "" {
server.RespondError(w, http.StatusForbidden, nil)
return
}
_, err := ctrl.svc.User.RegisterUser(r.Context(), regData) _, err := ctrl.svc.User.RegisterUser(r.Context(), regData)
if err != nil { if err != nil {
log.Err(err).Msg("failed to register user") log.Err(err).Msg("failed to register user")

View file

@ -23,6 +23,7 @@ type Config struct {
Mailer MailerConf `yaml:"mailer"` Mailer MailerConf `yaml:"mailer"`
Swagger SwaggerConf `yaml:"swagger"` Swagger SwaggerConf `yaml:"swagger"`
Demo bool `yaml:"demo"` Demo bool `yaml:"demo"`
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
} }
type SwaggerConf struct { type SwaggerConf struct {

View file

@ -42,9 +42,10 @@ volumes:
| HBOX_MODE | production | application mode used for runtime behavior can be one of: development, production | | HBOX_MODE | production | application mode used for runtime behavior can be one of: development, production |
| HBOX_WEB_PORT | 7745 | port to run the web server on, in you're using docker do not change this | | HBOX_WEB_PORT | 7745 | port to run the web server on, in you're using docker do not change this |
| HBOX_WEB_HOST | | host to run the web server on, in you're using docker do not change this | | HBOX_WEB_HOST | | host to run the web server on, in you're using docker do not change this |
| HBOX_ALLOW_REGISTRATION | true | allow users to register themselves |
| HBOX_WEB_MAX_UPLOAD_SIZE | 10 | maximum file upload size supported in MB |
| HBOX_STORAGE_DATA | /data/ | path to the data directory, do not change this if you're using docker | | HBOX_STORAGE_DATA | /data/ | path to the data directory, do not change this if you're using docker |
| HBOX_STORAGE_SQLITE_URL | /data/homebox.db?_fk=1 | sqlite database url, in you're using docker do not change this | | HBOX_STORAGE_SQLITE_URL | /data/homebox.db?_fk=1 | sqlite database url, in you're using docker do not change this |
| HBOX_WEB_MAX_UPLOAD_SIZE | 10 | maximum file upload size supported in MB |
| HBOX_LOG_LEVEL | info | log level to use, can be one of: trace, debug, info, warn, error, critical | | HBOX_LOG_LEVEL | info | log level to use, can be one of: trace, debug, info, warn, error, critical |
| HBOX_LOG_FORMAT | text | log format to use, can be one of: text, json | | HBOX_LOG_FORMAT | text | log format to use, can be one of: text, json |
| HBOX_MAILER_HOST | | email host to use, if not set no email provider will be used | | HBOX_MAILER_HOST | | email host to use, if not set no email provider will be used |
@ -77,6 +78,8 @@ volumes:
--mailer-from/$HBOX_MAILER_FROM <string> --mailer-from/$HBOX_MAILER_FROM <string>
--swagger-host/$HBOX_SWAGGER_HOST <string> (default: localhost:7745) --swagger-host/$HBOX_SWAGGER_HOST <string> (default: localhost:7745)
--swagger-scheme/$HBOX_SWAGGER_SCHEME <string> (default: http) --swagger-scheme/$HBOX_SWAGGER_SCHEME <string> (default: http)
--demo/$HBOX_DEMO <bool>
--allow-registration/$HBOX_ALLOW_REGISTRATION <bool> (default: true)
--help/-h --help/-h
display this help message display this help message
``` ```

View file

@ -187,6 +187,12 @@ export interface LocationSummary {
updatedAt: Date; updatedAt: Date;
} }
export interface PaginationResultRepoItemSummary {
items: ItemSummary[];
page: number;
pageSize: number;
total: number;
}
export interface UserOut { export interface UserOut {
email: string; email: string;