1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MongooseIM.MongooseIMController do
6 use Pleroma.Web, :controller
10 alias Pleroma.Web.Plugs.RateLimiter
12 plug(RateLimiter, [name: :authentication] when action in [:user_exists, :check_password])
13 plug(RateLimiter, [name: :authentication, params: ["user"]] when action == :check_password)
15 def user_exists(conn, %{"user" => username}) do
16 with %User{} <- Repo.get_by(User, nickname: username, local: true, is_active: true) do
22 |> put_status(:not_found)
27 def check_password(conn, %{"user" => username, "pass" => password}) do
28 with %User{password_hash: password_hash, is_active: true} <-
29 Repo.get_by(User, nickname: username, local: true),
30 true <- Pleroma.Password.checkpw(password, password_hash) do
36 |> put_status(:forbidden)
41 |> put_status(:not_found)