How do I insert a value, in an automatic column, when creating a user.
Straight into the changeset?
Ex:
I have a user registration, where the fields (username, email, password)
I need this username to generate automatically, from the email encryption, without the user having to fill it out.
def generate_string_encrypt(params) do
params |> :base64.encode
end
How can I put this function in my changeset?
Current changeset
schema "users" do
field :username, :string
field :email, :string
field :password, :string
timestamps()
end
def changeset(user, attrs) do
user
|> cast(attrs, [:username, :email, :password])
# |> generate_string_encrypt([:email]) ######## Would it be like this?
end
def generate_string_encrypt(params) do
params |> :base64.encode
end
How do I have the username filled in automatically, from that function?