This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/attribute-map.yml | |
"urn:mace:dir:attribute-def:email": "email" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/admin_user.rb | |
devise :recoverable, :rememberable, :trackable, :validatable, :lockable, :saml_authenticatable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/admin_users/sessions_controller.rb | |
prepend_before_action :require_no_authentication, only: [:new, :create] | |
prepend_before_action :allow_params_authentication!, only: :create | |
prepend_before_action :verify_signed_out_user, only: :destroy | |
prepend_before_action(only: [:create, :destroy]) { request.env["devise.skip_timeout"] = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/devise.rb | |
ActionDispatch::Routing::Mapper.class_eval do | |
protected | |
def devise_saml_authenticatable(mapping, controllers) | |
if ::Devise.saml_route_helper_prefix | |
prefix = ::Devise.saml_route_helper_prefix | |
resource :session, only: [], controller: controllers[:saml_sessions], path: '' do | |
get :new, path: 'saml/sign_in', as: "new_#{prefix}" | |
post :create, path: 'saml/auth', as: prefix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/active_admin_devise.rb | |
module ActiveAdmin | |
module Devise | |
def self.controllers | |
{ | |
sessions: "admin_users/sessions", | |
passwords: "active_admin/devise/passwords", | |
unlocks: "active_admin/devise/unlocks", | |
registrations: "active_admin/devise/registrations", | |
confirmations: "active_admin/devise/confirmations" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/admin_users/sessions_controller.rb | |
module AdminUsers | |
class SessionsController < Devise::SessionsController | |
# As you are overwriting devise session controller you need this to allow to login with user & pass (dev mode) | |
prepend_before_action :require_no_authentication, only: [:new, :create] | |
layout 'active_admin_logged_out' | |
helper ::ActiveAdmin::ViewHelpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/devise.rb | |
config.saml_route_helper_prefix = 'saml' | |
callback = Rails.env.development? ? 'http://localhost:3000' : ENV['SAML_CALLBACK_ADDRESS'] | |
# SAML configuration | |
config.saml_create_user = true | |
config.saml_update_user = true | |
config.saml_default_user_key = :email | |
config.saml_session_index_key = :session_index | |
config.saml_use_subject = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .env.dev | |
STRIPE_KEY="pk_test_TYooMQauvdEDq54NiTphI7jx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/services/stripe_service.rb | |
def create_subscription | |
Stripe::Subscription.create( | |
customer: customer.id, | |
plan: subs_plan_id, # this is the id of your plan (eg: monthly, annual, etc) | |
coupon: discount_code # if you have any (check COUPONS section below to understand them in more detail) | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/subscription.rb | |
class Subscription < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :purchase_plan # this can be optional if you have annual or monthly plans for example | |
has_many :subscription_items, dependent: :destroy # I'm going to explain this later | |
enum status: ['define_your_possible_statuses'] | |
end |
NewerOlder