Commit e7cd6e97 authored by lain's avatar lain
Browse files

Fix setting of keys.

parent fc3bcf33
......@@ -15,7 +15,7 @@ defmodule Pleroma.User.Info do
field(:no_rich_text, :boolean, default: false)
field(:ap_enabled, :boolean, default: false)
field(:is_moderator, :boolean, default: false)
field(:keys, :map, default: %{})
field(:keys, :string, default: nil)
end
def set_activation_status(info, deactivated) do
......@@ -61,4 +61,12 @@ def add_to_block(info, blocked) do
def remove_from_block(info, blocked) do
set_blocks(info, List.delete(info.blocks, blocked))
end
def set_keys(info, keys) do
params = %{keys: keys}
info
|> cast(params, [:keys])
|> validate_required([:keys])
end
end
......@@ -113,16 +113,20 @@ def represent_user(user, "XML") do
# This seems a better fit in Salmon
def ensure_keys_present(user) do
info = user.info || %{}
info = user.info
if info["keys"] do
if info.keys do
{:ok, user}
else
{:ok, pem} = Salmon.generate_rsa_pem()
info = Map.put(info, "keys", pem)
Ecto.Changeset.change(user, info: info)
|> User.update_and_set_cache()
info_cng = info
|> Pleroma.User.Info.set_keys(pem)
cng = Ecto.Changeset.change(user)
|> Ecto.Changeset.put_embed(:info, info_cng)
User.update_and_set_cache(cng)
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment