Merge branch 'hotfix/delete-activities' into 'develop'
[akkoma] / lib / pleroma / web / auth / pleroma_authenticator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Auth.PleromaAuthenticator do
6 alias Comeonin.Pbkdf2
7 alias Pleroma.User
8
9 @behaviour Pleroma.Web.Auth.Authenticator
10
11 def get_user(%Plug.Conn{} = conn) do
12 %{"authorization" => %{"name" => name, "password" => password}} = conn.params
13
14 with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
15 {_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do
16 {:ok, user}
17 else
18 error ->
19 {:error, error}
20 end
21 end
22
23 def handle_error(%Plug.Conn{} = _conn, error) do
24 error
25 end
26
27 def auth_template, do: nil
28 end