From 968d7490b689ba501a64f350841dc8f9b33b5244 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 16:27:16 +0300 Subject: [PATCH] [#114] User.Info: renamed `confirmation_update` to `confirmation_changeset`. --- lib/pleroma/user.ex | 2 +- lib/pleroma/user/info.ex | 10 +++++----- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- test/web/oauth/oauth_controller_test.exs | 2 +- test/web/twitter_api/twitter_api_controller_test.exs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 41d01cbf5..4e227b08d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -191,7 +191,7 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) - |> put_change(:info, User.Info.confirmation_change(%User.Info{}, confirmation_status)) + |> put_change(:info, User.Info.confirmation_changeset(%User.Info{}, confirmation_status)) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2800e9cff..ad9fe1bbe 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -143,21 +143,21 @@ def profile_update(info, params) do ]) end - def confirmation_change(info, :confirmed) do - confirmation_change(info, %{ + def confirmation_changeset(info, :confirmed) do + confirmation_changeset(info, %{ confirmation_pending: false, confirmation_token: nil }) end - def confirmation_change(info, :unconfirmed) do - confirmation_change(info, %{ + def confirmation_changeset(info, :unconfirmed) do + confirmation_changeset(info, %{ confirmation_pending: true, confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64() }) end - def confirmation_change(info, params) do + def confirmation_changeset(info, params) do cast(info, params, [:confirmation_pending, :confirmation_token]) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 4bd729b77..b362f3946 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -376,7 +376,7 @@ def password_reset(conn, params) do def confirm_email(conn, %{"token" => token}) do with %User{} = user <- User.get_by_confirmation_token(token), true <- user.local, - info_change <- User.Info.confirmation_change(user.info, :confirmed), + info_change <- User.Info.confirmation_changeset(user.info, :confirmed), changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do conn diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index 26505bab7..0621a8acc 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -116,7 +116,7 @@ test "rejects token exchange with invalid client credentials" do test "rejects token exchange for valid credentials belonging to unconfirmed user" do password = "testpassword" user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password)) - info_change = Pleroma.User.Info.confirmation_change(user.info, :unconfirmed) + info_change = Pleroma.User.Info.confirmation_changeset(user.info, :unconfirmed) {:ok, user} = user diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index a269c9757..53b390793 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -876,7 +876,7 @@ test "it returns 500 when user is not local", %{conn: conn, user: user} do describe "GET /api/account/confirm_email/:token" do setup do user = insert(:user) - info_change = User.Info.confirmation_change(user.info, :unconfirmed) + info_change = User.Info.confirmation_changeset(user.info, :unconfirmed) {:ok, user} = user @@ -908,7 +908,7 @@ test "it confirms the user account", %{conn: conn, user: user} do describe "POST /api/account/resend_confirmation_email" do setup do user = insert(:user) - info_change = User.Info.confirmation_change(user.info, :unconfirmed) + info_change = User.Info.confirmation_changeset(user.info, :unconfirmed) {:ok, user} = user