1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
9 alias Pleroma.Plugs.RateLimiter
13 plug(RateLimiter, [name: :authentication] when action in [:user_exists, :check_password])
14 plug(RateLimiter, [name: :authentication, params: ["user"]] when action == :check_password)
16 def user_exists(conn, %{"user" => username}) do
17 with %User{} <- Repo.get_by(User, nickname: username, local: true) do
23 |> put_status(:not_found)
28 def check_password(conn, %{"user" => username, "pass" => password}) do
29 user = Repo.get_by(User, nickname: username, local: true)
31 case User.account_status(user) do
34 |> put_status(:not_found)
37 :confirmation_pending ->
39 |> put_status(:not_found)
43 with %User{password_hash: password_hash} <-
45 true <- Pbkdf2.checkpw(password, password_hash) do
51 |> put_status(:forbidden)
56 |> put_status(:not_found)