X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fcommon_api%2Futils.ex;h=30089f553abbbf1646f6cd6e748bdd0828dfd7c3;hb=564c73ab2496bee24ba46f69fc48662296041db6;hp=5c2123f2d8675ee47ffdbd20eebe0564ed200e25;hpb=a16117225f9a4da9da08013ae256d8ac02ee3ec5;p=akkoma diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 5c2123f2d..30089f553 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -9,11 +9,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do def get_by_id_or_ap_id(id) do activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) - if activity.data["type"] == "Create" do - activity - else - Activity.get_create_activity_by_object_ap_id(activity.data["object"]) - end + activity && + if activity.data["type"] == "Create" do + activity + else + Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + end end def get_replied_to_activity(id) when not is_nil(id) do @@ -133,7 +134,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do "context" => context, "attachment" => attachments, "actor" => actor, - "tag" => tags |> Enum.map(fn {_, tag} -> tag end) + "tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq() } if inReplyTo do @@ -187,18 +188,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do end end - def confirm_current_password(user, params) do - case user do - nil -> - {:error, "Invalid credentials."} - - _ -> - with %User{local: true} = db_user <- Repo.get(User, user.id), - true <- Pbkdf2.checkpw(params["password"], db_user.password_hash) do - {:ok, db_user} - else - _ -> {:error, "Invalid password."} - end + def confirm_current_password(user, password) do + with %User{local: true} = db_user <- Repo.get(User, user.id), + true <- Pbkdf2.checkpw(password, db_user.password_hash) do + {:ok, db_user} + else + _ -> {:error, "Invalid password."} end end end