Sha256: 5f41d05ef5c0bf2f5617c28a6bf301aa021ca0303b765260efbcae5dd224a7f0

Contents?: true

Size: 1.89 KB

Versions: 33

Compression:

Stored size: 1.89 KB

Contents

module Locomotive
  module API
    module Resources

      class MyAccountResource < Grape::API

        resource :my_account do

          entity_klass = Entities::AccountEntity

          helpers do
            def must_not_be_logged_in
              raise Pundit::NotAuthorizedError.new('You must not be logged in') if current_account
            end
          end

          desc 'Show my account'
          get do
            authenticate_locomotive_account!
            present current_account, with: entity_klass
          end

          desc 'Update my account'
          params do
            requires :account, type: Hash do
              optional :name
              optional :email
              optional :locale
              optional :encrypte_password
              optional :password_salt
              optional :password
              optional :password_confirmation
            end
          end
          put do
            authenticate_locomotive_account!
            my_account = current_account
            authorize my_account, :update?

            my_account_form = Forms::MyAccountForm.new(permitted_params[:account])
            my_account.assign_attributes(my_account_form.serializable_hash)
            my_account.save!

            present my_account, with: entity_klass
          end


          desc 'Create account'
          params do
            requires :account, type: Hash do
              requires :name
              requires :email
              requires :password
              optional :password_confirmation
              optional :locale
            end
          end
          post do
            must_not_be_logged_in

            my_account_form = Forms::MyAccountForm.new(permitted_params[:account])
            my_account = Account.create!(my_account_form.serializable_hash)

            present my_account, with: entity_klass
          end

        end
      end

    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.2.0.alpha1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.1.1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.1.0 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.1.0.rc1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.3 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.0 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.0.rc0 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.0.alpha3 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.4.1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.0.alpha2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-4.0.0.alpha1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.4.0 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.3.0 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.3.0.rc3 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.3.0.rc2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.1.2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.2.1 app/api/locomotive/api/resources/my_account_resource.rb