Sha256: c821f8618ef369a96cd18e50f32555ffc407f9d3c1f17852394c0a196812bc6c

Contents?: true

Size: 565 Bytes

Versions: 5

Compression:

Stored size: 565 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 %>.signed_session_token }, status: :ok
    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

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-1.0.2 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-1.0.1 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-1.0.0 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.24 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.23 lib/generators/authentication/templates/app/controllers/api/sessions_controller.rb.tt