X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fregistration.ex;h=9163040b4d563f2fcb37466e4b87e4355fc355df;hb=b720ad2264cde6e24e63f6cf7f4662731448823b;hp=773e25fa604b05effcefa33b4f8bcac58b86d1c8;hpb=40e9a04c31a9965dee92cb8f07ed6db28f8ccd75;p=akkoma
diff --git a/lib/pleroma/registration.ex b/lib/pleroma/registration.ex
index 773e25fa6..9163040b4 100644
--- a/lib/pleroma/registration.ex
+++ b/lib/pleroma/registration.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Registration do
@@ -11,8 +11,10 @@ defmodule Pleroma.Registration do
alias Pleroma.Repo
alias Pleroma.User
+ @primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
+
schema "registrations" do
- belongs_to(:user, User, type: Pleroma.FlakeId)
+ belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
field(:provider, :string)
field(:uid, :string)
field(:info, :map, default: %{})
@@ -20,6 +22,18 @@ defmodule Pleroma.Registration do
timestamps()
end
+ def nickname(registration, default \\ nil),
+ do: Map.get(registration.info, "nickname", default)
+
+ def email(registration, default \\ nil),
+ do: Map.get(registration.info, "email", default)
+
+ def name(registration, default \\ nil),
+ do: Map.get(registration.info, "name", default)
+
+ def description(registration, default \\ nil),
+ do: Map.get(registration.info, "description", default)
+
def changeset(registration, params \\ %{}) do
registration
|> cast(params, [:user_id, :provider, :uid, :info])
@@ -28,6 +42,12 @@ defmodule Pleroma.Registration do
|> unique_constraint(:uid, name: :registrations_provider_uid_index)
end
+ def bind_to_user(registration, user) do
+ registration
+ |> changeset(%{user_id: (user && user.id) || nil})
+ |> Repo.update()
+ end
+
def get_by_provider_uid(provider, uid) do
Repo.get_by(Registration,
provider: to_string(provider),