2019-02-26 12:27:01 +00:00
|
|
|
defmodule Pleroma.Web.Auth.PleromaDatabaseAuthenticator do
|
2019-02-21 15:55:19 +00:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Comeonin.Pbkdf2
|
|
|
|
|
2019-02-26 12:27:01 +00:00
|
|
|
@behaviour Pleroma.Web.Auth.DatabaseAuthenticator
|
2019-02-21 15:55:19 +00:00
|
|
|
|
|
|
|
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
|