Refactor all configuration

This commit is contained in:
Alex
2023-09-09 16:59:14 +02:00
parent 71055223bd
commit 54b9c748b7
21 changed files with 253 additions and 239 deletions

View File

@@ -1,7 +1,7 @@
## v1.6.0
- Improve QR code readability
- Add ARM Docker image
- Refactor all runtime configuration
## v1.5.0

View File

@@ -12,7 +12,6 @@ config :claper,
# Configures the endpoint
config :claper, ClaperWeb.Endpoint,
url: [host: "localhost"],
render_errors: [view: ClaperWeb.ErrorView, accepts: ~w(html json), layout: false],
pubsub_server: Claper.PubSub,
live_view: [signing_salt: "DN0vwriJgVkHG0kn3hF5JKho/DE66onv"]
@@ -60,15 +59,6 @@ config :phoenix, :json_library, Jason
config :porcelain, driver: Porcelain.Driver.Basic
config :ex_aws,
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role],
region: {:system, "AWS_REGION"},
normalize_path: false
config :claper,
max_file_size: {:system, "MAX_FILE_SIZE_MB", "15"}
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

View File

@@ -1,14 +1,5 @@
import Config
# Configure your database
config :claper, Claper.Repo,
username: "claper",
password: "claper",
database: "postgres",
hostname: "localhost",
show_sensitive_data_on_connection_error: true,
pool_size: 10
# For development, we disable any cache and enable
# debugging and code reloading.
#
@@ -16,13 +7,9 @@ config :claper, Claper.Repo,
# watchers to your application. For example, we use it
# with esbuild to bundle .js and .css sources.
config :claper, ClaperWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {0, 0, 0, 0}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "sm/ICUyPRRbxOU0s0NN/KFY8ze7XRALuvFLoyidy8l1ZBeWl8p/zFhfdI5II+Jdk",
watchers: [
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
@@ -41,30 +28,6 @@ config :claper, ClaperWeb.Endpoint,
]
]
# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
# mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
# https: [
# port: 4001,
# cipher_suite: :strong,
# keyfile: "priv/cert/selfsigned_key.pem",
# certfile: "priv/cert/selfsigned.pem"
# ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.
# Watch static and templates for browser reloading.
config :claper, ClaperWeb.Endpoint,
live_reload: [

View File

@@ -1,51 +1,8 @@
import Config
# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
# when generating URLs.
#
# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and
# before starting your production server.
config :claper, ClaperWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json",
server: true
# Do not print debug messages in production
config :logger, level: :info
# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
# config :claper, ClaperWeb.Endpoint,
# ...,
# url: [host: "example.com", port: 443],
# https: [
# ...,
# port: 443,
# cipher_suite: :strong,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
# ]
#
# The `cipher_suite` is set to `:strong` to support only the
# latest and more secure SSL ciphers. This means old browsers
# and clients may not be supported. You can set it to
# `:compatible` for wider support.
#
# `:keyfile` and `:certfile` expect an absolute path to the key
# and cert in disk or a relative path inside priv, for example
# "priv/ssl/server.key". For all supported SSL configuration
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
#
# We also recommend setting `force_ssl` in your endpoint, ensuring
# no data is ever sent via http, always redirecting to https:
#
# config :claper, ClaperWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

View File

@@ -1,96 +1,127 @@
import Config
import Claper.ConfigHelpers
# config/runtime.exs is executed for all environments, including
# during releases. It is executed after compilation and before the
# system starts, so it is typically used to load production configuration
# and secrets from environment variables or elsewhere. Do not define
# any compile-time configuration in here, as it won't be applied.
# The block below contains prod specific runtime configuration.
if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""
config_dir = System.get_env("CONFIG_DIR", "/run/secrets")
config :claper, Claper.Repo,
url: database_url,
ssl: System.get_env("DB_SSL") == "true" || false,
ssl_opts: [
verify: :verify_none
],
prepare: :unnamed,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
queue_target: String.to_integer(System.get_env("QUEUE_TARGET") || "5000")
database_url =
get_var_from_path_or_env(
config_dir,
"DATABASE_URL",
"postgres://claper:claper@localhost:5432/postgres"
)
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
# want to use a different value for prod and you most likely don't want
# to check this value into version control, so we use an environment
# variable instead.
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""
db_ssl = get_var_from_path_or_env(config_dir, "DB_SSL", "false") |> String.to_existing_atom()
config :claper, ClaperWeb.Endpoint,
url: [
host: System.get_env("ENDPOINT_HOST") || "localhost",
port: String.to_integer(System.get_env("ENDPOINT_PORT") || "80")
],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: String.to_integer(System.get_env("PORT") || "4000")
],
secret_key_base: secret_key_base
# Listen IP supports IPv4 and IPv6 addresses.
listen_ip =
(
str = get_var_from_path_or_env(config_dir, "LISTEN_IP") || "0.0.0.0"
# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
# config :claper, ClaperWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
case :inet.parse_address(String.to_charlist(str)) do
{:ok, ip_addr} ->
ip_addr
# ## Configuring the mailer
#
# In production you need to configure the mailer to use a different adapter.
# Also, you may need to configure the Swoosh API client of your choice if you
# are not using SMTP. Here is an example of the configuration:
#
# config :claper, Claper.Mailer,
# adapter: Swoosh.Adapters.Mailgun,
# api_key: System.get_env("MAILGUN_API_KEY"),
# domain: System.get_env("MAILGUN_DOMAIN")
#
# For this example you need include a HTTP client required by Swoosh API client.
# Swoosh supports Hackney and Finch out of the box:
#
{:error, reason} ->
raise "Invalid LISTEN_IP '#{str}' error: #{inspect(reason)}"
end
)
if System.get_env("MAIL_TRANSPORT", "local") == "smtp" do
config :claper, Claper.Mailer,
adapter: Swoosh.Adapters.SMTP,
relay: System.get_env("SMTP_RELAY"),
username: System.get_env("SMTP_USERNAME"),
password: System.get_env("SMTP_PASSWORD"),
ssl: System.get_env("SMTP_SSL", "true") == "true",
# always, never, if_available
tls: String.to_atom(System.get_env("SMTP_TLS", "always")),
# always, never, if_available
auth: String.to_atom(System.get_env("SMTP_AUTH", "always")),
port: String.to_integer(System.get_env("SMTP_PORT", "25"))
end
port = get_int_from_path_or_env(config_dir, "PORT", "4000")
config :swoosh, :api_client, Swoosh.ApiClient.Finch
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
secret_key_base = get_var_from_path_or_env(config_dir, "SECRET_KEY_BASE", nil)
case secret_key_base do
nil ->
raise "SECRET_KEY_BASE configuration option is required. See https://docs.claper.co/configuration.html#production-docker"
key when byte_size(key) < 32 ->
raise "SECRET_KEY_BASE must be at least 32 bytes long. See https://docs.claper.co/configuration.html#production-docker"
_ ->
nil
end
endpoint_host = get_var_from_path_or_env(config_dir, "ENDPOINT_HOST", "localhost")
endpoint_port = get_int_from_path_or_env(config_dir, "ENDPOINT_PORT", 4000)
max_file_size = get_int_from_path_or_env(config_dir, "MAX_FILE_SIZE_MB", 15)
enable_account_creation = get_var_from_path_or_env(config_dir, "ENABLE_ACCOUNT_CREATION", "true") |> String.to_existing_atom()
pool_size = get_int_from_path_or_env(config_dir, "POOL_SIZE", 10)
queue_target = get_int_from_path_or_env(config_dir, "QUEUE_TARGET", 5_000)
mail_transport = get_var_from_path_or_env(config_dir, "MAIL_TRANSPORT", "local")
smtp_relay = get_var_from_path_or_env(config_dir, "SMTP_RELAY", nil)
smtp_username = get_var_from_path_or_env(config_dir, "SMTP_USERNAME", nil)
smtp_password = get_var_from_path_or_env(config_dir, "SMTP_PASSWORD", nil)
smtp_ssl = get_var_from_path_or_env(config_dir, "SMTP_SSL", "true") |> String.to_existing_atom()
smtp_tls = get_var_from_path_or_env(config_dir, "SMTP_TLS", "always")
smtp_auth = get_var_from_path_or_env(config_dir, "SMTP_AUTH", "always")
smtp_port = get_int_from_path_or_env(config_dir, "SMTP_PORT", 25)
aws_access_key_id = get_var_from_path_or_env(config_dir, "AWS_ACCESS_KEY_ID", nil)
aws_secret_access_key = get_var_from_path_or_env(config_dir, "AWS_SECRET_ACCESS_KEY", nil)
aws_region = get_var_from_path_or_env(config_dir, "AWS_REGION", nil)
config :claper, Claper.Repo,
url: database_url,
ssl: db_ssl,
ssl_opts: [
verify: :verify_none
],
prepare: :unnamed,
pool_size: pool_size,
queue_target: queue_target
config :claper, ClaperWeb.Endpoint,
url: [
host: endpoint_host,
port: endpoint_port
],
http: [
ip: listen_ip,
port: port,
transport_options: [max_connections: :infinity],
protocol_options: [max_request_line_length: 8192, max_header_value_length: 8192]
],
secret_key_base: secret_key_base
config :claper,
max_file_size: max_file_size,
enable_account_creation: enable_account_creation
config :claper, :presentations,
storage: get_var_from_path_or_env(config_dir, "PRESENTATION_STORAGE", "local"),
aws_bucket: get_var_from_path_or_env(config_dir, "AWS_PRES_BUCKET", nil),
resolution: get_var_from_path_or_env(config_dir, "GS_JPG_RESOLUTION", "300x300")
config :claper, :mail,
from: get_var_from_path_or_env(config_dir, "MAIL_FROM", "noreply@claper.co"),
from_name: get_var_from_path_or_env(config_dir, "MAIL_FROM_NAME", "Claper")
config :claper, ClaperWeb.MailboxGuard,
username: get_var_from_path_or_env(config_dir, "MAILBOX_USER", nil),
password: get_var_from_path_or_env(config_dir, "MAILBOX_PASSWORD", nil),
enabled: get_var_from_path_or_env(config_dir, "ENABLE_MAILBOX_ROUTE", "false") |> String.to_existing_atom()
if mail_transport == "smtp" do
config :claper, Claper.Mailer,
adapter: Swoosh.Adapters.SMTP,
relay: smtp_relay,
username: smtp_username,
password: smtp_password,
ssl: smtp_ssl,
# always, never, if_available
tls: smtp_tls,
# always, never, if_available
auth: smtp_auth,
port: smtp_port
end
config :ex_aws,
access_key_id: aws_access_key_id,
secret_access_key: aws_secret_access_key,
region: aws_region,
normalize_path: false
config :swoosh, :api_client, Swoosh.ApiClient.Finch

View File

@@ -0,0 +1,26 @@
defmodule Claper.ConfigHelpers do
def get_var_from_path_or_env(config_dir, var_name, default \\ nil) do
var_path = Path.join(config_dir, var_name)
if File.exists?(var_path) do
File.read!(var_path) |> String.trim()
else
System.get_env(var_name, default)
end
end
def get_int_from_path_or_env(config_dir, var_name, default \\ nil) do
var = get_var_from_path_or_env(config_dir, var_name)
case var do
nil ->
default
var ->
case Integer.parse(var) do
{int, ""} -> int
_ -> raise "Config variable #{var_name} must be an integer. Got #{var}"
end
end
end
end

View File

@@ -4,6 +4,10 @@ defmodule Claper.Repo do
adapter: Ecto.Adapters.Postgres
def init(_type, config) do
{:ok, Keyword.put(config, :url, System.get_env("DATABASE_URL"))}
if url = System.get_env("DATABASE_URL") do
{:ok, Keyword.put(config, :url, url)}
else
{:ok, config}
end
end
end

View File

@@ -46,7 +46,7 @@ defmodule Claper.Tasks.Converter do
def clear(hash) do
IO.puts("Clearing #{hash}...")
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
if get_presentation_storage() == "local" do
File.rm_rf(
Path.join([
:code.priv_dir(:claper),
@@ -57,11 +57,11 @@ defmodule Claper.Tasks.Converter do
)
else
stream =
ExAws.S3.list_objects(System.get_env("AWS_PRES_BUCKET"), prefix: "presentations/#{hash}")
ExAws.S3.list_objects(get_aws_bucket(), prefix: "presentations/#{hash}")
|> ExAws.stream!()
|> Stream.map(& &1.key)
ExAws.S3.delete_all_objects(System.get_env("AWS_PRES_BUCKET"), stream) |> ExAws.request()
ExAws.S3.delete_all_objects(get_aws_bucket(), stream) |> ExAws.request()
end
end
@@ -98,7 +98,7 @@ defmodule Claper.Tasks.Converter do
defp file_to_pdf(_ext, _path, _file), do: %Result{status: 0}
defp pdf_to_jpg(%Result{status: 0}, path, _presentation, _user_id) do
resolution = System.get_env("GS_JPG_RESOLUTION", "300x300")
resolution = get_resolution()
Porcelain.exec(
"gs",
@@ -123,7 +123,7 @@ defmodule Claper.Tasks.Converter do
# assign new hash to avoid cache issues
new_hash = :erlang.phash2("#{hash}-#{System.system_time(:second)}")
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
if get_presentation_storage() == "local" do
File.rename(
Path.join([
:code.priv_dir(:claper),
@@ -145,7 +145,7 @@ defmodule Claper.Tasks.Converter do
f
|> S3.Upload.stream_file()
|> S3.upload(
System.get_env("AWS_PRES_BUCKET"),
get_aws_bucket(),
"presentations/#{new_hash}/#{Path.basename(f)}",
acl: "public-read"
)
@@ -171,7 +171,7 @@ defmodule Claper.Tasks.Converter do
"length" => length,
"status" => "done"
}) do
unless System.get_env("PRESENTATION_STORAGE", "local") == "local", do: File.rm_rf!(path)
unless get_presentation_storage() == "local", do: File.rm_rf!(path)
Phoenix.PubSub.broadcast(
Claper.PubSub,
@@ -195,4 +195,17 @@ defmodule Claper.Tasks.Converter do
)
end
end
defp get_presentation_storage do
Application.get_env(:claper, :presentations) |> Keyword.get(:storage)
end
defp get_aws_bucket do
Application.get_env(:claper, :presentations) |> Keyword.get(:aws_bucket)
end
defp get_resolution do
Application.get_env(:claper, :presentations) |> Keyword.get(:resolution)
end
end

View File

@@ -0,0 +1,24 @@
defmodule ClaperWeb.MailboxGuard do
import Plug.Conn
import Phoenix.Controller
def init(default), do: default
def call(conn, _params \\ %{}) do
mailbox_username = Application.get_env(:claper, ClaperWeb.MailboxGuard) |> Keyword.get(:username)
mailbox_password = Application.get_env(:claper, ClaperWeb.MailboxGuard) |> Keyword.get(:password)
mailbox_enabled = Application.get_env(:claper, ClaperWeb.MailboxGuard) |> Keyword.get(:enabled)
IO.puts mailbox_enabled
if mailbox_enabled do
if mailbox_username && mailbox_password do
Plug.BasicAuth.basic_auth(conn, username: mailbox_username, password: mailbox_password)
else
conn
end
else
conn |> redirect(to: "/") |> halt()
end
end
end

View File

@@ -6,8 +6,14 @@ defmodule ClaperWeb.UserRegistrationController do
alias ClaperWeb.UserAuth
def new(conn, _params) do
changeset = Accounts.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)
if Application.get_env(:claper, :enable_account_creation) do
changeset = Accounts.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)
else
conn
|> put_flash(:error, gettext("Account creation is disabled"))
|> redirect(to: "/")
end
end
def confirm(conn, _params) do

View File

@@ -213,13 +213,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
end
defp get_max_file_size() do
case Application.fetch_env!(:claper, :max_file_size) do
{:system, env_var, default} ->
String.to_integer(System.get_env(env_var) || default)
direct_value ->
direct_value
end
Application.get_env(:claper, :max_file_size)
end
def error_to_string(:too_large), do: gettext("Your file is too large")

View File

@@ -358,7 +358,7 @@
phx-value-page={index}
class="py-4 focus:outline-none"
>
<%= if System.get_env("PRESENTATION_STORAGE", "local") == "local" do %>
<%= if Application.get_env(:claper, :presentations) |> Keyword.get(:storage) == "local" do %>
<img
class="w-1/3 mx-auto"
src={"/uploads/#{@event.presentation_file.hash}/#{index+1}.jpg"}
@@ -366,7 +366,7 @@
<% else %>
<img
class="w-1/3 mx-auto"
src={"https://#{System.get_env("AWS_PRES_BUCKET")}.s3.#{System.get_env("AWS_REGION")}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{index+1}.jpg"}
src={"https://#{Application.get_env(:claper, :presentations) |> Keyword.get(:aws_bucket)}.s3.#{Application.get_env(:ex_aws, :region)}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{index+1}.jpg"}
/>
<% end %>
</button>

View File

@@ -115,7 +115,7 @@
<!-- SLIDES -->
<div id="slider" phx-update="ignore">
<%= for index <- 1..@event.presentation_file.length do %>
<%= if System.get_env("PRESENTATION_STORAGE", "local") == "local" do %>
<%= if Application.get_env(:claper, :presentations) |> Keyword.get(:storage) == "local" do %>
<img
class="w-1/3 max-h-screen mx-auto"
src={"/uploads/#{@event.presentation_file.hash}/#{index}.jpg"}
@@ -123,7 +123,7 @@
<% else %>
<img
class="w-full max-h-screen mx-auto inline-block"
src={"https://#{System.get_env("AWS_PRES_BUCKET")}.s3.#{System.get_env("AWS_REGION")}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{index}.jpg"}
src={"https://#{Application.get_env(:claper, :presentations) |> Keyword.get(:aws_bucket)}.s3.#{Application.get_env(:ex_aws, :region)}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{index}.jpg"}
/>
<% end %>
<% end %>

View File

@@ -159,7 +159,7 @@
</h3>
<%= for position <- 0..@event.presentation_file.length-1 do %>
<div class="my-10">
<%= if System.get_env("PRESENTATION_STORAGE", "local") == "local" do %>
<%= if Application.get_env(:claper, :presentations) |> Keyword.get(:storage) == "local" do %>
<img
class="w-1/3 mx-auto"
src={"/uploads/#{@event.presentation_file.hash}/#{position+1}.jpg"}
@@ -167,7 +167,7 @@
<% else %>
<img
class="w-1/2 md:w-1/3 mb-4"
src={"https://#{System.get_env("AWS_PRES_BUCKET")}.s3.#{System.get_env("AWS_REGION")}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{position+1}.jpg"}
src={"https://#{Application.get_env(:claper, :presentations) |> Keyword.get(:aws_bucket)}.s3.#{Application.get_env(:ex_aws, :region)}.amazonaws.com/presentations/#{@event.presentation_file.hash}/#{position+1}.jpg"}
/>
<% end %>

View File

@@ -6,8 +6,8 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
new()
|> to(email)
|> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
{Application.get_env(:claper, :mail) |> Keyword.get(:from_name),
Application.get_env(:claper, :mail) |> Keyword.get(:from)}
)
|> subject(gettext("Connect to Claper"))
|> render_body("magic.html", %{url: url})
@@ -17,8 +17,8 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
new()
|> to(email)
|> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
{Application.get_env(:claper, :mail) |> Keyword.get(:from_name),
Application.get_env(:claper, :mail) |> Keyword.get(:from)}
)
|> subject(gettext("Next steps to boost your presentations"))
|> render_body("welcome.html", %{email: email})
@@ -28,8 +28,8 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
new()
|> to(user.email)
|> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
{Application.get_env(:claper, :mail) |> Keyword.get(:from_name),
Application.get_env(:claper, :mail) |> Keyword.get(:from)}
)
|> subject(gettext("Update email instructions"))
|> render_body("change.html", %{user: user, url: url})

View File

@@ -14,8 +14,8 @@ defmodule ClaperWeb.Router do
plug(ClaperWeb.Plugs.Locale)
end
pipeline :protect_with_basic_auth do
plug :basic_auth
pipeline :protect_mailbox do
plug ClaperWeb.MailboxGuard
end
pipeline :api do
@@ -91,15 +91,9 @@ defmodule ClaperWeb.Router do
#
# Note that preview only shows emails that were sent by the same
# node running the Phoenix server.
if Mix.env() == :dev || System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
if Mix.env() == :dev do
scope "/dev" do
if System.get_env("MAILBOX_USER") && System.get_env("MAILBOX_PASSWORD") &&
System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
pipe_through [:browser, :protect_with_basic_auth]
else
pipe_through [:browser]
end
pipe_through [:browser, :protect_mailbox]
forward("/mailbox", Plug.Swoosh.MailboxPreview)
end
end
@@ -108,10 +102,8 @@ defmodule ClaperWeb.Router do
scope "/", ClaperWeb do
pipe_through([:browser, :redirect_if_user_is_authenticated])
if System.get_env("ENABLE_ACCOUNT_CREATION", "true") == "true" do
get("/users/register", UserRegistrationController, :new)
post("/users/register", UserRegistrationController, :create)
end
get("/users/register", UserRegistrationController, :new)
post("/users/register", UserRegistrationController, :create)
get("/users/register/confirm", UserRegistrationController, :confirm)
get("/users/log_in", UserSessionController, :new)
@@ -141,10 +133,4 @@ defmodule ClaperWeb.Router do
get("/users/confirm/:token", UserConfirmationController, :edit)
post("/users/confirm/:token", UserConfirmationController, :update)
end
defp basic_auth(conn, _opts) do
username = System.fetch_env!("MAILBOX_USER")
password = System.fetch_env!("MAILBOX_PASSWORD")
Plug.BasicAuth.basic_auth(conn, username: username, password: password)
end
end

View File

@@ -69,7 +69,7 @@
</.form>
<div class="mt-4 text-center">
<%= if System.get_env("ENABLE_ACCOUNT_CREATION", "true") == "true" do %>
<%= if Application.get_env(:claper, :enable_account_creation) do %>
<%= link(gettext("Create account"),
to: Routes.user_registration_path(@conn, :new),
class: "text-white text-sm text-center"

View File

@@ -350,12 +350,12 @@ msgstr "Datei hochladen"
msgid "or drag and drop"
msgstr "oder drag and drop"
#: lib/claper_web/live/event_live/event_form_component.ex:226
#: lib/claper_web/live/event_live/event_form_component.ex:220
#, elixir-autogen, elixir-format
msgid "You have selected an incorrect file type"
msgstr "Sie haben einen falschen Dateitype auswählen"
#: lib/claper_web/live/event_live/event_form_component.ex:225
#: lib/claper_web/live/event_live/event_form_component.ex:219
#, elixir-autogen, elixir-format
msgid "Your file is too large"
msgstr "Ihrer Datei ist zu groẞ"
@@ -385,7 +385,7 @@ msgstr "Neue Umfrage"
msgid "Title of your poll"
msgstr "Name Ihrer Umfrage"
#: lib/claper_web/live/event_live/event_form_component.ex:227
#: lib/claper_web/live/event_live/event_form_component.ex:221
#, elixir-autogen, elixir-format
msgid "Upload failed"
msgstr "Hochladung scheitert"
@@ -956,3 +956,8 @@ msgstr "Benutze deinen Namen"
#, elixir-autogen, elixir-format
msgid "disabled"
msgstr "deaktiviert"
#: lib/claper_web/controllers/user_registration_controller.ex:14
#, elixir-autogen, elixir-format
msgid "Account creation is disabled"
msgstr "Kontoerstellung ist deaktiviert"

View File

@@ -352,12 +352,12 @@ msgstr ""
msgid "or drag and drop"
msgstr ""
#: lib/claper_web/live/event_live/event_form_component.ex:226
#: lib/claper_web/live/event_live/event_form_component.ex:220
#, elixir-autogen, elixir-format
msgid "You have selected an incorrect file type"
msgstr ""
#: lib/claper_web/live/event_live/event_form_component.ex:225
#: lib/claper_web/live/event_live/event_form_component.ex:219
#, elixir-autogen, elixir-format
msgid "Your file is too large"
msgstr ""
@@ -387,7 +387,7 @@ msgstr ""
msgid "Title of your poll"
msgstr ""
#: lib/claper_web/live/event_live/event_form_component.ex:227
#: lib/claper_web/live/event_live/event_form_component.ex:221
#, elixir-autogen, elixir-format
msgid "Upload failed"
msgstr ""
@@ -958,3 +958,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "disabled"
msgstr ""
#: lib/claper_web/controllers/user_registration_controller.ex:14
#, elixir-autogen, elixir-format
msgid "Account creation is disabled"
msgstr ""

View File

@@ -350,12 +350,12 @@ msgstr "Upload a file"
msgid "or drag and drop"
msgstr "or drag and drop"
#: lib/claper_web/live/event_live/event_form_component.ex:226
#: lib/claper_web/live/event_live/event_form_component.ex:220
#, elixir-autogen, elixir-format
msgid "You have selected an incorrect file type"
msgstr "You have selected an incorrect file type"
#: lib/claper_web/live/event_live/event_form_component.ex:225
#: lib/claper_web/live/event_live/event_form_component.ex:219
#, elixir-autogen, elixir-format
msgid "Your file is too large"
msgstr "Your file is too large"
@@ -385,7 +385,7 @@ msgstr "New poll"
msgid "Title of your poll"
msgstr "Title of your poll"
#: lib/claper_web/live/event_live/event_form_component.ex:227
#: lib/claper_web/live/event_live/event_form_component.ex:221
#, elixir-autogen, elixir-format
msgid "Upload failed"
msgstr "Upload failed"
@@ -956,3 +956,8 @@ msgstr "Use your name"
#, elixir-autogen, elixir-format
msgid "disabled"
msgstr "disabled"
#: lib/claper_web/controllers/user_registration_controller.ex:14
#, elixir-autogen, elixir-format
msgid "Account creation is disabled"
msgstr ""

View File

@@ -350,12 +350,12 @@ msgstr "Chargez un fichier"
msgid "or drag and drop"
msgstr "ou glisser-déposer"
#: lib/claper_web/live/event_live/event_form_component.ex:226
#: lib/claper_web/live/event_live/event_form_component.ex:220
#, elixir-autogen, elixir-format
msgid "You have selected an incorrect file type"
msgstr "Vous avez sélectionné un type de fichier incorrect"
#: lib/claper_web/live/event_live/event_form_component.ex:225
#: lib/claper_web/live/event_live/event_form_component.ex:219
#, elixir-autogen, elixir-format
msgid "Your file is too large"
msgstr "Votre fichier est trop volumineux"
@@ -385,7 +385,7 @@ msgstr "Nouveau sondage"
msgid "Title of your poll"
msgstr "Titre de votre sondage"
#: lib/claper_web/live/event_live/event_form_component.ex:227
#: lib/claper_web/live/event_live/event_form_component.ex:221
#, elixir-autogen, elixir-format
msgid "Upload failed"
msgstr "Échec du chargement"
@@ -961,3 +961,8 @@ msgstr "Utiliser votre nom"
#, elixir-autogen, elixir-format
msgid "disabled"
msgstr "désactivé"
#: lib/claper_web/controllers/user_registration_controller.ex:14
#, elixir-autogen, elixir-format
msgid "Account creation is disabled"
msgstr "La création de compte est désactivée"