Make require-login work

This commit is contained in:
binwiederhier 2025-05-24 14:46:18 -04:00
parent 1561251028
commit 74ea78fbdc
8 changed files with 54 additions and 43 deletions

View file

@ -159,6 +159,7 @@ func execServe(c *cli.Context) error {
webRoot := c.String("web-root") webRoot := c.String("web-root")
enableSignup := c.Bool("enable-signup") enableSignup := c.Bool("enable-signup")
enableLogin := c.Bool("enable-login") enableLogin := c.Bool("enable-login")
requireLogin := c.Bool("require-login")
enableReservations := c.Bool("enable-reservations") enableReservations := c.Bool("enable-reservations")
upstreamBaseURL := c.String("upstream-base-url") upstreamBaseURL := c.String("upstream-base-url")
upstreamAccessToken := c.String("upstream-access-token") upstreamAccessToken := c.String("upstream-access-token")
@ -408,6 +409,7 @@ func execServe(c *cli.Context) error {
conf.BillingContact = billingContact conf.BillingContact = billingContact
conf.EnableSignup = enableSignup conf.EnableSignup = enableSignup
conf.EnableLogin = enableLogin conf.EnableLogin = enableLogin
conf.RequireLogin = requireLogin
conf.EnableReservations = enableReservations conf.EnableReservations = enableReservations
conf.EnableMetrics = enableMetrics conf.EnableMetrics = enableMetrics
conf.MetricsListenHTTP = metricsListenHTTP conf.MetricsListenHTTP = metricsListenHTTP

View file

@ -150,6 +150,7 @@ type Config struct {
BillingContact string BillingContact string
EnableSignup bool // Enable creation of accounts via API and UI EnableSignup bool // Enable creation of accounts via API and UI
EnableLogin bool EnableLogin bool
RequireLogin bool
EnableReservations bool // Allow users with role "user" to own/reserve topics EnableReservations bool // Allow users with role "user" to own/reserve topics
EnableMetrics bool EnableMetrics bool
AccessControlAllowOrigin string // CORS header field to restrict access from web clients AccessControlAllowOrigin string // CORS header field to restrict access from web clients

View file

@ -586,7 +586,7 @@ func (s *Server) handleWebConfig(w http.ResponseWriter, _ *http.Request, _ *visi
EnableCalls: s.config.TwilioAccount != "", EnableCalls: s.config.TwilioAccount != "",
EnableEmails: s.config.SMTPSenderFrom != "", EnableEmails: s.config.SMTPSenderFrom != "",
EnableReservations: s.config.EnableReservations, EnableReservations: s.config.EnableReservations,
ReuqireLogin: s.config.RequireLogin, RequireLogin: s.config.RequireLogin,
EnableWebPush: s.config.WebPushPublicKey != "", EnableWebPush: s.config.WebPushPublicKey != "",
BillingContact: s.config.BillingContact, BillingContact: s.config.BillingContact,
WebPushPublicKey: s.config.WebPushPublicKey, WebPushPublicKey: s.config.WebPushPublicKey,

View file

@ -401,13 +401,13 @@ type apiConfigResponse struct {
BaseURL string `json:"base_url"` BaseURL string `json:"base_url"`
AppRoot string `json:"app_root"` AppRoot string `json:"app_root"`
EnableLogin bool `json:"enable_login"` EnableLogin bool `json:"enable_login"`
RequireLogin bool `json:"require_login"`
EnableSignup bool `json:"enable_signup"` EnableSignup bool `json:"enable_signup"`
EnablePayments bool `json:"enable_payments"` EnablePayments bool `json:"enable_payments"`
EnableCalls bool `json:"enable_calls"` EnableCalls bool `json:"enable_calls"`
EnableEmails bool `json:"enable_emails"` EnableEmails bool `json:"enable_emails"`
EnableReservations bool `json:"enable_reservations"` EnableReservations bool `json:"enable_reservations"`
EnableWebPush bool `json:"enable_web_push"` EnableWebPush bool `json:"enable_web_push"`
RequireLogin bool `json:"require_login"`
BillingContact string `json:"billing_contact"` BillingContact string `json:"billing_contact"`
WebPushPublicKey string `json:"web_push_public_key"` WebPushPublicKey string `json:"web_push_public_key"`
DisallowedTopics []string `json:"disallowed_topics"` DisallowedTopics []string `json:"disallowed_topics"`

View file

@ -9,6 +9,7 @@ var config = {
base_url: window.location.origin, // Change to test against a different server base_url: window.location.origin, // Change to test against a different server
app_root: "/", app_root: "/",
enable_login: true, enable_login: true,
require_login: true,
enable_signup: true, enable_signup: true,
enable_payments: false, enable_payments: false,
enable_reservations: true, enable_reservations: true,

View file

@ -164,36 +164,39 @@ const NavList = (props) => {
<ListItemText primary={t("nav_button_account")} /> <ListItemText primary={t("nav_button_account")} />
</ListItemButton> </ListItemButton>
)} )}
{session.exists() || !config.require_login && ( {session.exists() ||
<ListItemButton onClick={() => navigate(routes.settings)} selected={location.pathname === routes.settings}> (!config.require_login && (
<ListItemIcon> <ListItemButton onClick={() => navigate(routes.settings)} selected={location.pathname === routes.settings}>
<SettingsIcon /> <ListItemIcon>
</ListItemIcon> <SettingsIcon />
<ListItemText primary={t("nav_button_settings")} /> </ListItemIcon>
</ListItemButton> <ListItemText primary={t("nav_button_settings")} />
)} </ListItemButton>
))}
<ListItemButton onClick={() => openUrl("/docs")}> <ListItemButton onClick={() => openUrl("/docs")}>
<ListItemIcon> <ListItemIcon>
<ArticleIcon /> <ArticleIcon />
</ListItemIcon> </ListItemIcon>
<ListItemText primary={t("nav_button_documentation")} /> <ListItemText primary={t("nav_button_documentation")} />
</ListItemButton> </ListItemButton>
{session.exists() || !config.require_login && ( {session.exists() ||
<ListItemButton onClick={() => props.onPublishMessageClick()}> (!config.require_login && (
<ListItemIcon> <ListItemButton onClick={() => props.onPublishMessageClick()}>
<Send /> <ListItemIcon>
</ListItemIcon> <Send />
<ListItemText primary={t("nav_button_publish_message")} /> </ListItemIcon>
</ListItemButton> <ListItemText primary={t("nav_button_publish_message")} />
)} </ListItemButton>
{session.exists() || !config.require_login && ( ))}
<ListItemButton onClick={() => setSubscribeDialogOpen(true)}> {session.exists() ||
<ListItemIcon> (!config.require_login && (
<AddIcon /> <ListItemButton onClick={() => setSubscribeDialogOpen(true)}>
</ListItemIcon> <ListItemIcon>
<ListItemText primary={t("nav_button_subscribe")} /> <AddIcon />
</ListItemButton> </ListItemIcon>
)} <ListItemText primary={t("nav_button_subscribe")} />
</ListItemButton>
))}
{showUpgradeBanner && ( {showUpgradeBanner && (
// The text background gradient didn't seem to do well with switching between light/dark mode, // The text background gradient didn't seem to do well with switching between light/dark mode,
// So adding a `key` forces React to replace the entire component when the theme changes // So adding a `key` forces React to replace the entire component when the theme changes

View file

@ -640,12 +640,16 @@ const NoSubscriptions = () => {
{!session.exists() && config.require_login && t("notifications_no_subscriptions_login_title")} {!session.exists() && config.require_login && t("notifications_no_subscriptions_login_title")}
</Typography> </Typography>
<Paragraph> <Paragraph>
{!session.exists() && !config.require_login && t("notifications_no_subscriptions_description", { {!session.exists() &&
linktext: t("nav_button_subscribe"), !config.require_login &&
})} t("notifications_no_subscriptions_description", {
{!session.exists() && config.require_login && t("notifications_no_subscriptions_login_description", { linktext: t("nav_button_subscribe"),
linktext: t("action_bar_sign_in"), })}
})} {!session.exists() &&
config.require_login &&
t("notifications_no_subscriptions_login_description", {
linktext: t("action_bar_sign_in"),
})}
</Paragraph> </Paragraph>
<Paragraph> <Paragraph>
<ForMoreDetails /> <ForMoreDetails />

View file

@ -66,20 +66,20 @@ const maybeUpdateAccountSettings = async (payload) => {
}; };
const Preferences = () => { const Preferences = () => {
if (!session.exists() or !config.requireLogin) { if (!session.exists() || !config.require_login) {
window.location.href = routes.app; window.location.href = routes.app;
return <></>; return <></>;
} }
return ( return (
<Container maxWidth="md" sx={{ marginTop: 3, marginBottom: 3 }}> <Container maxWidth="md" sx={{ marginTop: 3, marginBottom: 3 }}>
<Stack spacing={3}> <Stack spacing={3}>
<Notifications /> <Notifications />
<Reservations /> <Reservations />
<Users /> <Users />
<Appearance /> <Appearance />
</Stack> </Stack>
</Container> </Container>
); );
}; };
const Notifications = () => { const Notifications = () => {