api token whitespace fix and magic link login fix
This commit is contained in:
parent
0b72b47ae6
commit
5e7576bc3f
2 changed files with 39 additions and 7 deletions
|
|
@ -1042,11 +1042,29 @@ defmodule ToweropsWeb.UserSettingsLive do
|
|||
</p>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<div class="rounded-lg bg-gray-50 p-3 dark:bg-gray-800/50">
|
||||
<code class="text-sm text-gray-900 dark:text-white break-all">
|
||||
{@created_token}
|
||||
</code>
|
||||
<div class="relative">
|
||||
<input
|
||||
type="text"
|
||||
readonly
|
||||
value={String.trim(@created_token)}
|
||||
class="w-full font-mono text-sm bg-gray-50 dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded px-3 py-2 pr-28 text-gray-900 dark:text-white select-all"
|
||||
id="api-token-input"
|
||||
onclick="this.select()"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
phx-hook="CopyToClipboard"
|
||||
data-target="#api-token-input"
|
||||
id="copy-api-token"
|
||||
class="absolute right-2 top-1/2 -translate-y-1/2 px-3 py-1.5 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 rounded shadow-sm transition-colors flex items-center gap-1.5"
|
||||
>
|
||||
<.icon name="hero-clipboard" class="h-3.5 w-3.5" />
|
||||
<span>Copy</span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="mt-1.5 text-xs text-gray-500 dark:text-gray-400">
|
||||
Click the token to select all, or use the Copy button
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -46,9 +46,12 @@ defmodule ToweropsWeb.UserAuth do
|
|||
def log_in_user(conn, user, params \\ %{}) do
|
||||
user_return_to = get_session(conn, :user_return_to)
|
||||
|
||||
conn
|
||||
|> create_or_extend_session(user, params)
|
||||
|> redirect(to: user_return_to || signed_in_path(user))
|
||||
conn =
|
||||
conn
|
||||
|> create_or_extend_session(user, params)
|
||||
|> maybe_set_default_organization(user)
|
||||
|
||||
redirect(conn, to: user_return_to || signed_in_path(user))
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -203,6 +206,17 @@ defmodule ToweropsWeb.UserAuth do
|
|||
|
||||
defp maybe_write_remember_me_cookie(conn, _token, _params, _), do: conn
|
||||
|
||||
defp maybe_set_default_organization(conn, user) do
|
||||
# Set the first organization in the session to support routes that require organization context
|
||||
case Towerops.Organizations.list_user_organizations(user.id) do
|
||||
[first_org | _] ->
|
||||
put_session(conn, :current_organization_id, first_org.id)
|
||||
|
||||
[] ->
|
||||
conn
|
||||
end
|
||||
end
|
||||
|
||||
defp write_remember_me_cookie(conn, token) do
|
||||
conn
|
||||
|> put_session(:user_remember_me, true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue