Change user.discoverable field to user.is_discoverable
[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
8 alias Pleroma.Plugs.OAuthScopesPlug
9 alias Pleroma.User
10
11 def init(options) do
12 options
13 end
14
15 def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
16
17 def call(
18 %{
19 assigns: %{
20 auth_user: %{password_hash: "$6$" <> _ = password_hash} = auth_user,
21 auth_credentials: %{password: password}
22 }
23 } = conn,
24 _
25 ) do
26 with ^password_hash <- :crypt.crypt(password, password_hash),
27 {:ok, user} <-
28 User.reset_password(auth_user, %{password: password, password_confirmation: password}) do
29 conn
30 |> assign(:auth_user, user)
31 |> assign(:user, user)
32 |> OAuthScopesPlug.skip_plug()
33 else
34 _ ->
35 conn
36 end
37 end
38
39 def call(conn, _) do
40 conn
41 end
42 end