talha-azeem
talha-azeem
AEAsh Elixir
Created by talha-azeem on 2/2/2023 in #support
How do we seed data of a specific resource?
Thank you
3 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
Basic User Settings Implemented using the Ash resources. Thank you to both of you 🫰🏻 @Zach Daniel @frankdugan3
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
Thank you guys 🫢🏻
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
name was the issue
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
current_password still doesn't show up in params
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
id of form?
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
I inspected the params in validate and they are
params => : %{
"email" => "[email protected]",
"password" => "",
"password_confirmation" => ""
}
params => : %{
"email" => "[email protected]",
"password" => "",
"password_confirmation" => ""
}
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
only for current_password at the moment
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
@impl true
def handle_event("validate_password", %{"change_password" => params}, socket) do
{:noreply,
assign(socket,
password_form:
AshPhoenix.Form.validate(socket.assigns.password_form, params,
errors: socket.assigns.password_form.submitted_once?
)
)}
end

@impl true
def handle_event("save_password", %{"change_password" => params}, socket) do
case AshPhoenix.Form.submit(socket.assigns.password_form, params: params) do
{:ok, _result} ->
{:noreply,
socket
|> put_flash(:info, "Password has been successfully changed.")
|> push_redirect(to: "/")}

{:error, password_form} ->
{:noreply, assign(socket, password_form: password_form)}
end
end
@impl true
def handle_event("validate_password", %{"change_password" => params}, socket) do
{:noreply,
assign(socket,
password_form:
AshPhoenix.Form.validate(socket.assigns.password_form, params,
errors: socket.assigns.password_form.submitted_once?
)
)}
end

@impl true
def handle_event("save_password", %{"change_password" => params}, socket) do
case AshPhoenix.Form.submit(socket.assigns.password_form, params: params) do
{:ok, _result} ->
{:noreply,
socket
|> put_flash(:info, "Password has been successfully changed.")
|> push_redirect(to: "/")}

{:error, password_form} ->
{:noreply, assign(socket, password_form: password_form)}
end
end
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
I tried debugging it but my current_password field is like it was never there.
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
in user.ex:
update :change_password do
accept []

argument :current_password, :string do
sensitive? true
allow_nil? false
end

argument :password, :string do
sensitive? true
allow_nil? false
end

argument :password_confirmation, :string do
sensitive? true
allow_nil? false
end

change set_context(%{strategy_name: :password})

validate confirm(:password, :password_confirmation)

validate {AshAuthentication.Strategy.Password.PasswordValidation,
strategy_name: :password, password_argument: :current_password} do
only_when_valid? true
before_action? true
end

change AshAuthentication.Strategy.Password.HashPasswordChange
end



policies do
policy action(:change_password) do
description "A logged in user can reset their password"
authorize_if expr(id == ^actor(:id))
end
end
update :change_password do
accept []

argument :current_password, :string do
sensitive? true
allow_nil? false
end

argument :password, :string do
sensitive? true
allow_nil? false
end

argument :password_confirmation, :string do
sensitive? true
allow_nil? false
end

change set_context(%{strategy_name: :password})

validate confirm(:password, :password_confirmation)

validate {AshAuthentication.Strategy.Password.PasswordValidation,
strategy_name: :password, password_argument: :current_password} do
only_when_valid? true
before_action? true
end

change AshAuthentication.Strategy.Password.HashPasswordChange
end



policies do
policy action(:change_password) do
description "A logged in user can reset their password"
authorize_if expr(id == ^actor(:id))
end
end
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
password_form =
AshPhoenix.Form.for_update(user, :change_password,
as: "change_password",
api: Accounts,
actor: user
)
password_form =
AshPhoenix.Form.for_update(user, :change_password,
as: "change_password",
api: Accounts,
actor: user
)
password form in mount
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
updating password through ash resources
<.header>Change Password</.header>

<.simple_form
:let={f}
id="password_form"
for={@password_form}
method="post"
phx-change="validate_password"
phx-submit="save_password"
>
<.input field={{f, :email}} type="hidden" />

<.input field={{f, :password}} type="password" label="New password" required />
<.input field={{f, :password_confirmation}} type="password" label="Confirm new password" />
<.input
field={{f, :current_password}}
name="current_password"
type="password"
label="Current password"
id="current_password_for_password"
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Password</.button>
</:actions>
</.simple_form>
<.header>Change Password</.header>

<.simple_form
:let={f}
id="password_form"
for={@password_form}
method="post"
phx-change="validate_password"
phx-submit="save_password"
>
<.input field={{f, :email}} type="hidden" />

<.input field={{f, :password}} type="password" label="New password" required />
<.input field={{f, :password_confirmation}} type="password" label="Confirm new password" />
<.input
field={{f, :current_password}}
name="current_password"
type="password"
label="Current password"
id="current_password_for_password"
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Password</.button>
</:actions>
</.simple_form>
frontend part
26 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
update :update_name do
accept [:name]
end
update :update_name do
accept [:name]
end
worked after updating it like this, Thank you πŸ™ŒπŸ»
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
I was about to try this πŸ˜… just saw this in docs πŸ˜…
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
In my user.ex:
policies do
policy action(:update_name) do
description "A logged in user can update their name"
authorize_if expr(id == ^actor(:id))
end
end

update :update_name do
argument :name, :ci_string, allow_nil?: false
end
policies do
policy action(:update_name) do
description "A logged in user can update their name"
authorize_if expr(id == ^actor(:id))
end
end

update :update_name do
argument :name, :ci_string, allow_nil?: false
end
these are defined
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
@impl true
def handle_event("save_name", params, socket) do
case AshPhoenix.Form.submit(socket.assigns.name_form, params: params) do
{:ok, _result} ->
{:noreply,
socket
|> put_flash(:info, "Name updated")
|> push_redirect(to: "/users/settings")}

{:error, name_form} ->
{:noreply, assign(socket, name_form: name_form)}
end
end

def handle_event("validate_name", params, socket) do
{:noreply,
assign(socket,
name_form:
AshPhoenix.Form.validate(socket.assigns.name_form, params,
errors: socket.assigns.name_form.submitted_once?
)
)}
end
@impl true
def handle_event("save_name", params, socket) do
case AshPhoenix.Form.submit(socket.assigns.name_form, params: params) do
{:ok, _result} ->
{:noreply,
socket
|> put_flash(:info, "Name updated")
|> push_redirect(to: "/users/settings")}

{:error, name_form} ->
{:noreply, assign(socket, name_form: name_form)}
end
end

def handle_event("validate_name", params, socket) do
{:noreply,
assign(socket,
name_form:
AshPhoenix.Form.validate(socket.assigns.name_form, params,
errors: socket.assigns.name_form.submitted_once?
)
)}
end
validate and save name handle events.
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
<.header>Change Name</.header>

<.simple_form
:let={f}
id="name_form"
for={@name_form}
method="post"
phx-change="validate_name"
phx-submit="save_name"
>
<.input
field={{f, :name}}
name="name"
type="text"
label="Name"
id="name_for_user"
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Name</.button>
</:actions>
</.simple_form>
<.header>Change Name</.header>

<.simple_form
:let={f}
id="name_form"
for={@name_form}
method="post"
phx-change="validate_name"
phx-submit="save_name"
>
<.input
field={{f, :name}}
name="name"
type="text"
label="Name"
id="name_for_user"
required
/>
<:actions>
<.button phx-disable-with="Changing...">Change Name</.button>
</:actions>
</.simple_form>
form on the frontend
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Update Name through Ash resources.
name_form_params = %{"name" => user.name}
user = socket.assigns.current_user
name_form_params = %{"name" => user.name}
user = socket.assigns.current_user
name_form =
AshPhoenix.Form.for_update(user, :update_name,
as: "update_name",
api: Accounts,
actor: user
)
|> AshPhoenix.Form.validate(name_form_params, errors: false)
name_form =
AshPhoenix.Form.for_update(user, :update_name,
as: "update_name",
api: Accounts,
actor: user
)
|> AshPhoenix.Form.validate(name_form_params, errors: false)
name form that i am assigning in mount of liveview
15 replies
AEAsh Elixir
Created by talha-azeem on 1/30/2023 in #support
Ash HQ User Settings Page
Thank you for the clarification @frankdugan3 πŸ™ŒπŸ»
14 replies