[#114] Email confirmation route, action, node setting, User.Info fields.

This commit is contained in:
Ivan Tashkinov 2018-12-14 16:38:56 +03:00
parent b6ae412fcd
commit a05cb10a95
5 changed files with 25 additions and 0 deletions

View file

@ -364,6 +364,10 @@ def get_or_fetch_by_nickname(nickname) do
end end
end end
def get_by_confirmation_token(token) do
Repo.one(from(u in User, where: fragment("? ->> 'confirmation_token' = ?", u.info, ^token)))
end
def get_followers_query(%User{id: id, follower_address: follower_address}) do def get_followers_query(%User{id: id, follower_address: follower_address}) do
from( from(
u in User, u in User,

View file

@ -9,6 +9,8 @@ defmodule Pleroma.User.Info do
field(:note_count, :integer, default: 0) field(:note_count, :integer, default: 0)
field(:follower_count, :integer, default: 0) field(:follower_count, :integer, default: 0)
field(:locked, :boolean, default: false) field(:locked, :boolean, default: false)
field(:confirmation_pending, :boolean, default: false)
field(:confirmation_token, :string, default: nil)
field(:default_scope, :string, default: "public") field(:default_scope, :string, default: "public")
field(:blocks, {:array, :string}, default: []) field(:blocks, {:array, :string}, default: [])
field(:domain_blocks, {:array, :string}, default: []) field(:domain_blocks, {:array, :string}, default: [])
@ -141,6 +143,10 @@ def profile_update(info, params) do
]) ])
end end
def confirmation_update(info, params) do
cast(info, params, [:confirmation_pending, :confirmation_token])
end
def mastodon_profile_update(info, params) do def mastodon_profile_update(info, params) do
info info
|> cast(params, [ |> cast(params, [

View file

@ -132,6 +132,7 @@ def nodeinfo(conn, %{"version" => "2.0"}) do
banner: Keyword.get(instance, :banner_upload_limit), banner: Keyword.get(instance, :banner_upload_limit),
background: Keyword.get(instance, :background_upload_limit) background: Keyword.get(instance, :background_upload_limit)
}, },
accountActivationRequired: Keyword.get(instance, :account_activation_required, false),
invitesEnabled: Keyword.get(instance, :invites_enabled, false), invitesEnabled: Keyword.get(instance, :invites_enabled, false),
features: features features: features
} }

View file

@ -281,6 +281,7 @@ defmodule Pleroma.Web.Router do
post("/account/register", TwitterAPI.Controller, :register) post("/account/register", TwitterAPI.Controller, :register)
post("/account/password_reset", TwitterAPI.Controller, :password_reset) post("/account/password_reset", TwitterAPI.Controller, :password_reset)
get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email)
get("/search", TwitterAPI.Controller, :search) get("/search", TwitterAPI.Controller, :search)
get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)

View file

@ -372,6 +372,19 @@ def password_reset(conn, params) do
end end
end end
def confirm_email(conn, %{"token" => token}) do
with %User{} = user <- User.get_by_confirmation_token(token),
true <- user.local,
new_info_fields <- %{confirmation_pending: false, confirmation_token: nil},
info_change <- User.Info.confirmation_update(user.info, new_info_fields),
changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change),
{:ok, _} <- User.update_and_set_cache(changeset) do
conn
|> put_flash(:info, "Email confirmed. Please sign in.")
|> redirect(to: "/")
end
end
def update_avatar(%{assigns: %{user: user}} = conn, params) do def update_avatar(%{assigns: %{user: user}} = conn, params) do
{:ok, object} = ActivityPub.upload(params, type: :avatar) {:ok, object} = ActivityPub.upload(params, type: :avatar)
change = Changeset.change(user, %{avatar: object.data}) change = Changeset.change(user, %{avatar: object.data})