projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only fetch if it's http.
[akkoma]
/
lib
/
pleroma
/
plugs
/
authentication_plug.ex
diff --git
a/lib/pleroma/plugs/authentication_plug.ex
b/lib/pleroma/plugs/authentication_plug.ex
index 90bd07b911bcca4dcb36872120b500fafcc0f562..60f6faf494496b0e7085134c35b48ff173340283 100644
(file)
--- a/
lib/pleroma/plugs/authentication_plug.ex
+++ b/
lib/pleroma/plugs/authentication_plug.ex
@@
-1,28
+1,41
@@
defmodule Pleroma.Plugs.AuthenticationPlug do
defmodule Pleroma.Plugs.AuthenticationPlug do
+ alias Comeonin.Pbkdf2
import Plug.Conn
import Plug.Conn
+ alias Pleroma.User
def init(options) do
options
end
def init(options) do
options
end
+ def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
+
def call(conn, opts) do
with {:ok, username, password} <- decode_header(conn),
{:ok, user} <- opts[:fetcher].(username),
def call(conn, opts) do
with {:ok, username, password} <- decode_header(conn),
{:ok, user} <- opts[:fetcher].(username),
- {:ok, verified_user} <- verify(user, password)
+ false <- !!user.info["deactivated"],
+ saved_user_id <- get_session(conn, :user_id),
+ {:ok, verified_user} <- verify(user, password, saved_user_id)
do
do
- conn |> assign(:user, verified_user)
+ conn
+ |> assign(:user, verified_user)
+ |> put_session(:user_id, verified_user.id)
else
_ -> conn |> halt_or_continue(opts)
end
end
else
_ -> conn |> halt_or_continue(opts)
end
end
- defp verify(nil, _password) do
- Comeonin.Pbkdf2.dummy_checkpw
+ # Short-circuit if we have a cookie with the id for the given user.
+ defp verify(%{id: id} = user, _password, id) do
+ {:ok, user}
+ end
+
+ defp verify(nil, _password, _user_id) do
+ Pbkdf2.dummy_checkpw
:error
end
:error
end
- defp verify(user, password) do
- if
Comeonin.
Pbkdf2.checkpw(password, user.password_hash) do
+ defp verify(user, password
, _user_id
) do
+ if Pbkdf2.checkpw(password, user.password_hash) do
{:ok, user}
else
:error
{:ok, user}
else
:error
@@
-32,9
+45,9
@@
defmodule Pleroma.Plugs.AuthenticationPlug do
defp decode_header(conn) do
with ["Basic " <> header] <- get_req_header(conn, "authorization"),
{:ok, userinfo} <- Base.decode64(header),
defp decode_header(conn) do
with ["Basic " <> header] <- get_req_header(conn, "authorization"),
{:ok, userinfo} <- Base.decode64(header),
- [username, password] <- String.split(userinfo, ":")
+ [username, password] <- String.split(userinfo, ":"
, parts: 2
)
do
do
- {
:ok, username, password
}
+ {
:ok, username, password
}
end
end
end
end