Allow user to change default email

This commit is contained in:
Jamil Bou Kheir
2021-03-10 11:29:08 -08:00
parent 79a27767d6
commit 74f5d04565
3 changed files with 10 additions and 6 deletions

View File

@@ -40,6 +40,10 @@ defmodule FgHttp.Users do
User.changeset(user, %{})
end
def single_user? do
Repo.one(from u in User, select: count()) == 1
end
# For now, assume first User is admin
def admin do
User |> first |> Repo.one()

View File

@@ -13,7 +13,7 @@
<div class="field">
<%= label(:session, :email, class: "label") %>
<div class="control">
<%= text_input(f, :email, email_field_opts()) %>
<%= text_input(f, :email, email_field_opts(class: "input")) %>
</div>
<p class="help is-danger">
<%= error_tag f, :email %>

View File

@@ -2,12 +2,12 @@ defmodule FgHttpWeb.SessionView do
use FgHttpWeb, :view
alias FgHttp.Users
# Don't allow user to enter email if signups are disabled.
def email_field_opts do
if signups_disabled?() do
[class: "input", readonly: true, value: Users.admin_email()]
# Guess email if signups are disabled and only one user exists
def email_field_opts(opts \\ []) when is_list(opts) do
if Users.single_user?() and signups_disabled?() do
opts ++ [value: Users.admin_email()]
else
[class: "input"]
opts
end
end