mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-28 10:18:51 +00:00
Allow user to change default email
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user