OAuthController#create_authorization user retrieval / creation, errors handling, template & layout selection.stable
parent
2813f28b6f
commit
1097ce6d9f
@ -0,0 +1,22 @@
|
|||||||
|
defmodule Pleroma.Web.Authenticator do
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Comeonin.Pbkdf2
|
||||||
|
|
||||||
|
@behaviour Pleroma.Web.AuthenticatorAdapter
|
||||||
|
|
||||||
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
|
%{"authorization" => %{"name" => name, "password" => password}} = conn.params
|
||||||
|
|
||||||
|
with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
|
||||||
|
{_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
|
||||||
|
{:ok, user}
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
{:error, error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_error(%Plug.Conn{} = _conn, error) do
|
||||||
|
error
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
defmodule Pleroma.Web.AuthenticatorAdapter do
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
|
@callback get_user(Plug.Conn.t()) :: {:ok, User.t()} | {:error, any()}
|
||||||
|
|
||||||
|
@callback handle_error(Plug.Conn.t(), any()) :: any()
|
||||||
|
end
|
Loading…
Reference in new issue