Sha256: 57a6c1ba524c186241406ceee63e52bb7810c026a67118fa275156220a293633

Contents?: true

Size: 552 Bytes

Versions: 5

Compression:

Stored size: 552 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 }
    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-0.0.22 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.20 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.18 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.17 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
authentication-zero-0.0.16 lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt