wedding-planner/app/controllers/sessions_controller.rb

22 lines
649 B
Ruby
Raw Normal View History

2024-11-18 23:27:50 +00:00
# Copyright (C) 2024 Manuel Bustillo
class SessionsController < ApplicationController
2024-11-19 00:32:24 +01:00
allow_unauthenticated_access only: :create
rate_limit to: 10, within: 3.minutes, only: :create,
with: -> { render json: { errors: ['Rate limit exceeded'] }, status: :too_many_requests }
def create
if user = User.authenticate_by(params.permit(:email_address, :password))
start_new_session_for user
2024-11-19 00:32:24 +01:00
render json: {}, status: :created
else
2024-11-19 00:32:24 +01:00
render json: { errors: ['Invalid email address or password'] }, status: :unauthorized
end
end
def destroy
terminate_session
2024-11-19 00:32:24 +01:00
render json: {}, status: :ok
end
end