pass invite token in properly
This commit is contained in:
parent
dce04e4d7f
commit
3adb8c9aae
@ -106,8 +106,7 @@ defmodule Cannery.Invites do
|
|||||||
|> Base.url_encode64()
|
|> Base.url_encode64()
|
||||||
|> binary_part(0, @invite_token_length)
|
|> binary_part(0, @invite_token_length)
|
||||||
|
|
||||||
attrs = attrs |> Map.put("token", token)
|
%Invite{} |> Invite.create_changeset(user, token, attrs) |> Repo.insert()
|
||||||
%Invite{} |> Invite.create_changeset(user, attrs) |> Repo.insert()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -38,11 +38,12 @@ defmodule Cannery.Invites.Invite do
|
|||||||
@type id :: UUID.t()
|
@type id :: UUID.t()
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec create_changeset(new_invite(), User.t(), attrs :: map()) :: Changeset.t(new_invite())
|
@spec create_changeset(new_invite(), User.t(), token :: binary(), attrs :: map()) ::
|
||||||
def create_changeset(invite, %User{id: user_id}, attrs) do
|
Changeset.t(new_invite())
|
||||||
|
def create_changeset(invite, %User{id: user_id}, token, attrs) do
|
||||||
invite
|
invite
|
||||||
|> change(user_id: user_id)
|
|> change(token: token, user_id: user_id)
|
||||||
|> cast(attrs, [:name, :token, :uses_left, :disabled_at])
|
|> cast(attrs, [:name, :uses_left, :disabled_at])
|
||||||
|> validate_required([:name, :token, :user_id])
|
|> validate_required([:name, :token, :user_id])
|
||||||
|> validate_number(:uses_left, greater_than_or_equal_to: 0)
|
|> validate_number(:uses_left, greater_than_or_equal_to: 0)
|
||||||
end
|
end
|
||||||
|
@ -38,7 +38,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
|
|||||||
|
|
||||||
changeset =
|
changeset =
|
||||||
case action do
|
case action do
|
||||||
:new -> invite |> Invite.create_changeset(user, invite_params)
|
:new -> invite |> Invite.create_changeset(user, "example_token", invite_params)
|
||||||
:edit -> invite |> Invite.update_changeset(invite_params)
|
:edit -> invite |> Invite.update_changeset(invite_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user