genkan 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/Rakefile +11 -11
- data/app/controllers/concerns/genkan/authenticatable.rb +16 -16
- data/app/controllers/concerns/genkan/helper.rb +2 -1
- data/app/controllers/genkan/sessions_controller.rb +27 -26
- data/app/models/concerns/genkan/auth.rb +13 -13
- data/lib/generators/genkan/helper.rb +48 -48
- data/lib/generators/genkan/templates/initializer.erb +4 -3
- data/lib/genkan/config.rb +1 -1
- data/lib/genkan/engine.rb +1 -1
- data/lib/genkan/version.rb +1 -1
- data/spec/controllers/genkan/sessions_controller_spec.rb +14 -14
- data/spec/controllers/welcome_controller_spec.rb +4 -4
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/mailers/application_mailer.rb +2 -2
- data/spec/dummy/bin/bundle +2 -2
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +9 -10
- data/spec/dummy/bin/update +9 -9
- data/spec/dummy/bin/yarn +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +3 -3
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +2 -2
- data/spec/dummy/config/environments/production.rb +2 -2
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/assets.rb +2 -2
- data/spec/dummy/config/initializers/genkan.rb +5 -5
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/config/spring.rb +2 -2
- data/spec/dummy/db/schema.rb +1 -3
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +1029 -0
- data/spec/lib/genkan/config_spec.rb +15 -15
- data/spec/lib/genkan_spec.rb +4 -4
- data/spec/models/user_spec.rb +47 -46
- data/spec/rails_helper.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c307f7abb2b38ee3287f779669caea8f91e82c4b
|
4
|
+
data.tar.gz: b9a3e6ecff992de2c1f0ab7ddcaf587dbe7bc669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d61ee0cf2c60f858cf557bd6fba6a4f9a3f6fd45fc76e6f5fe7b88f2b7f5a2e80c0afbeac925ee9925ddff0cb7a324ed99583c75bd38cd7bef0dd82473b85c90
|
7
|
+
data.tar.gz: 7d9a8b435dd182b2b56508433f55f13a921f12ef005162d7e9ae7e0511e50e5ecb48a6c6b02d4e8cb8dbb62a44c894cf8725227b65b9b9445174ef8a7af94c93
|
data/README.md
CHANGED
@@ -56,9 +56,10 @@ Some setup you must do manually if you haven't yet:
|
|
56
56
|
ENV['GOOGLE_OAUTH_CLIENT_ID'],
|
57
57
|
ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
|
58
58
|
{
|
59
|
-
name:
|
60
|
-
scope:
|
61
|
-
hd:
|
59
|
+
name: 'google',
|
60
|
+
scope: 'email',
|
61
|
+
hd: 'host-domain.com',
|
62
|
+
verify_iss: false,
|
62
63
|
}
|
63
64
|
)
|
64
65
|
end
|
data/Rakefile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "bundler/setup"
|
3
3
|
rescue LoadError
|
4
|
-
puts
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "rdoc/task"
|
8
8
|
|
9
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title =
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "Genkan"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.md")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
15
|
end
|
16
16
|
|
17
17
|
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
-
load
|
18
|
+
load "rails/tasks/engine.rake"
|
19
19
|
|
20
|
-
load
|
20
|
+
load "rails/tasks/statistics.rake"
|
21
21
|
|
22
|
-
require
|
22
|
+
require "bundler/gem_tasks"
|
23
23
|
require "rspec/core/rake_task"
|
24
24
|
RSpec::Core::RakeTask.new(:spec)
|
25
25
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Genkan
|
2
|
-
|
2
|
+
module Authenticatable
|
3
3
|
include Genkan::Helper
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
@@ -10,24 +10,24 @@ module Genkan
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def authenticate
|
14
|
+
unless logged_in?
|
15
|
+
store_location
|
16
|
+
redirect_to genkan.login_path, notice: t("genkan.sessions.required")
|
17
|
+
end
|
17
18
|
end
|
18
|
-
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
define_method(current_user_method_name) do
|
21
|
+
instance_variable_get(:"@#{current_user_method_name}") || \
|
22
|
+
instance_variable_set(:"@#{current_user_method_name}", user_class.active.find_by(remember_token: session[:remember_token]))
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def logged_in?
|
26
|
+
send(current_user_method_name).present?
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def store_location
|
30
|
+
session[:referer] = request.fullpath
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
@@ -6,53 +6,54 @@ module Genkan
|
|
6
6
|
redirect_to genkan.login_path, alert: user.errors.full_messages.to_sentence
|
7
7
|
end
|
8
8
|
|
9
|
-
skip_before_action :authenticate, only: %i
|
9
|
+
skip_before_action :authenticate, only: %i[new create failure]
|
10
10
|
|
11
|
-
def new
|
11
|
+
def new
|
12
|
+
end
|
12
13
|
|
13
14
|
def create
|
14
15
|
user.login!
|
15
16
|
create_session
|
16
17
|
create_encrypted_cookie
|
17
|
-
redirect_to referer_or_root_path, notice: t(
|
18
|
+
redirect_to referer_or_root_path, notice: t("genkan.sessions.logged_in")
|
18
19
|
end
|
19
20
|
|
20
21
|
def failure
|
21
|
-
redirect_to genkan.login_path, alert: t(
|
22
|
+
redirect_to genkan.login_path, alert: t("genkan.sessions.failure")
|
22
23
|
end
|
23
24
|
|
24
25
|
def destroy
|
25
26
|
destroy_session
|
26
|
-
redirect_to genkan.login_path, notice: t(
|
27
|
+
redirect_to genkan.login_path, notice: t("genkan.sessions.logged_out")
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def user
|
33
|
+
@user ||= user_class.find_or_create_by(email: auth.dig(:info, :email))
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def auth
|
37
|
+
request.env["omniauth.auth"]
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def create_session
|
41
|
+
session[:remember_token] = user.remember_token
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def create_encrypted_cookie
|
45
|
+
cookies.encrypted[:remember_token] = {
|
46
|
+
value: user.remember_token,
|
47
|
+
expires: Time.current.since(Genkan.config.cookie_expiration),
|
48
|
+
}
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def destroy_session
|
52
|
+
session[:remember_token] = nil
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def referer_or_root_path
|
56
|
+
session.delete(:referer) || main_app.root_path
|
57
|
+
end
|
57
58
|
end
|
58
59
|
end
|
@@ -58,21 +58,21 @@ module Genkan
|
|
58
58
|
|
59
59
|
private
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
def store_last_logged_in_at
|
62
|
+
self.last_logged_in_at = Time.current
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
def increment_logged_in_count
|
66
|
+
self.logged_in_count ||= 0
|
67
|
+
self.logged_in_count += 1
|
68
|
+
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
def ensure_record_has_accepted
|
71
|
+
errors.add(:base, :not_accepted) unless accepted?
|
72
|
+
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
def ensure_record_has_not_banned
|
75
|
+
errors.add(:base, :banned) if banned?
|
76
|
+
end
|
77
77
|
end
|
78
78
|
end
|
@@ -5,57 +5,57 @@ module Genkan
|
|
5
5
|
|
6
6
|
private
|
7
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
|
-
else
|
36
|
-
[model_class_name]
|
37
|
-
end.join("::")
|
38
|
-
end
|
39
|
-
|
40
|
-
def migration_class_name
|
41
|
-
if Rails::VERSION::MAJOR >= 5
|
42
|
-
"ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
43
|
-
else
|
44
|
-
"ActiveRecord::Migration"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class_methods do
|
49
|
-
# Define the next_migration_number method (necessary for the migration_template method to work)
|
50
|
-
def next_migration_number(dirname)
|
51
|
-
if ActiveRecord::Base.timestamped_migrations
|
52
|
-
sleep 1 # make sure each time we get a different timestamp
|
53
|
-
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
8
|
+
def model_class_name
|
9
|
+
options.has_key?(:model) ? options[:model].classify : "User"
|
10
|
+
end
|
11
|
+
|
12
|
+
def model_file_path
|
13
|
+
model_name.underscore
|
14
|
+
end
|
15
|
+
|
16
|
+
def model_path
|
17
|
+
@model_path ||= File.join("app", "models", "#{model_file_path}.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
def namespace
|
21
|
+
Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace)
|
22
|
+
end
|
23
|
+
|
24
|
+
def namespaced?
|
25
|
+
!!namespace
|
26
|
+
end
|
27
|
+
|
28
|
+
def table_name_prefix
|
29
|
+
model_class_name.to_s.split("::")[0..-2].join("_").underscore.presence
|
30
|
+
end
|
31
|
+
|
32
|
+
def model_name
|
33
|
+
if namespaced?
|
34
|
+
[namespace.to_s] + [model_class_name]
|
54
35
|
else
|
55
|
-
|
36
|
+
[model_class_name]
|
37
|
+
end.join("::")
|
38
|
+
end
|
39
|
+
|
40
|
+
def migration_class_name
|
41
|
+
if Rails::VERSION::MAJOR >= 5
|
42
|
+
"ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
43
|
+
else
|
44
|
+
"ActiveRecord::Migration"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class_methods do
|
49
|
+
# Define the next_migration_number method (necessary for the migration_template method to work)
|
50
|
+
def next_migration_number(dirname)
|
51
|
+
if ActiveRecord::Base.timestamped_migrations
|
52
|
+
sleep 1 # make sure each time we get a different timestamp
|
53
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
54
|
+
else
|
55
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
56
|
+
end
|
56
57
|
end
|
57
58
|
end
|
58
|
-
end
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -13,9 +13,10 @@ Genkan::Engine.configure do |config|
|
|
13
13
|
# ENV['GOOGLE_OAUTH_CLIENT_ID'],
|
14
14
|
# ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
|
15
15
|
# {
|
16
|
-
# name:
|
17
|
-
# scope:
|
18
|
-
# hd:
|
16
|
+
# name: 'google',
|
17
|
+
# scope: 'email',
|
18
|
+
# hd: 'host-domain.com',
|
19
|
+
# verify_iss: false
|
19
20
|
# }
|
20
21
|
# )
|
21
22
|
# end
|
data/lib/genkan/config.rb
CHANGED
@@ -13,7 +13,7 @@ module Genkan
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def current_user_method_name
|
16
|
-
@current_user_method_name ||= "current_#{user_class_name.underscore.tr(
|
16
|
+
@current_user_method_name ||= "current_#{user_class_name.underscore.tr("/", "_")}".freeze
|
17
17
|
end
|
18
18
|
|
19
19
|
def auto_acceptance?
|
data/lib/genkan/engine.rb
CHANGED
data/lib/genkan/version.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
require
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
RSpec.describe Genkan::SessionsController do
|
4
4
|
routes { Genkan::Engine.routes }
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_omniauth
|
8
|
-
request.env[
|
8
|
+
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
11
|
+
describe "GET #new" do
|
12
12
|
before { get :new }
|
13
13
|
it { expect(response).to have_http_status(200) }
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe "POST #create" do
|
17
17
|
subject(:execution) { post :create, params: { provider: :google } }
|
18
18
|
|
19
|
-
context
|
19
|
+
context "when auto_acceptance is true" do
|
20
20
|
before { allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(true) }
|
21
21
|
|
22
|
-
it
|
22
|
+
it "creates a user" do
|
23
23
|
expect { execution }.to change { User.count }.by(1)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it "creates a session" do
|
27
27
|
expect(session[:remember_token]).to be_nil
|
28
28
|
execution
|
29
29
|
expect(session[:remember_token]).to be_present
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it "redirects root_path" do
|
33
33
|
execution
|
34
34
|
expect(response).to have_http_status(302)
|
35
35
|
expect(response).to redirect_to(Dummy::Application.routes.url_helpers.root_path)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
context
|
39
|
+
context "when auto_acceptance is false" do
|
40
40
|
before { allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(false) }
|
41
41
|
|
42
|
-
it
|
42
|
+
it "creates a user" do
|
43
43
|
expect { execution }.to change { User.count }.by(1)
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it "redirects login_path" do
|
47
47
|
execution
|
48
48
|
expect(response).to have_http_status(302)
|
49
49
|
expect(response).to redirect_to(login_path)
|
@@ -51,7 +51,7 @@ RSpec.describe Genkan::SessionsController do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe "GET #destroy" do
|
55
55
|
before do
|
56
56
|
allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(true)
|
57
57
|
post :create, params: { provider: :google }
|
@@ -59,13 +59,13 @@ RSpec.describe Genkan::SessionsController do
|
|
59
59
|
|
60
60
|
subject(:execution) { get :destroy }
|
61
61
|
|
62
|
-
it
|
62
|
+
it "destroys a session" do
|
63
63
|
expect(session[:remember_token]).to be_present
|
64
64
|
execution
|
65
65
|
expect(session[:remember_token]).to be_nil
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it "redirects login_path" do
|
69
69
|
execution
|
70
70
|
expect(response).to have_http_status(302)
|
71
71
|
expect(response).to redirect_to(login_path)
|