kingsman 0.0.0.beta → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +5 -4
- data/app/controllers/kingsman/confirmations_controller.rb +54 -0
- data/app/controllers/kingsman/omniauth_callbacks_controller.rb +36 -0
- data/app/controllers/kingsman/passwords_controller.rb +83 -0
- data/app/controllers/kingsman/registrations_controller.rb +168 -0
- data/app/controllers/kingsman/sessions_controller.rb +83 -0
- data/app/controllers/kingsman/unlocks_controller.rb +52 -0
- data/app/controllers/kingsman_controller.rb +252 -0
- data/app/jobs/application_job.rb +2 -0
- data/app/mailers/kingsman/mailer.rb +30 -0
- data/app/views/kingsman/confirmations/new.html.erb +16 -0
- data/app/views/kingsman/home/index.html.erb +1 -0
- data/app/views/kingsman/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/kingsman/mailer/email_changed.html.erb +7 -0
- data/app/views/kingsman/mailer/password_change.html.erb +3 -0
- data/app/views/kingsman/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/kingsman/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/kingsman/passwords/edit.html.erb +25 -0
- data/app/views/kingsman/passwords/new.html.erb +16 -0
- data/app/views/kingsman/registrations/edit.html.erb +42 -0
- data/app/views/kingsman/registrations/new.html.erb +29 -0
- data/app/views/kingsman/sessions/new.html.erb +26 -0
- data/app/views/kingsman/shared/_error_messages.html.erb +15 -0
- data/app/views/kingsman/shared/_links.html.erb +25 -0
- data/app/views/kingsman/unlocks/new.html.erb +16 -0
- data/app/views/kingsman/up/index.html.erb +11 -0
- data/config/application.rb +0 -0
- data/config/locales/en.yml +63 -0
- data/config.ru +6 -0
- data/lib/generators/active_record/kingsman_generator.rb +127 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/kingsman/controllers_generator.rb +46 -0
- data/lib/generators/kingsman/install_generator.rb +42 -0
- data/lib/generators/kingsman/kingsman_generator.rb +28 -0
- data/lib/generators/kingsman/orm_helpers.rb +40 -0
- data/lib/generators/kingsman/views_generator.rb +145 -0
- data/lib/generators/mongoid/kingsman_generator.rb +57 -0
- data/lib/generators/templates/README +36 -0
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/kingsman.rb +313 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +20 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +27 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +18 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +35 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +25 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +20 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +19 -0
- data/lib/kingsman/autoloader.rb +31 -0
- data/lib/kingsman/controllers/helpers.rb +221 -0
- data/lib/kingsman/controllers/rememberable.rb +57 -0
- data/lib/kingsman/controllers/responder.rb +35 -0
- data/lib/kingsman/controllers/scoped_views.rb +19 -0
- data/lib/kingsman/controllers/sign_in_out.rb +112 -0
- data/lib/kingsman/controllers/store_location.rb +76 -0
- data/lib/kingsman/controllers/url_helpers.rb +72 -0
- data/lib/kingsman/delegator.rb +18 -0
- data/lib/kingsman/encryptor.rb +19 -0
- data/lib/kingsman/failure_app.rb +280 -0
- data/lib/kingsman/hooks/activatable.rb +12 -0
- data/lib/kingsman/hooks/csrf_cleaner.rb +14 -0
- data/lib/kingsman/hooks/forgetable.rb +11 -0
- data/lib/kingsman/hooks/lockable.rb +9 -0
- data/lib/kingsman/hooks/proxy.rb +23 -0
- data/lib/kingsman/hooks/rememberable.rb +9 -0
- data/lib/kingsman/hooks/timeoutable.rb +35 -0
- data/lib/kingsman/hooks/trackable.rb +11 -0
- data/lib/kingsman/hooks.rb +6 -0
- data/lib/kingsman/jets/routes.rb +195 -0
- data/lib/kingsman/jets/warden_compat.rb +15 -0
- data/lib/kingsman/jets.rb +39 -0
- data/lib/kingsman/mailers/helpers.rb +93 -0
- data/lib/kingsman/mapping.rb +148 -0
- data/lib/kingsman/models/authenticatable.rb +310 -0
- data/lib/kingsman/models/confirmable.rb +369 -0
- data/lib/kingsman/models/database_authenticatable.rb +206 -0
- data/lib/kingsman/models/lockable.rb +214 -0
- data/lib/kingsman/models/omniauthable.rb +29 -0
- data/lib/kingsman/models/recoverable.rb +156 -0
- data/lib/kingsman/models/registerable.rb +29 -0
- data/lib/kingsman/models/rememberable.rb +158 -0
- data/lib/kingsman/models/timeoutable.rb +45 -0
- data/lib/kingsman/models/trackable.rb +51 -0
- data/lib/kingsman/models/validatable.rb +68 -0
- data/lib/kingsman/models.rb +122 -0
- data/lib/kingsman/modules.rb +33 -0
- data/lib/kingsman/omniauth/config.rb +47 -0
- data/lib/kingsman/omniauth/url_helpers.rb +28 -0
- data/lib/kingsman/omniauth.rb +20 -0
- data/lib/kingsman/orm/active_record.rb +13 -0
- data/lib/kingsman/orm/mongoid.rb +8 -0
- data/lib/kingsman/orm.rb +37 -0
- data/lib/kingsman/parameter_filter.rb +44 -0
- data/lib/kingsman/parameter_sanitizer.rb +173 -0
- data/lib/kingsman/secret_key_finder.rb +27 -0
- data/lib/kingsman/strategies/authenticatable.rb +178 -0
- data/lib/kingsman/strategies/base.rb +22 -0
- data/lib/kingsman/strategies/database_authenticatable.rb +31 -0
- data/lib/kingsman/strategies/rememberable.rb +67 -0
- data/lib/kingsman/token_generator.rb +32 -0
- data/lib/kingsman/version.rb +1 -1
- data/lib/kingsman.rb +427 -3
- metadata +304 -11
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
require 'generators/kingsman/orm_helpers'
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module Generators
|
8
|
+
class KingsmanGenerator < ActiveRecord::Generators::Base
|
9
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
10
|
+
|
11
|
+
class_option :primary_key_type, type: :string, desc: "The type for primary key"
|
12
|
+
|
13
|
+
include Kingsman::Generators::OrmHelpers
|
14
|
+
source_root File.expand_path("../templates", __FILE__)
|
15
|
+
|
16
|
+
def copy_kingsman_migration
|
17
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
18
|
+
migration_template "migration_existing.rb", "#{migration_path}/add_kingsman_to_#{table_name}.rb", migration_version: migration_version
|
19
|
+
else
|
20
|
+
migration_template "migration.rb", "#{migration_path}/kingsman_create_#{table_name}.rb", migration_version: migration_version
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_model
|
25
|
+
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
26
|
+
end
|
27
|
+
|
28
|
+
def inject_kingsman_content
|
29
|
+
content = model_contents
|
30
|
+
|
31
|
+
class_path = if namespaced?
|
32
|
+
class_name.to_s.split("::")
|
33
|
+
else
|
34
|
+
[class_name]
|
35
|
+
end
|
36
|
+
|
37
|
+
indent_depth = class_path.size - 1
|
38
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
39
|
+
|
40
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
41
|
+
end
|
42
|
+
|
43
|
+
def migration_data
|
44
|
+
<<RUBY
|
45
|
+
## Database authenticatable
|
46
|
+
t.string :email, null: false, default: ""
|
47
|
+
t.string :encrypted_password, null: false, default: ""
|
48
|
+
|
49
|
+
## Recoverable
|
50
|
+
t.string :reset_password_token
|
51
|
+
t.datetime :reset_password_sent_at
|
52
|
+
|
53
|
+
## Rememberable
|
54
|
+
t.datetime :remember_created_at
|
55
|
+
|
56
|
+
## Trackable
|
57
|
+
# t.integer :sign_in_count, default: 0, null: false
|
58
|
+
# t.datetime :current_sign_in_at
|
59
|
+
# t.datetime :last_sign_in_at
|
60
|
+
# t.#{ip_column} :current_sign_in_ip
|
61
|
+
# t.#{ip_column} :last_sign_in_ip
|
62
|
+
|
63
|
+
## Confirmable
|
64
|
+
# t.string :confirmation_token
|
65
|
+
# t.datetime :confirmed_at
|
66
|
+
# t.datetime :confirmation_sent_at
|
67
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
68
|
+
|
69
|
+
## Lockable
|
70
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
71
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
72
|
+
# t.datetime :locked_at
|
73
|
+
RUBY
|
74
|
+
end
|
75
|
+
|
76
|
+
def ip_column
|
77
|
+
# Padded with spaces so it aligns nicely with the rest of the columns.
|
78
|
+
"%-8s" % (inet? ? "inet" : "string")
|
79
|
+
end
|
80
|
+
|
81
|
+
def inet?
|
82
|
+
postgresql?
|
83
|
+
end
|
84
|
+
|
85
|
+
def rails5_and_up?
|
86
|
+
require "rails/gem_version"
|
87
|
+
Rails::VERSION::MAJOR >= 5
|
88
|
+
end
|
89
|
+
|
90
|
+
def rails61_and_up?
|
91
|
+
require "rails/gem_version"
|
92
|
+
Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)
|
93
|
+
end
|
94
|
+
|
95
|
+
def postgresql?
|
96
|
+
ar_config && ar_config['adapter'] == 'postgresql'
|
97
|
+
end
|
98
|
+
|
99
|
+
def ar_config
|
100
|
+
if ActiveRecord::Base.configurations.respond_to?(:configs_for)
|
101
|
+
if rails61_and_up?
|
102
|
+
ActiveRecord::Base.configurations.configs_for(env_name: Jets.env, name: "primary").configuration_hash
|
103
|
+
else
|
104
|
+
ActiveRecord::Base.configurations.configs_for(env_name: Jets.env, spec_name: "primary").config
|
105
|
+
end
|
106
|
+
else
|
107
|
+
ActiveRecord::Base.configurations[Jets.env]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def migration_version
|
112
|
+
if rails5_and_up?
|
113
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def primary_key_type
|
118
|
+
primary_key_string if rails5_and_up?
|
119
|
+
end
|
120
|
+
|
121
|
+
def primary_key_string
|
122
|
+
key_string = options[:primary_key_type]
|
123
|
+
", id: :#{key_string}" if key_string
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class KingsmanCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
4
|
+
def change
|
5
|
+
create_table :<%= table_name %><%= primary_key_type %> do |t|
|
6
|
+
<%= migration_data -%>
|
7
|
+
|
8
|
+
<% attributes.each do |attribute| -%>
|
9
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :<%= table_name %>, :email, unique: true
|
16
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
17
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
18
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddKingsmanTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
4
|
+
def self.up
|
5
|
+
change_table :<%= table_name %> do |t|
|
6
|
+
<%= migration_data -%>
|
7
|
+
|
8
|
+
<% attributes.each do |attribute| -%>
|
9
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
# Uncomment below if timestamps were not included in your original model.
|
13
|
+
# t.timestamps null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :<%= table_name %>, :email, unique: true
|
17
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
18
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
19
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
24
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
25
|
+
raise ActiveRecord::IrreversibleMigration
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module Kingsman
|
6
|
+
module Generators
|
7
|
+
class ControllersGenerator < Rails::Generators::Base
|
8
|
+
CONTROLLERS = %w(confirmations passwords registrations sessions unlocks omniauth_callbacks).freeze
|
9
|
+
|
10
|
+
desc <<-DESC.strip_heredoc
|
11
|
+
Create inherited Kingsman controllers in your app/controllers folder.
|
12
|
+
|
13
|
+
Use -c to specify which controller you want to overwrite.
|
14
|
+
If you do no specify a controller, all controllers will be created.
|
15
|
+
For example:
|
16
|
+
|
17
|
+
jets generate kingsman:controllers users -c=sessions
|
18
|
+
|
19
|
+
This will create a controller class at app/controllers/users/sessions_controller.rb like this:
|
20
|
+
|
21
|
+
class Users::SessionsController < Kingsman::SessionsController
|
22
|
+
content...
|
23
|
+
end
|
24
|
+
DESC
|
25
|
+
|
26
|
+
source_root File.expand_path("../../templates/controllers", __FILE__)
|
27
|
+
argument :scope, required: true,
|
28
|
+
desc: "The scope to create controllers in, e.g. users, admins"
|
29
|
+
class_option :controllers, aliases: "-c", type: :array,
|
30
|
+
desc: "Select specific controllers to generate (#{CONTROLLERS.join(', ')})"
|
31
|
+
|
32
|
+
def create_controllers
|
33
|
+
@scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
|
34
|
+
controllers = options[:controllers] || CONTROLLERS
|
35
|
+
controllers.each do |name|
|
36
|
+
template "#{name}_controller.rb",
|
37
|
+
"app/controllers/#{scope}/#{name}_controller.rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_readme
|
42
|
+
readme "README" if behavior == :invoke
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
module Kingsman
|
7
|
+
module Generators
|
8
|
+
MissingORMError = Class.new(Thor::Error)
|
9
|
+
|
10
|
+
class InstallGenerator < Rails::Generators::Base
|
11
|
+
source_root File.expand_path("../../templates", __FILE__)
|
12
|
+
|
13
|
+
desc "Creates a Kingsman initializer and copy locale files to your application."
|
14
|
+
class_option :orm, required: true
|
15
|
+
|
16
|
+
def copy_initializer
|
17
|
+
unless options[:orm]
|
18
|
+
raise MissingORMError, <<-ERROR.strip_heredoc
|
19
|
+
An ORM must be set to install Kingsman in your application.
|
20
|
+
|
21
|
+
Be sure to have an ORM like Active Record or Mongoid loaded in your
|
22
|
+
app or configure your own at `config/application.rb`.
|
23
|
+
|
24
|
+
config.generators do |g|
|
25
|
+
g.orm :your_orm_gem
|
26
|
+
end
|
27
|
+
ERROR
|
28
|
+
end
|
29
|
+
|
30
|
+
template "kingsman.rb", "config/initializers/kingsman.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_locale
|
34
|
+
copy_file "../../../config/locales/en.yml", "config/locales/kingsman.en.yml"
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_readme
|
38
|
+
readme "README" if behavior == :invoke
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/named_base'
|
4
|
+
|
5
|
+
module Kingsman
|
6
|
+
module Generators
|
7
|
+
class KingsmanGenerator < Rails::Generators::NamedBase
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
|
10
|
+
namespace "kingsman"
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
|
+
|
13
|
+
desc "Generates a model with the given NAME (if one does not exist) with kingsman " \
|
14
|
+
"configuration plus a migration file and kingsman routes."
|
15
|
+
|
16
|
+
hook_for :orm, required: true
|
17
|
+
|
18
|
+
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
19
|
+
|
20
|
+
def add_kingsman_routes
|
21
|
+
kingsman_route = "kingsman_for :#{plural_name}".dup
|
22
|
+
kingsman_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
|
23
|
+
kingsman_route << %Q(, skip: :all) unless options.routes?
|
24
|
+
route kingsman_route
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kingsman
|
4
|
+
module Generators
|
5
|
+
module OrmHelpers
|
6
|
+
def model_contents
|
7
|
+
buffer = <<-CONTENT
|
8
|
+
# Include default kingsman modules. Others available are:
|
9
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
10
|
+
kingsman :database_authenticatable, :registerable,
|
11
|
+
:recoverable, :rememberable, :validatable
|
12
|
+
|
13
|
+
CONTENT
|
14
|
+
buffer
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def model_exists?
|
20
|
+
File.exist?(File.join(destination_root, model_path))
|
21
|
+
end
|
22
|
+
|
23
|
+
def migration_exists?(table_name)
|
24
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_kingsman_to_#{table_name}.rb$/).first
|
25
|
+
end
|
26
|
+
|
27
|
+
def migration_path
|
28
|
+
if Jets.version >= '5.0.3'
|
29
|
+
db_migrate_path
|
30
|
+
else
|
31
|
+
@migration_path ||= File.join("db", "migrate")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def model_path
|
36
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module Kingsman
|
6
|
+
module Generators
|
7
|
+
# Include this module in your generator to generate Kingsman views.
|
8
|
+
# `copy_views` is the main method and by default copies all views
|
9
|
+
# with forms.
|
10
|
+
module ViewPathTemplates #:nodoc:
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
argument :scope, required: false, default: nil,
|
15
|
+
desc: "The scope to copy views to"
|
16
|
+
|
17
|
+
# Le sigh, ensure Thor won't handle opts as args
|
18
|
+
# It should be fixed in future Jets releases
|
19
|
+
class_option :form_builder, aliases: "-b"
|
20
|
+
class_option :markerb
|
21
|
+
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
|
22
|
+
|
23
|
+
public_task :copy_views
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_views
|
27
|
+
if options[:views]
|
28
|
+
options[:views].each do |directory|
|
29
|
+
view_directory directory.to_sym
|
30
|
+
end
|
31
|
+
else
|
32
|
+
view_directory :confirmations
|
33
|
+
view_directory :passwords
|
34
|
+
view_directory :registrations
|
35
|
+
view_directory :sessions
|
36
|
+
view_directory :unlocks
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def view_directory(name, _target_path = nil)
|
43
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
|
44
|
+
if scope
|
45
|
+
content.gsub("kingsman/shared", "#{plural_scope}/shared")
|
46
|
+
else
|
47
|
+
content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def target_path
|
53
|
+
@target_path ||= "app/views/#{plural_scope || :kingsman}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def plural_scope
|
57
|
+
@plural_scope ||= scope.presence && scope.underscore.pluralize
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
62
|
+
include ViewPathTemplates
|
63
|
+
source_root File.expand_path("../../../../app/views/kingsman", __FILE__)
|
64
|
+
desc "Copies shared Kingsman views to your application."
|
65
|
+
hide!
|
66
|
+
|
67
|
+
# Override copy_views to just copy mailer and shared.
|
68
|
+
def copy_views
|
69
|
+
view_directory :shared
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
74
|
+
include ViewPathTemplates
|
75
|
+
source_root File.expand_path("../../../../app/views/kingsman", __FILE__)
|
76
|
+
desc "Copies default Kingsman views to your application."
|
77
|
+
hide!
|
78
|
+
end
|
79
|
+
|
80
|
+
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
81
|
+
include ViewPathTemplates
|
82
|
+
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
83
|
+
desc "Copies simple form enabled views to your application."
|
84
|
+
hide!
|
85
|
+
|
86
|
+
def copy_views
|
87
|
+
if options[:views]
|
88
|
+
options[:views].delete('mailer')
|
89
|
+
end
|
90
|
+
super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
95
|
+
include ViewPathTemplates
|
96
|
+
source_root File.expand_path("../../../../app/views/kingsman", __FILE__)
|
97
|
+
desc "Copies Kingsman mail erb views to your application."
|
98
|
+
hide!
|
99
|
+
|
100
|
+
def copy_views
|
101
|
+
if !options[:views] || options[:views].include?('mailer')
|
102
|
+
view_directory :mailer
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
|
108
|
+
include ViewPathTemplates
|
109
|
+
source_root File.expand_path("../../templates", __FILE__)
|
110
|
+
desc "Copies Kingsman mail markerb views to your application."
|
111
|
+
hide!
|
112
|
+
|
113
|
+
def copy_views
|
114
|
+
if !options[:views] || options[:views].include?('mailer')
|
115
|
+
view_directory :markerb, target_path
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def target_path
|
120
|
+
"app/views/#{plural_scope || :kingsman}/mailer"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class ViewsGenerator < Rails::Generators::Base
|
125
|
+
desc "Copies Kingsman views to your application."
|
126
|
+
|
127
|
+
argument :scope, required: false, default: nil,
|
128
|
+
desc: "The scope to copy views to"
|
129
|
+
|
130
|
+
invoke SharedViewsGenerator
|
131
|
+
|
132
|
+
hook_for :form_builder, aliases: "-b",
|
133
|
+
desc: "Form builder to be used",
|
134
|
+
default: defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
135
|
+
|
136
|
+
hook_for :markerb, desc: "Generate markerb instead of erb mail views",
|
137
|
+
default: defined?(Markerb),
|
138
|
+
type: :boolean
|
139
|
+
|
140
|
+
hook_for :erb, desc: "Generate erb mail views",
|
141
|
+
default: !defined?(Markerb),
|
142
|
+
type: :boolean
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/named_base'
|
4
|
+
require 'generators/kingsman/orm_helpers'
|
5
|
+
|
6
|
+
module Mongoid
|
7
|
+
module Generators
|
8
|
+
class KingsmanGenerator < Rails::Generators::NamedBase
|
9
|
+
include Kingsman::Generators::OrmHelpers
|
10
|
+
|
11
|
+
def generate_model
|
12
|
+
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
def inject_field_types
|
16
|
+
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
|
17
|
+
end
|
18
|
+
|
19
|
+
def inject_kingsman_content
|
20
|
+
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
|
21
|
+
end
|
22
|
+
|
23
|
+
def migration_data
|
24
|
+
<<RUBY
|
25
|
+
## Database authenticatable
|
26
|
+
field :email, type: String, default: ""
|
27
|
+
field :encrypted_password, type: String, default: ""
|
28
|
+
|
29
|
+
## Recoverable
|
30
|
+
field :reset_password_token, type: String
|
31
|
+
field :reset_password_sent_at, type: Time
|
32
|
+
|
33
|
+
## Rememberable
|
34
|
+
field :remember_created_at, type: Time
|
35
|
+
|
36
|
+
## Trackable
|
37
|
+
# field :sign_in_count, type: Integer, default: 0
|
38
|
+
# field :current_sign_in_at, type: Time
|
39
|
+
# field :last_sign_in_at, type: Time
|
40
|
+
# field :current_sign_in_ip, type: String
|
41
|
+
# field :last_sign_in_ip, type: String
|
42
|
+
|
43
|
+
## Confirmable
|
44
|
+
# field :confirmation_token, type: String
|
45
|
+
# field :confirmed_at, type: Time
|
46
|
+
# field :confirmation_sent_at, type: Time
|
47
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
48
|
+
|
49
|
+
## Lockable
|
50
|
+
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
51
|
+
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
52
|
+
# field :locked_at, type: Time
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Depending on your application's configuration some manual setup may be required:
|
4
|
+
|
5
|
+
1. Ensure you have defined default url options in your environments files. Here
|
6
|
+
is an example of default_url_options appropriate for a development environment
|
7
|
+
in config/environments/development.rb:
|
8
|
+
|
9
|
+
config.action_mailer.default_url_options = { host: 'localhost', port: 8888 }
|
10
|
+
|
11
|
+
In production, :host should be set to the actual host of your application.
|
12
|
+
|
13
|
+
* Required for all applications. *
|
14
|
+
|
15
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb.
|
16
|
+
For example:
|
17
|
+
|
18
|
+
root to: "home#index"
|
19
|
+
|
20
|
+
* Not required for API-only Applications *
|
21
|
+
|
22
|
+
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
|
23
|
+
For example:
|
24
|
+
|
25
|
+
<p class="notice"><%= notice %></p>
|
26
|
+
<p class="alert"><%= alert %></p>
|
27
|
+
|
28
|
+
* Not required for API-only Applications *
|
29
|
+
|
30
|
+
4. You can copy Kingsman views (for customization) to your app by running:
|
31
|
+
|
32
|
+
jets generate kingsman:views
|
33
|
+
|
34
|
+
* Not required *
|
35
|
+
|
36
|
+
===============================================================================
|
@@ -0,0 +1,14 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
Ensure you have overridden routes for generated controllers in your routes.rb.
|
6
|
+
For example:
|
7
|
+
|
8
|
+
Jets.application.routes.draw do
|
9
|
+
kingsman_for :users, controllers: {
|
10
|
+
sessions: 'users/sessions'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
===============================================================================
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class <%= @scope_prefix %>ConfirmationsController < Kingsman::ConfirmationsController
|
4
|
+
# GET /resource/confirmation/new
|
5
|
+
# def new
|
6
|
+
# super
|
7
|
+
# end
|
8
|
+
|
9
|
+
# POST /resource/confirmation
|
10
|
+
# def create
|
11
|
+
# super
|
12
|
+
# end
|
13
|
+
|
14
|
+
# GET /resource/confirmation?confirmation_token=abcdef
|
15
|
+
# def show
|
16
|
+
# super
|
17
|
+
# end
|
18
|
+
|
19
|
+
# protected
|
20
|
+
|
21
|
+
# The path used after resending confirmation instructions.
|
22
|
+
# def after_resending_confirmation_instructions_path_for(resource_name)
|
23
|
+
# super(resource_name)
|
24
|
+
# end
|
25
|
+
|
26
|
+
# The path used after confirmation.
|
27
|
+
# def after_confirmation_path_for(resource_name, resource)
|
28
|
+
# super(resource_name, resource)
|
29
|
+
# end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class <%= @scope_prefix %>OmniauthCallbacksController < Kingsman::OmniauthCallbacksController
|
4
|
+
# You should configure your model like this:
|
5
|
+
# kingsman :omniauthable, omniauth_providers: [:twitter]
|
6
|
+
|
7
|
+
# You should also create an action method in this controller like this:
|
8
|
+
# def twitter
|
9
|
+
# end
|
10
|
+
|
11
|
+
# More info at:
|
12
|
+
# https://github.com/heartcombo/kingsman#omniauth
|
13
|
+
|
14
|
+
# GET|POST /resource/auth/twitter
|
15
|
+
# def passthru
|
16
|
+
# super
|
17
|
+
# end
|
18
|
+
|
19
|
+
# GET|POST /users/auth/twitter/callback
|
20
|
+
# def failure
|
21
|
+
# super
|
22
|
+
# end
|
23
|
+
|
24
|
+
# protected
|
25
|
+
|
26
|
+
# The path used when OmniAuth fails
|
27
|
+
# def after_omniauth_failure_path_for(scope)
|
28
|
+
# super(scope)
|
29
|
+
# end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class <%= @scope_prefix %>PasswordsController < Kingsman::PasswordsController
|
4
|
+
# GET /resource/password/new
|
5
|
+
# def new
|
6
|
+
# super
|
7
|
+
# end
|
8
|
+
|
9
|
+
# POST /resource/password
|
10
|
+
# def create
|
11
|
+
# super
|
12
|
+
# end
|
13
|
+
|
14
|
+
# GET /resource/password/edit?reset_password_token=abcdef
|
15
|
+
# def edit
|
16
|
+
# super
|
17
|
+
# end
|
18
|
+
|
19
|
+
# PUT /resource/password
|
20
|
+
# def update
|
21
|
+
# super
|
22
|
+
# end
|
23
|
+
|
24
|
+
# protected
|
25
|
+
|
26
|
+
# def after_resetting_password_path_for(resource)
|
27
|
+
# super(resource)
|
28
|
+
# end
|
29
|
+
|
30
|
+
# The path used after sending reset password instructions
|
31
|
+
# def after_sending_reset_password_instructions_path_for(resource_name)
|
32
|
+
# super(resource_name)
|
33
|
+
# end
|
34
|
+
end
|