Sha256: 48435c447ceb843b7631958e14d1cc638fa0e43b0eda29d256522c306fcd43c7

Contents?: true

Size: 545 Bytes

Versions: 2

Compression:

Stored size: 545 Bytes

Contents

class SessionsController < ApplicationController
  skip_before_action :authenticate, except: :destroy

  def create
    @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])

    if @<%= singular_table_name %>.try(:authenticate, params[:password])
      render json: { session_token: @<%= singular_table_name %>.session_token }
    else
      render json: { error: "Invalid email or password" }, status: :unauthorized
    end
  end

  def destroy
    Current.<%= singular_table_name %>.regenerate_session_token
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-0.0.21 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.19 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt