Gatleon Rails
add authentication to your website - in 1 minute or less.
Installation
Add this line to your application's Gemfile:
gem "gatleon-rails"
And then execute:
$ bundle install
Add a profile controller
class ProfileController < ActionController::Base
AUTHFORM_FORM_SECRET_KEY = "" # Available at https://authform.gatleon.com. coming soon!
AUTHFORM_FORM_PUBLIC_KEY = "" # Available at https://authform.gatleon.com. coming soon!
include Gatleon::Rails::Authform::Concern.new(public_key: AUTHFORM_FORM_PUBLIC_KEY, secret_key: AUTHFORM_FORM_SECRET_KEY)
before_action :require_login, only: [:index]
def index
erb = <<~ERB
<h1>Profile</h1>
<p style="color: green;">You are signed in.</p>
<p><%= current_user %></p>
ERB
render inline: erb
end
def signin
erb = <<~ERB
<p style="color: red;"><%= flash[:error] %></p>
<h1>Sign In</h1>
<form action="https://authform.gatleon.com/v1/form/<%= ProfileController::AUTHFORM_FORM_PUBLIC_KEY %>" method="POST">
<input type="email" name="email">
<button type="submit">Sign In</button>
</form>
ERB
render inline: erb
end
private
def require_login
unless current_user
flash[:error] = "Sign in, please."
redirect_to(profile_signin_path) and return
end
end
end
Add profile routes to routes.rb
Rails.application.routes.draw do
get '/profile', to: 'profile#index', as: 'profile'
get '/profile/signin', to: 'profile#signin', as: 'profile_signin'
end
That's it!
License
The gem is available as open source under the terms of the MIT License.