diff --git a/config/runtime.exs b/config/runtime.exs index 47783183..7b19085a 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -44,8 +44,6 @@ config :cannery, Cannery.Repo, pool_size: String.to_integer(System.get_env("POOL_SIZE", "10")), socket_options: maybe_ipv6 -config :cannery, Cannery.Accounts, registration: System.get_env("REGISTRATION", "invite") - config :cannery, CanneryWeb.Endpoint, url: [scheme: "https", host: host, port: 443], http: [ @@ -56,6 +54,10 @@ config :cannery, CanneryWeb.Endpoint, ], server: true +if config_env() in [:dev, :prod] do + config :cannery, Cannery.Accounts, registration: System.get_env("REGISTRATION", "invite") +end + if config_env() == :prod do # 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 diff --git a/config/test.exs b/config/test.exs index 718ffc75..caed05b4 100644 --- a/config/test.exs +++ b/config/test.exs @@ -22,6 +22,9 @@ config :cannery, CanneryWeb.Endpoint, # In test we don't send emails. config :cannery, Cannery.Mailer, adapter: Swoosh.Adapters.Test +# Don't require invites for signups +config :cannery, Cannery.Accounts, registration: "public" + # Print only warnings and errors during test config :logger, level: :warn diff --git a/lib/cannery/accounts.ex b/lib/cannery/accounts.ex index fbe31e14..71f45179 100644 --- a/lib/cannery/accounts.ex +++ b/lib/cannery/accounts.ex @@ -117,6 +117,8 @@ defmodule Cannery.Accounts do :passed """ + @spec register_user(attrs :: map()) :: + {:ok, User.t()} | {:error, :invalid_token | User.changeset()} @spec register_user(attrs :: map(), Invite.token() | nil) :: {:ok, User.t()} | {:error, :invalid_token | User.changeset()} def register_user(attrs, invite_token \\ nil) do diff --git a/lib/cannery/accounts/invites.ex b/lib/cannery/accounts/invites.ex index 88be85e3..7f8e955d 100644 --- a/lib/cannery/accounts/invites.ex +++ b/lib/cannery/accounts/invites.ex @@ -85,7 +85,9 @@ defmodule Cannery.Accounts.Invites do end end - @spec get_invite_by_token(Invite.token()) :: {:ok, Invite.t()} | {:error, :invalid_token} + @spec get_invite_by_token(Invite.token() | nil) :: {:ok, Invite.t()} | {:error, :invalid_token} + defp get_invite_by_token(token) when token in [nil, ""], do: {:error, :invalid_token} + defp get_invite_by_token(token) do Repo.one( from i in Invite,