2017-09-07 06:58:10 +00:00
|
|
|
defmodule Pleroma.Web.OAuth.App do
|
2017-09-06 17:06:25 +00:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.{Changeset}
|
|
|
|
|
|
|
|
schema "apps" do
|
2018-03-30 13:01:53 +00:00
|
|
|
field(:client_name, :string)
|
|
|
|
field(:redirect_uris, :string)
|
|
|
|
field(:scopes, :string)
|
|
|
|
field(:website, :string)
|
|
|
|
field(:client_id, :string)
|
|
|
|
field(:client_secret, :string)
|
2017-09-06 17:06:25 +00:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
def register_changeset(struct, params \\ %{}) do
|
2018-03-30 13:01:53 +00:00
|
|
|
changeset =
|
|
|
|
struct
|
|
|
|
|> cast(params, [:client_name, :redirect_uris, :scopes, :website])
|
|
|
|
|> validate_required([:client_name, :redirect_uris, :scopes])
|
2017-09-06 17:06:25 +00:00
|
|
|
|
|
|
|
if changeset.valid? do
|
|
|
|
changeset
|
2018-03-30 13:01:53 +00:00
|
|
|
|> put_change(:client_id, :crypto.strong_rand_bytes(32) |> Base.url_encode64())
|
|
|
|
|> put_change(:client_secret, :crypto.strong_rand_bytes(32) |> Base.url_encode64())
|
2017-09-06 17:06:25 +00:00
|
|
|
else
|
|
|
|
changeset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|