Skip to content

Instantly share code, notes, and snippets.

View 123ish's full-sized avatar

123ish LLC 123ish

View GitHub Profile
@123ish
123ish / Hello!
Created May 31, 2020 00:41
Hello from 123ish!
123ish LLC will provide a Social Network Service that navigates the users through the discovery of the best solutions, tools, places, people, products, and ideas for their specific interests and matters of living.
123ishは、ユーザーの特別な興味や生活の様々な場面において、最良な解決、手段、場所、人、商品、アイデアの発見を導くソーシャルネットワーキングサービスを提供します。
123ish LLC akan menyediakan Layanan Jejaring Sosial yang menavigasi pengguna melalui penemuan solusi, alat, tempat, orang, produk, dan ide terbaik untuk kepentingan dan hal-hal khusus mereka.
@123ish
123ish / example_active_support.rb
Last active June 20, 2020 15:31
Sampe gist - active_support.rb
# test gist
# just a code chunk
require "securerandom"
require "active_support/dependencies/autoload"
....
module ActiveSupport
extend ActiveSupport::Autoload
@123ish
123ish / activate_2fa.html.erb
Created June 23, 2020 00:26
How to implement two-factor authentication for Rails app by using Devise gem, Google authenticator, and ActiveModel::Otp gem: activate_2fa.html.erb
<# /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 23, 2020 00:28
How to implement two-factor authentication for Rails app by using Devise gem, Google authenticator, and ActiveModel::Otp gem - Gemfile
gem 'devise', '~> 4.7.1'
gem 'active_model_otp', '~> 2.0.1'
gem 'rqrcode', '~> 1.1.2'
@123ish
123ish / activate_2fa.html.erb
Created June 24, 2020 00:34 — forked from kevinhq/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 kevinhq/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 kevinhq/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 kevinhq/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 kevinhq/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 / entries_controller.rb
Last active June 27, 2020 21:21
Friendly ID # /app/controllers/entries_controller.rb
class EntriesController < ApplicationController
before_action :set_entry, only: [:show, :update, :destroy, :edit]
def set_entry
@entry = Entry.find(params[:id])
if !Rails.env.test? && @entry.friendly_id.present? && action_name=='show'
redirect_to action: action_name, id: @entry.friendly_id, status: 301 unless @entry.friendly_id == params[:id]
end
end
emd