Skip to content

Commit

Permalink
Fix set user password
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed May 30, 2024
1 parent c6895ed commit feac03f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/actions/users/htmx/password.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class User::Htmx::Password < HtmxAction
put "/users/:id/password" do
user = UserQuery.find(params.get(:id))

p! params.get(:password)
p! params.get(:confirm_password)

# SaveUser.update!(user, is_editable: !user.is_editable)
SaveUser.update!(user, password: params.get(:password))

plain_text "ok"
end
Expand Down
21 changes: 11 additions & 10 deletions src/pages/me/show_page.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Me::ShowPage < MainLayout
"确认",
href: "#!",
class: "modal-close waves-effect btn-flat",
"hx-put": "aaaaaaaaaaaa",
"hx-put": "will_be_replace_when_clicking",
"hx-swap": "none",
"hx-include": "[name='_csrf']",
"hx-include": "[name='_csrf'],[name='password']",
id: "password"
)
end
Expand Down Expand Up @@ -91,14 +91,14 @@ class Me::ShowPage < MainLayout
span class: "switch" do
label for: "#{user_id}_is_editable" do
args = {
type: "checkbox",
name: "is_editable",
value: true,
id: "#{user_id}_is_editable",
"hx-put": User::Htmx::Editable.with(user.id).path,
"hx-swap": "none",
type: "checkbox",
name: "is_editable",
value: true,
id: "#{user_id}_is_editable",
"hx-put": User::Htmx::Editable.with(user.id).path,
"hx-swap": "none",
"hx-confirm": "确认?",
"hx-include": "[name='_csrf']"
"hx-include": "[name='_csrf']",
}

if user.is_editable
Expand All @@ -118,8 +118,9 @@ class Me::ShowPage < MainLayout
href: "#modal1",
class: "waves-effect waves-light btn modal-trigger",
script: "
on mouseenter put '修改 #{user.email} 的密码' into the <#modal1 h5/>
on click put '修改 #{user.email} 的密码' into the <#modal1 h5/>
then set @hx-put of <#modal1 a[hx-put]/> to '#{User::Htmx::Password.with(user_id).path}'
then js htmx.process(document.body) end
"
)
end
Expand Down

0 comments on commit feac03f

Please sign in to comment.