Gokul595/api_guard

View on GitHub
app/controllers/api_guard/registration_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

require_dependency 'api_guard/application_controller'

module ApiGuard
  class RegistrationController < ApplicationController
    before_action :authenticate_resource, only: [:destroy]

    def create
      init_resource(sign_up_params)
      if resource.save
        create_token_and_set_header(resource, resource_name)
        render_success(message: I18n.t('api_guard.registration.signed_up'))
      else
        render_error(422, object: resource)
      end
    end

    def destroy
      current_resource.destroy
      render_success(message: I18n.t('api_guard.registration.account_deleted'))
    end

    private

    def sign_up_params
      params.permit(:email, :password, :password_confirmation)
    end
  end
end