Commit be54e408 authored by Alexander Strizhakov's avatar Alexander Strizhakov

twitter api registration

fix for twitter api tests
parent 0484f3a8
......@@ -163,36 +163,49 @@ def register_user(params) do
{:error, %{error: Jason.encode!(%{captcha: [error]})}}
else
registrations_open = Pleroma.Config.get([:instance, :registrations_open])
registration_process(registrations_open, params, token_string)
end
end
# no need to query DB if registration is open
token =
unless registrations_open || is_nil(token_string) do
Repo.get_by(UserInviteToken, %{token: token_string})
end
defp registration_process(_registration_open = true, params, _token_string) do
create_user(params)
end
cond do
registrations_open || (!is_nil(token) && !token.used) ->
changeset = User.register_changeset(%User{}, params)
defp registration_process(registration_open, params, token_string)
when registration_open == false or is_nil(registration_open) do
token =
unless is_nil(token_string) do
Repo.get_by(UserInviteToken, %{token: token_string})
end
with {:ok, user} <- User.register(changeset) do
!registrations_open && UserInviteToken.mark_as_used(token.token)
valid_token? = token && UserInviteToken.valid_token?(token)
{:ok, user}
else
{:error, changeset} ->
errors =
Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|> Jason.encode!()
case token do
nil ->
{:error, "Invalid token"}
{:error, %{error: errors}}
end
token when valid_token? ->
UserInviteToken.update_usage(token)
create_user(params)
!registrations_open && is_nil(token) ->
{:error, "Invalid token"}
_ ->
{:error, "Expired token"}
end
end
!registrations_open && token.used ->
{:error, "Expired token"}
end
defp create_user(params) do
changeset = User.register_changeset(%User{}, params)
case User.register(changeset) do
{:ok, user} ->
{:ok, user}
{:error, changeset} ->
errors =
Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|> Jason.encode!()
{:error, %{error: errors}}
end
end
......
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"toot": "http://joinmastodon.org/ns#",
"featured": {
"@id": "toot:featured",
"@type": "@id"
},
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"
},
"movedTo": {
"@id": "as:movedTo",
"@type": "@id"
},
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"Hashtag": "as:Hashtag",
"Emoji": "toot:Emoji",
"IdentityProof": "toot:IdentityProof",
"focalPoint": {
"@container": "@list",
"@id": "toot:focalPoint"
}
}
],
"id": "https://mastodon.social/users/lambadalambda",
"type": "Person",
"following": "https://mastodon.social/users/lambadalambda/following",
"followers": "https://mastodon.social/users/lambadalambda/followers",
"inbox": "https://mastodon.social/users/lambadalambda/inbox",
"outbox": "https://mastodon.social/users/lambadalambda/outbox",
"featured": "https://mastodon.social/users/lambadalambda/collections/featured",
"preferredUsername": "lambadalambda",
"name": "Critical Value",
"summary": "\u003cp\u003e\u003c/p\u003e",
"url": "https://mastodon.social/@lambadalambda",
"manuallyApprovesFollowers": false,
"publicKey": {
"id": "https://mastodon.social/users/lambadalambda#main-key",
"owner": "https://mastodon.social/users/lambadalambda",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw0P/Tq4gb4G/QVuMGbJo\nC/AfMNcv+m7NfrlOwkVzcU47jgESuYI4UtJayissCdBycHUnfVUd9qol+eznSODz\nCJhfJloqEIC+aSnuEPGA0POtWad6DU0E6/Ho5zQn5WAWUwbRQqowbrsm/GHo2+3v\neR5jGenwA6sYhINg/c3QQbksyV0uJ20Umyx88w8+TJuv53twOfmyDWuYNoQ3y5cc\nHKOZcLHxYOhvwg3PFaGfFHMFiNmF40dTXt9K96r7sbzc44iLD+VphbMPJEjkMuf8\nPGEFOBzy8pm3wJZw2v32RNW2VESwMYyqDzwHXGSq1a73cS7hEnc79gXlELsK04L9\nQQIDAQAB\n-----END PUBLIC KEY-----\n"
},
"tag": [],
"attachment": [],
"endpoints": {
"sharedInbox": "https://mastodon.social/inbox"
},
"icon": {
"type": "Image",
"mediaType": "image/gif",
"url": "https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif"
},
"image": {
"type": "Image",
"mediaType": "image/gif",
"url": "https://files.mastodon.social/accounts/headers/000/000/264/original/28b26104f83747d2.gif"
}
}
......@@ -716,6 +716,10 @@ def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
end
def get("https://mastodon.social/users/lambadalambda", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
end
def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
end
......
This diff is collapsed.
Markdown is supported
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