Daniel's implementation - mnishiguchi/authentication_demo GitHub Wiki
class Login < ApplicationRecord
strip_attributes
has_secure_password
before_save { self.email = email.downcase }
validates :first_name, presence: true, length: { maximum: 50 }
validates :last_name, presence: true, length: { maximum: 50 }
validates :email, presence: true, length: { maximum: 255 }, email: true, uniqueness: { case_sensitive: false }
belongs_to :frontend_authenticatable, polymorphic: true, optional: true
belongs_to :backend_authenticatable, polymorphic: true, optional: true
end
create_table :logins do |t|
t.string :first_name
t.string :last_name
t.string :email
t.index :email, unique: true
t.string :password_digest
t.references :pulse_authenticatable, polymorphic: true, index: true
t.references :frontend_authenticatable, polymorphic: true, index: true
t.timestamps
end
Login
---
name
email
password
/ \
FrontendUser Admin AccountExecutive PropertyClient ManagementClinet
module BackendUser (mixin)
Backend user
- Manually registered.
- Can get a front-end account automatically if needed.