forked from shibao/cannery
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()
|
||||
|> binary_part(0, @invite_token_length)
|
||||
|
||||
attrs = attrs |> Map.put("token", token)
|
||||
%Invite{} |> Invite.create_changeset(user, attrs) |> Repo.insert()
|
||||
%Invite{} |> Invite.create_changeset(user, token, attrs) |> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -38,11 +38,12 @@ defmodule Cannery.Invites.Invite do
|
||||
@type id :: UUID.t()
|
||||
|
||||
@doc false
|
||||
@spec create_changeset(new_invite(), User.t(), attrs :: map()) :: Changeset.t(new_invite())
|
||||
def create_changeset(invite, %User{id: user_id}, attrs) do
|
||||
@spec create_changeset(new_invite(), User.t(), token :: binary(), attrs :: map()) ::
|
||||
Changeset.t(new_invite())
|
||||
def create_changeset(invite, %User{id: user_id}, token, attrs) do
|
||||
invite
|
||||
|> change(user_id: user_id)
|
||||
|> cast(attrs, [:name, :token, :uses_left, :disabled_at])
|
||||
|> change(token: token, user_id: user_id)
|
||||
|> cast(attrs, [:name, :uses_left, :disabled_at])
|
||||
|> validate_required([:name, :token, :user_id])
|
||||
|> validate_number(:uses_left, greater_than_or_equal_to: 0)
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
|
||||
|
||||
changeset =
|
||||
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)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user