Merge branch 'exclude-reblogs-from-admin-api-by-default' into 'develop'
[akkoma] / lib / pleroma / plugs / legacy_authentication_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.LegacyAuthenticationPlug do
6 import Plug.Conn
7 alias Pleroma.User
8
9 def init(options) do
10 options
11 end
12
13 def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
14
15 def call(
16 %{
17 assigns: %{
18 auth_user: %{password_hash: "$6$" <> _ = password_hash} = auth_user,
19 auth_credentials: %{password: password}
20 }
21 } = conn,
22 _
23 ) do
24 with ^password_hash <- :crypt.crypt(password, password_hash),
25 {:ok, user} <-
26 User.reset_password(auth_user, %{password: password, password_confirmation: password}) do
27 conn
28 |> assign(:auth_user, user)
29 |> assign(:user, user)
30 else
31 _ ->
32 conn
33 end
34 end
35
36 def call(conn, _) do
37 conn
38 end
39 end