mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-29 16:56:52 +00:00
9be6caf125
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk> Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/406
45 lines
1 KiB
Elixir
45 lines
1 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.Plugs.AuthenticationPlug do
|
|
@moduledoc "Password authentication plug."
|
|
|
|
alias Pleroma.Helpers.AuthHelper
|
|
alias Pleroma.User
|
|
alias Pleroma.Password
|
|
|
|
import Plug.Conn
|
|
|
|
require Logger
|
|
|
|
def init(options), do: options
|
|
|
|
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
|
|
|
|
def call(
|
|
%{
|
|
assigns: %{
|
|
auth_user: %{password_hash: password_hash} = auth_user,
|
|
auth_credentials: %{password: password}
|
|
}
|
|
} = conn,
|
|
_
|
|
) do
|
|
if Password.checkpw(password, password_hash) do
|
|
{:ok, auth_user} = Password.maybe_update_password(auth_user, password)
|
|
|
|
conn
|
|
|> assign(:user, auth_user)
|
|
|> AuthHelper.skip_oauth()
|
|
else
|
|
conn
|
|
end
|
|
end
|
|
|
|
def call(conn, _), do: conn
|
|
|
|
@spec checkpw(String.t(), String.t()) :: boolean
|
|
defdelegate checkpw(password, hash), to: Password
|
|
end
|