2019-02-26 22:26:54 +09:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-02-28 20:12:41 +09:00
|
|
|
defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
2019-02-22 00:55:19 +09:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Comeonin.Pbkdf2
|
|
|
|
|
2019-02-28 20:12:41 +09:00
|
|
|
@behaviour Pleroma.Web.Auth.Authenticator
|
2019-02-22 00:55:19 +09: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
|
2019-02-28 19:58:58 +09:00
|
|
|
|
|
|
|
def auth_template, do: nil
|
2019-02-22 00:55:19 +09:00
|
|
|
end
|