Skip to content

Instantly share code, notes, and snippets.

View 123ish's full-sized avatar

123ish LLC 123ish

View GitHub Profile
@123ish
123ish / activate_2fa.html.erb
Created June 24, 2020 00:34 — forked from imrubyist/activate_2fa.html.erb
Two-Factor authentication form with QR code
<# /app/views/users/activate_2fa.html.erb %>
<%= @svg.html_safe %>
<%= form_for(@user, url: activate_2fa_update_path) do |f| %>
<%= f.text_field :otp_response_code %>
<%= f.submit %>
<% end %>
@123ish
123ish / Gemfile
Created June 24, 2020 00:34 — forked from imrubyist/Gemfile
Gemfile for Two-Factor authentication with devise and active_model_otp gem
gem 'devise', '~> 4.7.1'
gem 'active_model_otp', '~> 2.0.1'
gem 'rqrcode', '~> 1.1.2
@123ish
123ish / sessions_controller.rb
Created June 24, 2020 00:35 — forked from imrubyist/sessions_controller.rb
Two-Factor authentication with devise - override sessions controller
# /app/controllers/users/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
def create
self.resource = resource_class.find_for_authentication(sign_in_params.except(:password, :otp_response_code))
if resource
if resource.active_for_authentication?
if resource && resource.otp_module_disabled?
continue_sign_in(resource, resource_name)
elsif resource && resource.otp_module_enabled?
@123ish
123ish / two_factors_authentication.html.erb
Created June 24, 2020 00:35 — forked from imrubyist/two_factors_authentication.html.erb
Two-Factor authentication - form after login
<%# /app/views/users/sessions/two_factors_authentication.html.erb %>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => { :role => 'form', :method => 'POST' }) do |f| %>
<%= f.hidden_field :email, value: params[:user][:email] %>
<%= f.text_field :otp_response_code %>
<%= f.submit %>
<% end %>
@123ish
123ish / users_controller.rb
Created June 24, 2020 00:35 — forked from imrubyist/users_controller.rb
Two-Factor authentication users controller
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def activate_2fa
qrcode = RQRCode::QRCode.new(current_user.provisioning_uri(nil, issuer: 'your-app-url.com'), :size => 12, :level => :h)
@svg = qrcode.as_svg(offset: 0, color: '000',
shape_rendering: 'crispEdges',
module_size: 4)
respond_to :html
end
@123ish
123ish / Gemfile
Created July 3, 2020 15:32 — forked from imrubyist/Gemfile
Optimize Rails app with Bullet - Gemfile
gem 'bullet', '~> 6.1.0'
@123ish
123ish / optimization.rb
Created July 3, 2020 15:34 — forked from imrubyist/optimization.rb
Place this on config/environments/optimization.rb
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end
@123ish
123ish / Gemfile
Created July 3, 2020 15:34 — forked from imrubyist/Gemfile
Gemfile with custom environment
group :optimization do
gem 'bullet', '~> 6.1.0'
end
@123ish
123ish / mime_types.rb
Created July 6, 2020 20:59 — forked from imrubyist/mime_types.rb
Create AMP in Rails powered website - mime_types.rb
# config/initializers/mime_types.rb
Mime::Type.register 'text/html', :amp
@123ish
123ish / samples_controller.rb
Created July 9, 2020 01:47 — forked from imrubyist/samples_controller.rb
Create AMP in Rails powered website - samples_controller.rb
# app/controllers/samples_controller.rb
Class SamplesController
# other existing methods
def show
# your existing codes
respond_to do |format|
format.html
format.amp { render 'amp/samples/show.amp', layout: 'amp/layouts/application' }
end