Sha256: 601d2f029223ffb8462c6427b7ee92378d4abdf57fd5b6519703091ad4d38d8e

Contents?: true

Size: 1.85 KB

Versions: 19

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Decidim
  # The controller to handle the user's account page.
  class AccountController < Decidim::ApplicationController
    include Decidim::UserProfile

    def show
      enforce_permission_to :show, :user, current_user: current_user
      @account = form(AccountForm).from_model(current_user)
    end

    def update
      enforce_permission_to :update, :user, current_user: current_user
      @account = form(AccountForm).from_params(account_params)

      UpdateAccount.call(current_user, @account) do
        on(:ok) do |email_is_unconfirmed|
          flash[:notice] = if email_is_unconfirmed
                             t("account.update.success_with_email_confirmation", scope: "decidim")
                           else
                             t("account.update.success", scope: "decidim")
                           end

          bypass_sign_in(current_user)
          redirect_to account_path(locale: current_user.reload.locale)
        end

        on(:invalid) do
          flash[:alert] = t("account.update.error", scope: "decidim")
          render action: :show
        end
      end
    end

    def delete
      enforce_permission_to :delete, :user, current_user: current_user
      @form = form(DeleteAccountForm).from_model(current_user)
    end

    def destroy
      enforce_permission_to :delete, :user, current_user: current_user
      @form = form(DeleteAccountForm).from_params(params)

      DestroyAccount.call(current_user, @form) do
        on(:ok) do
          sign_out(current_user)
          flash[:notice] = t("account.destroy.success", scope: "decidim")
        end

        on(:invalid) do
          flash[:alert] = t("account.destroy.error", scope: "decidim")
        end
      end

      redirect_to decidim.root_path
    end

    private

    def account_params
      params[:user].to_unsafe_h
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/controllers/decidim/account_controller.rb
decidim-core-0.26.9 app/controllers/decidim/account_controller.rb
decidim-core-0.26.8 app/controllers/decidim/account_controller.rb
decidim-core-0.26.7 app/controllers/decidim/account_controller.rb
decidim-core-0.26.5 app/controllers/decidim/account_controller.rb
decidim-core-0.26.4 app/controllers/decidim/account_controller.rb
decidim-core-0.26.3 app/controllers/decidim/account_controller.rb
decidim-core-0.26.2 app/controllers/decidim/account_controller.rb
decidim-core-0.26.1 app/controllers/decidim/account_controller.rb
decidim-core-0.26.0 app/controllers/decidim/account_controller.rb
decidim-core-0.26.0.rc2 app/controllers/decidim/account_controller.rb
decidim-core-0.26.0.rc1 app/controllers/decidim/account_controller.rb
decidim-core-0.25.2 app/controllers/decidim/account_controller.rb
decidim-core-0.25.1 app/controllers/decidim/account_controller.rb
decidim-core-0.25.0 app/controllers/decidim/account_controller.rb
decidim-core-0.25.0.rc4 app/controllers/decidim/account_controller.rb
decidim-core-0.25.0.rc3 app/controllers/decidim/account_controller.rb
decidim-core-0.25.0.rc2 app/controllers/decidim/account_controller.rb
decidim-core-0.25.0.rc1 app/controllers/decidim/account_controller.rb