mtdevise 3.8.4 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +2 -2
- data/README.md +16 -14
- data/Rakefile +12 -11
- data/app/extenders/controllers/application_controller_extender.rb +5 -5
- data/app/extenders/mtdevise/constraints/subdomain_required.rb +12 -0
- data/app/helpers/mtdevise/application_helper.rb +23 -23
- data/app/mailers/mtdevise/application_mailer.rb +2 -0
- data/app/models/concerns/mtdevise/user_storage.rb +11 -11
- data/app/models/mtdevise/account.rb +46 -46
- data/app/models/mtdevise/application_record.rb +3 -3
- data/app/models/mtdevise/member.rb +7 -7
- data/app/models/mtdevise/user.rb +17 -17
- data/config/initializers/assets.rb +1 -10
- data/config/initializers/devise.rb +274 -274
- data/config/initializers/devise/strategies/subdomain.rb +21 -20
- data/db/migrate/20150426071228_create_mtdevise_accounts.rb +9 -7
- data/db/migrate/20150426115631_add_owner_id_to_mtdevise_accounts.rb +6 -4
- data/db/migrate/20150426115910_create_mtdevise_users.rb +10 -8
- data/db/migrate/20150426143800_add_devise_to_mtdevise_users.rb +48 -46
- data/db/migrate/20150427200506_add_subdomain_to_mtdevise_accounts.rb +7 -5
- data/db/migrate/20150428110406_create_mtdevise_members.rb +10 -8
- data/db/migrate/20150504181830_add_confirmed_at_to_users.rb +9 -7
- data/db/migrate/20150719125100_add_authentication_token_to_mtdevise_users.rb +7 -5
- data/db/migrate/20151231043439_add_firstname_to_mtdevise_accounts.rb +8 -6
- data/lib/generators/mtdevise/views_generator.rb +57 -56
- data/lib/mtdevise.rb +0 -1
- data/lib/mtdevise/active_record_extensions.rb +12 -12
- data/lib/mtdevise/engine.rb +33 -31
- data/lib/mtdevise/scoped_to.rb +6 -6
- data/lib/mtdevise/version.rb +1 -1
- data/lib/templates/erb/scaffold/_form.html.erb +5 -3
- metadata +22 -40
- data/app/assets/mtdevise/constraints/subdomain_required.rb +0 -12
@@ -1,25 +1,26 @@
|
|
1
1
|
require 'devise/strategies/authenticatable'
|
2
2
|
|
3
3
|
module Devise
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
module Strategies
|
5
|
+
class SubdomainLogin < Authenticatable
|
6
|
+
|
7
|
+
def subdomain
|
8
|
+
request.subdomain
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
subdomain.present? && params["user"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def authenticate!
|
16
|
+
return fail!('Invalid email or password.') unless account = Mtdevise::Account.find_by(subdomain: subdomain)
|
17
|
+
return fail!('Invalid email or password.') unless user = account.users.find_by(email: params["user"]["email"])
|
18
|
+
return fail!('Invalid email or password.') unless user.valid_password?(params["user"]["password"])
|
19
|
+
success! user
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
24
|
end
|
25
|
+
|
25
26
|
Warden::Strategies.add(:subdomain_login, Devise::Strategies::SubdomainLogin)
|
@@ -1,9 +1,11 @@
|
|
1
1
|
class CreateMtdeviseAccounts < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
t.string :name
|
2
|
+
def change
|
3
|
+
create_table :mtdevise_accounts do |t|
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
t.string :name
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class CreateMtdeviseUsers < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
t.string :email
|
5
|
-
t.string :password_digest
|
2
|
+
def change
|
3
|
+
create_table :mtdevise_users do |t|
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
t.string :email
|
6
|
+
t.string :password_digest
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,49 +1,51 @@
|
|
1
1
|
class AddDeviseToMtdeviseUsers < ActiveRecord::Migration[5.0]
|
2
|
-
def self.up
|
3
|
-
change_table(:mtdevise_users) do |t|
|
4
|
-
## Database authenticatable
|
5
|
-
t.string :encrypted_password, null: false, default: ""
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
def self.up
|
4
|
+
change_table(:mtdevise_users) do |t|
|
5
|
+
## Database authenticatable
|
6
|
+
t.string :encrypted_password, null: false, default: ""
|
7
|
+
|
8
|
+
## Recoverable
|
9
|
+
t.string :reset_password_token
|
10
|
+
t.datetime :reset_password_sent_at
|
11
|
+
|
12
|
+
## Rememberable
|
13
|
+
t.datetime :remember_created_at
|
14
|
+
|
15
|
+
## Trackable
|
16
|
+
t.integer :sign_in_count, default: 0, null: false
|
17
|
+
t.datetime :current_sign_in_at
|
18
|
+
t.datetime :last_sign_in_at
|
19
|
+
t.string :current_sign_in_ip
|
20
|
+
t.string :last_sign_in_ip
|
21
|
+
|
22
|
+
## Confirmable
|
23
|
+
# t.string :confirmation_token
|
24
|
+
# t.datetime :confirmed_at
|
25
|
+
# t.datetime :confirmation_sent_at
|
26
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
27
|
+
|
28
|
+
## Lockable
|
29
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
30
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
31
|
+
# t.datetime :locked_at
|
32
|
+
|
33
|
+
|
34
|
+
# Uncomment below if timestamps were not included in your original model.
|
35
|
+
# t.timestamps null: false
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index :mtdevise_users, :email, unique: true
|
39
|
+
add_index :mtdevise_users, :reset_password_token, unique: true
|
40
|
+
# add_index :mtdevise_users, :confirmation_token, unique: true
|
41
|
+
# add_index :mtdevise_users, :unlock_token, unique: true
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.down
|
45
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
46
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
47
|
+
raise ActiveRecord::IrreversibleMigration
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
10
51
|
|
11
|
-
## Rememberable
|
12
|
-
t.datetime :remember_created_at
|
13
|
-
|
14
|
-
## Trackable
|
15
|
-
t.integer :sign_in_count, default: 0, null: false
|
16
|
-
t.datetime :current_sign_in_at
|
17
|
-
t.datetime :last_sign_in_at
|
18
|
-
t.string :current_sign_in_ip
|
19
|
-
t.string :last_sign_in_ip
|
20
|
-
|
21
|
-
## Confirmable
|
22
|
-
# t.string :confirmation_token
|
23
|
-
# t.datetime :confirmed_at
|
24
|
-
# t.datetime :confirmation_sent_at
|
25
|
-
# t.string :unconfirmed_email # Only if using reconfirmable
|
26
|
-
|
27
|
-
## Lockable
|
28
|
-
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
29
|
-
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
30
|
-
# t.datetime :locked_at
|
31
|
-
|
32
|
-
|
33
|
-
# Uncomment below if timestamps were not included in your original model.
|
34
|
-
# t.timestamps null: false
|
35
|
-
end
|
36
|
-
|
37
|
-
add_index :mtdevise_users, :email, unique: true
|
38
|
-
add_index :mtdevise_users, :reset_password_token, unique: true
|
39
|
-
# add_index :mtdevise_users, :confirmation_token, unique: true
|
40
|
-
# add_index :mtdevise_users, :unlock_token, unique: true
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.down
|
44
|
-
# By default, we don't want to make any assumption about how to roll back a migration when your
|
45
|
-
# model already existed. Please edit below which fields you would like to remove in this migration.
|
46
|
-
raise ActiveRecord::IrreversibleMigration
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class AddSubdomainToMtdeviseAccounts < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
def change
|
3
|
+
|
4
|
+
add_column :mtdevise_accounts, :subdomain, :string
|
5
|
+
add_index :mtdevise_accounts, :subdomain
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class CreateMtdeviseMembers < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def change
|
3
|
+
create_table :mtdevise_members do |t|
|
4
|
+
|
5
|
+
t.integer :account_id
|
6
|
+
t.integer :user_id
|
7
|
+
|
8
|
+
t.timestamps
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class AddConfirmedAtToUsers < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
def change
|
3
|
+
|
4
|
+
add_column :mtdevise_users, :confirmed_at, :timestamp
|
5
|
+
add_column :mtdevise_users, :confirmation_token, :string
|
6
|
+
add_column :mtdevise_users, :confirmation_sent_at, :timestamp
|
7
|
+
add_column :mtdevise_users, :unconfirmed_email, :string
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class AddAuthenticationTokenToMtdeviseUsers < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
def change
|
3
|
+
|
4
|
+
add_column :mtdevise_users, :authentication_token, :string
|
5
|
+
add_index :mtdevise_users, :authentication_token
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class AddFirstnameToMtdeviseAccounts < ActiveRecord::Migration[5.0]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
def change
|
3
|
+
|
4
|
+
add_column :mtdevise_accounts, :firstname, :string
|
5
|
+
add_column :mtdevise_accounts, :lastname, :string
|
6
|
+
add_column :mtdevise_accounts, :username, :string
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
@@ -1,59 +1,60 @@
|
|
1
1
|
require 'rails/generators/base'
|
2
2
|
|
3
3
|
module Mtdevise
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
module ViewPathTemplates
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (devise, layouts, mtdevise)"
|
11
|
+
public_task :copy_views
|
12
|
+
end
|
13
|
+
|
14
|
+
# module ClassMethods
|
15
|
+
# def hide!
|
16
|
+
# Rails::Generators.hide_namespace self.namespace
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
def copy_views
|
21
|
+
if options[:views]
|
22
|
+
options[:views].each do |directory|
|
23
|
+
view_directory directory.to_sym
|
24
|
+
end
|
25
|
+
else
|
26
|
+
view_directory :devise
|
27
|
+
view_directory :layouts
|
28
|
+
view_directory :shared
|
29
|
+
view_directory :mtdevise
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def view_directory(name, _target_path = nil)
|
36
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
|
37
|
+
content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def target_path
|
42
|
+
@target_path ||= "app/views"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class SharedViewsGenerator < Rails::Generators::Base
|
48
|
+
include ViewPathTemplates
|
49
|
+
source_root File.expand_path("../../../../app/views", __FILE__)
|
50
|
+
desc "Copies Mtdevise views to your application."
|
51
|
+
hide!
|
52
|
+
end
|
53
|
+
|
54
|
+
class ViewsGenerator < Rails::Generators::Base
|
55
|
+
desc "Copies Mtdevise views to your application."
|
56
|
+
invoke SharedViewsGenerator
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/mtdevise.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
ActiveRecord::Base.class_eval do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def self.scoped_to_account
|
4
|
+
belongs_to :account, :class_name => "Mtdevise::Account"
|
5
|
+
association_name = self.to_s.downcase.pluralize
|
6
|
+
Mtdevise::Account.has_many association_name.to_sym, :class_name => self.to_s
|
7
|
+
|
8
|
+
instance_eval <<-HERE
|
9
|
+
def scoped_to(account)
|
10
|
+
where(:account_id => account.id)
|
11
|
+
end
|
12
|
+
HERE
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
def scoped_to(account)
|
10
|
-
where(:account_id => account.id)
|
11
|
-
end
|
12
|
-
HERE
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
15
|
+
end
|
data/lib/mtdevise/engine.rb
CHANGED
@@ -15,37 +15,39 @@ require 'font-awesome-rails'
|
|
15
15
|
require 'gravtastic'
|
16
16
|
require 'phctitleseo'
|
17
17
|
require 'phcnotifi'
|
18
|
-
|
19
|
-
module Mtdevise
|
20
|
-
class Engine < ::Rails::Engine
|
21
|
-
|
22
|
-
#Isolate Name
|
23
|
-
isolate_namespace Mtdevise
|
24
|
-
|
25
|
-
# Houser Gem
|
26
|
-
initializer 'mtdevise.middleware.houser' do
|
27
|
-
Rails.application.config.middleware.use Houser::Middleware, :class_name => 'Mtdevise::Account'
|
28
|
-
end
|
29
|
-
|
30
|
-
# Testing and Rspec
|
31
|
-
config.generators do |g|
|
32
|
-
g.test_framework :rspec, :view_specs => false
|
33
|
-
end
|
34
18
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
19
|
+
module Mtdevise
|
20
|
+
class Engine < ::Rails::Engine
|
21
|
+
|
22
|
+
#Isolate Name
|
23
|
+
isolate_namespace Mtdevise
|
24
|
+
|
25
|
+
# Houser Gem
|
26
|
+
initializer 'mtdevise.middleware.houser' do
|
27
|
+
Rails.application.config.middleware.use Houser::Middleware, :class_name => 'Mtdevise::Account'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Testing and Rspec
|
31
|
+
config.generators do |g|
|
32
|
+
g.test_framework :rspec, :view_specs => false
|
33
|
+
end
|
34
|
+
|
35
|
+
config.to_prepare do
|
36
|
+
root = Mtdevise::Engine.root
|
37
|
+
extenders_path = root + "app/extenders/**/*.rb"
|
38
|
+
Dir.glob(extenders_path) do |file|
|
39
|
+
Rails.configuration.cache_classes ? require(file) : load(file)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Load Helper Files
|
44
|
+
config.to_prepare do
|
45
|
+
ApplicationController.helper(ApplicationHelper)
|
46
|
+
Phcnotifi::ApplicationController.helper(ApplicationHelper)
|
47
|
+
Phctitleseo::ApplicationController.helper(ApplicationHelper)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
42
52
|
|
43
|
-
# Load Helper Files
|
44
|
-
config.to_prepare do
|
45
|
-
ApplicationController.helper(ApplicationHelper)
|
46
|
-
Phcnotifi::ApplicationController.helper(ApplicationHelper)
|
47
|
-
Phctitleseo::ApplicationController.helper(ApplicationHelper)
|
48
|
-
end
|
49
53
|
|
50
|
-
end
|
51
|
-
end
|