Fix setting of keys.
This commit is contained in:
parent
fc3bcf335e
commit
e7cd6e9739
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue