Database authenticator behaviour / Pleroma implementation refactoring.
[akkoma] / lib / pleroma / web / auth / pleroma_database_authenticator.ex
1 defmodule Pleroma.Web.Auth.PleromaDatabaseAuthenticator do
2 alias Pleroma.User
3 alias Comeonin.Pbkdf2
4
5 @behaviour Pleroma.Web.Auth.DatabaseAuthenticator
6
7 def get_user(%Plug.Conn{} = conn) do
8 %{"authorization" => %{"name" => name, "password" => password}} = conn.params
9
10 with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
11 {_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
12 {:ok, user}
13 else
14 error ->
15 {:error, error}
16 end
17 end
18
19 def handle_error(%Plug.Conn{} = _conn, error) do
20 error
21 end
22 end