Sha256: d2027b876285c9ee8341d9bd5654ca41e4c66a3667b93136f8ccfd9f57176972

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Overrides
  class SessionsController < DeviseTokenAuth::SessionsController
    OVERRIDE_PROOF = "(^^,)"

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

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

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

      elsif @resource and 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

2 entries across 2 versions & 2 rubygems

Version Path
devise_token_auth-0.1.43 test/dummy/app/controllers/overrides/sessions_controller.rb
digix_devise_token_auth-0.1.44 test/dummy/app/controllers/overrides/sessions_controller.rb