Sha256: 041d8352474844d091dea0ccc1f3df22f484de741bba1b32156312b1ec8089d2

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Overrides
  class SessionsController < DeviseTokenAuth::SessionsController
    OVERRIDE_PROOF = '(^^,)'.freeze

    def create
      @resource = resource_class.find_by(email: resource_params[:email])

      if @resource && valid_params?(:email, resource_params[:email]) && @resource.valid_password?(resource_params[:password]) && @resource.confirmed?
        @client_id, @token = @resource.create_token
        @resource.save

        render json: {
          data: @resource.as_json(except: %i[tokens created_at updated_at]),
          override_proof: OVERRIDE_PROOF
        }

      elsif @resource && (not @resource.confirmed?)
        render json: {
          success: false,
          errors: [
            "A confirmation email was sent to your account at #{@resource.email}. "\
            'You must follow the instructions in the email before your account '\
            'can be activated'
          ]
        }, status: 401

      else
        render json: {
          errors: ['Invalid login credentials. Please try again.']
        }, status: 401
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devise_token_auth-1.0.0 test/dummy/app/controllers/overrides/sessions_controller.rb
devise_token_auth-1.0.0.rc2 test/dummy/app/controllers/overrides/sessions_controller.rb
devise_token_auth-1.0.0.rc1 test/dummy/app/controllers/overrides/sessions_controller.rb