Sha256: fdb3d1dcca2eab91fb0bafdeedeb56baf3e1e348c7f60b285a6eaef1bbb2c1e6

Contents?: true

Size: 1.89 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
locomotivecms-3.0.0.rc5 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.rc4 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.rc3 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.rc2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.rc1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.pre.beta.1 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.pre.alpha.3 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.pre.alpha.2 app/api/locomotive/api/resources/my_account_resource.rb
locomotivecms-3.0.0.pre.alpha app/api/locomotive/api/resources/my_account_resource.rb