Sha256: 8e0cc61b729980afc95cbf531398247df3774be15abf2520baf03e645c31f6f6

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_dependency "decidim/application_controller"

module Decidim
  # The controller to handle the user's account page.
  class AccountController < 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(params)

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

          bypass_sign_in(current_user)
        end

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

      render action: :show
    end

    private

    def authorizations
      @authorizations ||= current_user.authorizations
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-core-0.2.0 app/controllers/decidim/account_controller.rb