Sha256: 50fa66f50c1044b0784cca8ae9a23f8f8158d93571ce388ca31eab779ebf5ee7

Contents?: true

Size: 1.85 KB

Versions: 24

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
    helper_method :authorizations
    include Decidim::UserProfile

    def show
      authorize! :show, current_user
      @account = form(AccountForm).from_model(current_user)
    end

    def update
      authorize! :update, 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
        end

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

    def delete
      authorize! :delete, current_user
      @form = form(DeleteAccountForm).from_model(current_user)
    end

    def destroy
      authorize! :delete, 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 authorizations
      @authorizations ||= current_user.authorizations
    end

    def account_params
      { avatar: current_user.avatar }.merge(params[:user].to_unsafe_h)
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
decidim-core-0.6.8 app/controllers/decidim/account_controller.rb
decidim-0.6.8 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.7 app/controllers/decidim/account_controller.rb
decidim-0.6.7 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.6 app/controllers/decidim/account_controller.rb
decidim-0.6.6 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.5 app/controllers/decidim/account_controller.rb
decidim-0.6.5 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.4 app/controllers/decidim/account_controller.rb
decidim-0.6.4 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.3 app/controllers/decidim/account_controller.rb
decidim-0.6.3 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.2 app/controllers/decidim/account_controller.rb
decidim-0.6.2 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.1 app/controllers/decidim/account_controller.rb
decidim-0.6.1 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.6.0 app/controllers/decidim/account_controller.rb
decidim-0.6.0 decidim-core/app/controllers/decidim/account_controller.rb
decidim-core-0.5.1 app/controllers/decidim/account_controller.rb
decidim-0.5.1 decidim-core/app/controllers/decidim/account_controller.rb