Skip to content

Instantly share code, notes, and snippets.

@afcapel
Last active July 3, 2018 20:36
Show Gist options
  • Save afcapel/c534b63975d26bce9a072344b64a86b9 to your computer and use it in GitHub Desktop.
Save afcapel/c534b63975d26bce9a072344b64a86b9 to your computer and use it in GitHub Desktop.
# app/controllers/concerns/authentication.rb
# (Authorisation is different than Authentication and so it is handled in a different concern)
module Authentication
extend ActiveSupport::Concern
included do
before_action :authenticate
helper_method :logged_in?
end
private
def logged_in?
Current.person.present?
end
def authenticate
if authenticated_user = Person.find_by(id: session[:person_id])
Current.person = authenticated_user
end
end
def sign_in(person)
session[:person_id] = person.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment