Skip to content

Commit 841501c

Browse files
committed
Allow changing hash type in admin
1 parent bda2262 commit 841501c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/password_example/user.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ defmodule PasswordExample.User do
2121
|> Repo.insert()
2222
end
2323

24+
def delete_all do
25+
users_changed()
26+
Repo.delete_all(User)
27+
end
28+
2429
def get_all do
2530
Repo.all(User)
2631
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
defmodule PasswordExampleWeb.AdminLive do
22
use PasswordExampleWeb, :live_view
3+
# use Phoenix.HTML
34
alias PasswordExampleWeb.UsersTableComponent
5+
alias PasswordExample.{HashingAlgorithmChoice, User}
6+
7+
@impl true
8+
def mount(_, _, socket) do
9+
{:ok, assign(socket, hash_type: HashingAlgorithmChoice.get())}
10+
end
11+
12+
@impl true
13+
def handle_event("change_hash_type", %{"value" => hash_type}, socket) do
14+
hash_type = String.to_atom(hash_type)
15+
HashingAlgorithmChoice.set(hash_type)
16+
User.delete_all()
17+
{:noreply, assign(socket, hash_type: hash_type)}
18+
end
419
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<h1>Admin</h1>
22

3+
<%= select :hash_type, :hash_type, HashingAlgorithmChoice.choices, value: @hash_type, phx_blur: "change_hash_type" %>
4+
<button type="button">Delete Users and Change Hash Type</button>
5+
36
<%= live_component @socket, UsersTableComponent, id: :users_table %>

0 commit comments

Comments
 (0)