forked from shibao/cannery
		
	merge base project into cannery
This commit is contained in:
		@@ -27,21 +27,21 @@ defmodule Cannery.Email do
 | 
			
		||||
  @spec generate_email(key :: String.t(), User.t(), attrs :: map()) :: t()
 | 
			
		||||
  def generate_email("welcome", user, %{"url" => url}) do
 | 
			
		||||
    user
 | 
			
		||||
    |> base_email(dgettext("emails", "Confirm your %{name} account", name: "Cannery"))
 | 
			
		||||
    |> base_email(dgettext("emails", "Confirm your Cannery account"))
 | 
			
		||||
    |> render_body("confirm_email.html", %{user: user, url: url})
 | 
			
		||||
    |> text_body(EmailView.render("confirm_email.txt", %{user: user, url: url}))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def generate_email("reset_password", user, %{"url" => url}) do
 | 
			
		||||
    user
 | 
			
		||||
    |> base_email(dgettext("emails", "Reset your %{name} password", name: "Cannery"))
 | 
			
		||||
    |> base_email(dgettext("emails", "Reset your Cannery password"))
 | 
			
		||||
    |> render_body("reset_password.html", %{user: user, url: url})
 | 
			
		||||
    |> text_body(EmailView.render("reset_password.txt", %{user: user, url: url}))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def generate_email("update_email", user, %{"url" => url}) do
 | 
			
		||||
    user
 | 
			
		||||
    |> base_email(dgettext("emails", "Update your %{name} email", name: "Cannery"))
 | 
			
		||||
    |> base_email(dgettext("emails", "Update your Cannery email"))
 | 
			
		||||
    |> render_body("update_email.html", %{user: user, url: url})
 | 
			
		||||
    |> text_body(EmailView.render("update_email.txt", %{user: user, url: url}))
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,9 @@ defmodule Cannery.Release do
 | 
			
		||||
 | 
			
		||||
  def rollback(repo, version) do
 | 
			
		||||
    load_app()
 | 
			
		||||
    {:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
 | 
			
		||||
 | 
			
		||||
    {:ok, _fun_return, _apps} =
 | 
			
		||||
      Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp load_app do
 | 
			
		||||
@@ -20,7 +22,8 @@ defmodule Cannery.Release do
 | 
			
		||||
    load_app()
 | 
			
		||||
 | 
			
		||||
    for repo <- Application.fetch_env!(@app, :ecto_repos) do
 | 
			
		||||
      {:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
 | 
			
		||||
      {:ok, _fun_return, _apps} =
 | 
			
		||||
        Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
defmodule Cannery.Repo.Migrator do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Genserver to automatically run migrations in prod env
 | 
			
		||||
  Genserver to automatically perform all migration on app start
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  use GenServer
 | 
			
		||||
 
 | 
			
		||||
@@ -93,7 +93,7 @@ defmodule CanneryWeb.Components.Topbar do
 | 
			
		||||
            <% end %>
 | 
			
		||||
            <li class="mx-2 my-1">
 | 
			
		||||
              <.link
 | 
			
		||||
                navigate={Routes.user_settings_path(Endpoint, :edit)}
 | 
			
		||||
                href={Routes.user_settings_path(Endpoint, :edit)}
 | 
			
		||||
                class="text-primary-600 text-white hover:underline truncate"
 | 
			
		||||
              >
 | 
			
		||||
                <%= @current_user.email %>
 | 
			
		||||
@@ -108,29 +108,32 @@ defmodule CanneryWeb.Components.Topbar do
 | 
			
		||||
                <i class="fas fa-sign-out-alt"></i>
 | 
			
		||||
              </.link>
 | 
			
		||||
            </li>
 | 
			
		||||
            <%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
 | 
			
		||||
              <li class="mx-2 my-1">
 | 
			
		||||
                <.link
 | 
			
		||||
                  navigate={Routes.live_dashboard_path(Endpoint, :home)}
 | 
			
		||||
                  class="text-primary-600 text-white hover:underline"
 | 
			
		||||
                >
 | 
			
		||||
                  <i class="fas fa-gauge"></i>
 | 
			
		||||
                </.link>
 | 
			
		||||
              </li>
 | 
			
		||||
            <% end %>
 | 
			
		||||
            <li
 | 
			
		||||
              :if={
 | 
			
		||||
                @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2)
 | 
			
		||||
              }
 | 
			
		||||
              class="mx-2 my-1"
 | 
			
		||||
            >
 | 
			
		||||
              <.link
 | 
			
		||||
                navigate={Routes.live_dashboard_path(Endpoint, :home)}
 | 
			
		||||
                class="text-white text-white hover:underline"
 | 
			
		||||
              >
 | 
			
		||||
                <i class="fas fa-gauge"></i>
 | 
			
		||||
              </.link>
 | 
			
		||||
            </li>
 | 
			
		||||
          <% else %>
 | 
			
		||||
            <li :if={Accounts.allow_registration?()} class="mx-2 my-1">
 | 
			
		||||
              <.link
 | 
			
		||||
                navigate={Routes.user_registration_path(Endpoint, :new)}
 | 
			
		||||
                class="text-primary-600 text-white hover:underline truncate"
 | 
			
		||||
                href={Routes.user_registration_path(Endpoint, :new)}
 | 
			
		||||
                class="text-white hover:underline truncate"
 | 
			
		||||
              >
 | 
			
		||||
                <%= dgettext("actions", "Register") %>
 | 
			
		||||
              </.link>
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="mx-2 my-1">
 | 
			
		||||
              <.link
 | 
			
		||||
                navigate={Routes.user_session_path(Endpoint, :new)}
 | 
			
		||||
                class="text-primary-600 text-white hover:underline truncate"
 | 
			
		||||
                href={Routes.user_session_path(Endpoint, :new)}
 | 
			
		||||
                class="text-white hover:underline truncate"
 | 
			
		||||
              >
 | 
			
		||||
                <%= dgettext("actions", "Log in") %>
 | 
			
		||||
              </.link>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,8 @@
 | 
			
		||||
defmodule CanneryWeb.HomeController do
 | 
			
		||||
  @moduledoc """
 | 
			
		||||
  Controller for home page
 | 
			
		||||
  """
 | 
			
		||||
 | 
			
		||||
  use CanneryWeb, :controller
 | 
			
		||||
 | 
			
		||||
  def index(conn, _params) do
 | 
			
		||||
 
 | 
			
		||||
@@ -3,23 +3,21 @@
 | 
			
		||||
    <%= dgettext("emails", "Hi %{email},", email: @user.email) %>
 | 
			
		||||
  </span>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <span style="margin-bottom: 1em; font-size: 1.25em;">
 | 
			
		||||
    <%= dgettext("emails", "Welcome to %{name}!", name: "Cannery") %>
 | 
			
		||||
    <%= dgettext("emails", "Welcome to Cannery") %>
 | 
			
		||||
  </span>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails", "You can confirm your account by visiting the URL below:") %>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href="<%= @url %>"><%= @url %></a>
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails",
 | 
			
		||||
    "If you didn't create an account at %{name}, please ignore this.",
 | 
			
		||||
    name: "Cannery") %>
 | 
			
		||||
  <%= dgettext("emails", "If you didn't create an account at Cannery, please ignore this.") %>
 | 
			
		||||
</div>
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
 | 
			
		||||
<%= dgettext("emails", "Hi %{email},", email: @user.email) %>
 | 
			
		||||
 | 
			
		||||
<%= dgettext("emails", "Welcome to %{name}%!", name: "Cannery") %>
 | 
			
		||||
<%= dgettext("emails", "Welcome to Cannery") %>
 | 
			
		||||
 | 
			
		||||
<%= dgettext("emails", "You can confirm your account by visiting the URL below:") %>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,17 +3,15 @@
 | 
			
		||||
    <%= dgettext("emails", "Hi %{email},", email: @user.email) %>
 | 
			
		||||
  </span>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails", "You can reset your password by visiting the URL below:") %>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href="<%= @url %>"><%= @url %></a>
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails",
 | 
			
		||||
    "If you didn't request this change from %{name}, please ignore this.",
 | 
			
		||||
    name: "Cannery") %>
 | 
			
		||||
  <%= dgettext("emails", "If you didn't request this change from Cannery, please ignore this.") %>
 | 
			
		||||
</div>
 | 
			
		||||
@@ -3,17 +3,18 @@
 | 
			
		||||
    <%= dgettext("emails", "Hi %{email},", email: @user.email) %>
 | 
			
		||||
  </span>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails", "You can change your email by visiting the URL below:") %>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href="<%= @url %>"><%= @url %></a>
 | 
			
		||||
  <a style="margin: 1em; color: rgb(31, 31, 31);" href={@url}><%= @url %></a>
 | 
			
		||||
 | 
			
		||||
  <br/>
 | 
			
		||||
  <br />
 | 
			
		||||
 | 
			
		||||
  <%= dgettext("emails",
 | 
			
		||||
    "If you didn't request this change from %{name}, please ignore this.",
 | 
			
		||||
    name: "Cannery") %>
 | 
			
		||||
  <%= dgettext(
 | 
			
		||||
    "emails",
 | 
			
		||||
    "If you didn't request this change from Cannery, please ignore this."
 | 
			
		||||
  ) %>
 | 
			
		||||
</div>
 | 
			
		||||
@@ -13,7 +13,7 @@
 | 
			
		||||
  </head>
 | 
			
		||||
  <body class="pb-8 m-0 p-0 w-full h-full">
 | 
			
		||||
    <header>
 | 
			
		||||
      <.topbar current_user={assigns[:current_user]}></.topbar>
 | 
			
		||||
      <.topbar current_user={assigns[:current_user]} />
 | 
			
		||||
    </header>
 | 
			
		||||
 | 
			
		||||
    <div class="pb-8 w-full flex flex-col justify-center items-center text-center">
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<main role="main" class="min-h-full min-w-full">
 | 
			
		||||
  <header>
 | 
			
		||||
    <.topbar current_user={assigns[:current_user]}></.topbar>
 | 
			
		||||
    <.topbar current_user={assigns[:current_user]} />
 | 
			
		||||
 | 
			
		||||
    <div class="mx-8 my-2 flex flex-col space-y-4 text-center">
 | 
			
		||||
      <p :if={get_flash(@conn, :info)} class="alert alert-info" role="alert">
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,7 @@
 | 
			
		||||
    <a style="color: rgb(31, 31, 31);" href={Routes.live_url(Endpoint, HomeLive)}>
 | 
			
		||||
      <%= dgettext(
 | 
			
		||||
        "emails",
 | 
			
		||||
        "This email was sent from %{name}, the self-hosted firearm tracker website.",
 | 
			
		||||
        name: "Cannery"
 | 
			
		||||
        "This email was sent from Cannery, the self-hosted firearm tracker website."
 | 
			
		||||
      ) %>
 | 
			
		||||
    </a>
 | 
			
		||||
  </body>
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,5 @@
 | 
			
		||||
=====================
 | 
			
		||||
 | 
			
		||||
<%= dgettext("emails",
 | 
			
		||||
  "This email was sent from %{name} at %{url}, the self-hosted firearm tracker website.",
 | 
			
		||||
  name: "Cannery",
 | 
			
		||||
  "This email was sent from Cannery at %{url}, the self-hosted firearm tracker website.",
 | 
			
		||||
  url: Routes.live_url(Endpoint, HomeLive)) %>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<main class="pb-8 min-w-full">
 | 
			
		||||
  <header>
 | 
			
		||||
    <.topbar current_user={assigns[:current_user]}></.topbar>
 | 
			
		||||
    <.topbar current_user={assigns[:current_user]} />
 | 
			
		||||
 | 
			
		||||
    <div class="mx-8 my-2 flex flex-col space-y-4 text-center">
 | 
			
		||||
      <p
 | 
			
		||||
 
 | 
			
		||||
@@ -9,11 +9,9 @@
 | 
			
		||||
    action={Routes.user_reset_password_path(@conn, :update, @token)}
 | 
			
		||||
    class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
 | 
			
		||||
  >
 | 
			
		||||
    <div :if={@changeset.action && not @changeset.valid?()} class="alert alert-danger col-span-3">
 | 
			
		||||
      <p>
 | 
			
		||||
        <%= dgettext("errors", "Oops, something went wrong! Please check the errors below.") %>
 | 
			
		||||
      </p>
 | 
			
		||||
    </div>
 | 
			
		||||
    <p :if={@changeset.action && not @changeset.valid?()} class="alert alert-danger col-span-3">
 | 
			
		||||
      <%= dgettext("errors", "Oops, something went wrong! Please check the errors below.") %>
 | 
			
		||||
    </p>
 | 
			
		||||
 | 
			
		||||
    <%= label(f, :password, gettext("New password"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
    <%= password_input(f, :password, required: true, class: "input input-primary col-span-2") %>
 | 
			
		||||
 
 | 
			
		||||
@@ -10,11 +10,9 @@
 | 
			
		||||
    as="user"
 | 
			
		||||
    class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
 | 
			
		||||
  >
 | 
			
		||||
    <div :if={@error_message} class="alert alert-danger col-span-3">
 | 
			
		||||
      <p>
 | 
			
		||||
        <%= @error_message %>
 | 
			
		||||
      </p>
 | 
			
		||||
    </div>
 | 
			
		||||
    <p :if={@error_message} class="alert alert-danger col-span-3">
 | 
			
		||||
      <%= @error_message %>
 | 
			
		||||
    </p>
 | 
			
		||||
 | 
			
		||||
    <%= label(f, :email, gettext("Email"), class: "title text-lg text-primary-600") %>
 | 
			
		||||
    <%= email_input(f, :email, required: true, class: "input input-primary col-span-2") %>
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ defmodule CanneryWeb.ErrorView do
 | 
			
		||||
      case error_path do
 | 
			
		||||
        "404.html" -> dgettext("errors", "Not found")
 | 
			
		||||
        "401.html" -> dgettext("errors", "Unauthorized")
 | 
			
		||||
        _other_template -> dgettext("errors", "Internal Server Error")
 | 
			
		||||
        _other_path -> dgettext("errors", "Internal Server Error")
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    render("error.html", %{error_string: error_string})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user