generate keys at registration time
This commit is contained in:
parent
935d397692
commit
0772d003e3
2 changed files with 9 additions and 1 deletions
|
@ -681,6 +681,7 @@ def register_changeset_ldap(struct, params = %{password: password})
|
|||
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|
||||
|> validate_format(:nickname, local_nickname_regex())
|
||||
|> put_ap_id()
|
||||
|> put_keys()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
end
|
||||
|
@ -740,6 +741,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
|
|||
|> validate_length(:registration_reason, max: reason_limit)
|
||||
|> maybe_validate_required_email(opts[:external])
|
||||
|> put_password_hash
|
||||
|> put_keys()
|
||||
|> put_ap_id()
|
||||
|> unique_constraint(:ap_id)
|
||||
|> put_following_and_follower_and_featured_address()
|
||||
|
@ -755,6 +757,11 @@ def maybe_validate_required_email(changeset, _) do
|
|||
end
|
||||
end
|
||||
|
||||
def put_keys(changeset) do
|
||||
{:ok, pem} = Keys.generate_rsa_pem()
|
||||
put_change(changeset, :keys, pem)
|
||||
end
|
||||
|
||||
def put_ap_id(changeset) do
|
||||
ap_id = ap_id(%User{nickname: get_field(changeset, :nickname)})
|
||||
put_change(changeset, :ap_id, ap_id)
|
||||
|
|
|
@ -620,13 +620,14 @@ test "it blocks blacklisted email domains" do
|
|||
assert changeset.valid?
|
||||
end
|
||||
|
||||
test "it sets the password_hash and ap_id" do
|
||||
test "it sets the password_hash, ap_id and PEM key" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
assert changeset.valid?
|
||||
|
||||
assert is_binary(changeset.changes[:password_hash])
|
||||
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
|
||||
assert is_binary(changeset.changes[:keys])
|
||||
|
||||
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue