minimum-omniauth-scaffold 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/minimum/omniauth/scaffold.rb +68 -70
- data/lib/minimum/omniauth/scaffold/templates/controllers/application_controller.rb +2 -2
- data/lib/minimum/omniauth/scaffold/templates/controllers/sessions_controller.rb +2 -2
- data/lib/minimum/omniauth/scaffold/templates/controllers/top_controller.rb +1 -1
- data/lib/minimum/omniauth/scaffold/templates/migrate/create_users.rb +1 -0
- data/lib/minimum/omniauth/scaffold/templates/models/user.rb +2 -1
- data/lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.haml +2 -0
- data/lib/minimum/omniauth/scaffold/templates/views/application.html.haml +40 -0
- data/lib/minimum/omniauth/scaffold/templates/views/index.html.haml +1 -0
- data/lib/minimum/omniauth/scaffold/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95c5062c1e0686de1fd6c70f74cb5f7f64f940fe
|
4
|
+
data.tar.gz: c406d7a6cf6faf23f6365dd7cc4502f4158610d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4643d4474da688ac6fb31a83351763124e81a3fb51eb377d718a4d29c282c4280e5e16cb437dbe9ccfdbd7285b39acb8b1c9e1156198d068d3cc2cf5e464a53
|
7
|
+
data.tar.gz: 6ec0c22bb2837e778dd1ecb524b7c2007a4bb0e9f03426913241687986435c6a071b9436ee6432b90dc87332e8ecb0276d4d080ce4ae8fa3fa6fbbcf3bc864bb
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ rails g minimum:omniauth:scaffold
|
|
65
65
|
rake db:migrate
|
66
66
|
```
|
67
67
|
|
68
|
-
###
|
68
|
+
### 開発用キー作成
|
69
69
|
|
70
70
|
* Twitter
|
71
71
|
* [Create an application | Twitter Developers](https://dev.twitter.com/apps/new)
|
@@ -97,6 +97,8 @@ github_secret: "Client Secret"
|
|
97
97
|
|
98
98
|
## Heroku環境変数設定
|
99
99
|
|
100
|
+
※Production用キーを別途作成
|
101
|
+
|
100
102
|
* Twitter
|
101
103
|
|
102
104
|
```
|
@@ -10,86 +10,84 @@ require 'awesome_print'
|
|
10
10
|
module Minimum
|
11
11
|
module Omniauth
|
12
12
|
class ScaffoldGenerator < Rails::Generators::Base
|
13
|
-
@@template_path = source_root File.expand_path(
|
13
|
+
@@template_path = source_root File.expand_path("../scaffold/templates", __FILE__)
|
14
14
|
|
15
15
|
def generate_scaffold
|
16
16
|
app_name = Rails.application.class.name.split('::').first
|
17
17
|
|
18
|
-
|
19
|
-
copy_file
|
20
|
-
copy_file
|
21
|
-
copy_file
|
22
|
-
copy_file
|
23
|
-
copy_file
|
24
|
-
copy_file
|
18
|
+
## rails_config
|
19
|
+
copy_file "#{@@template_path}/rails_config/rails_config.rb", "config/initializers/rails_config.rb"
|
20
|
+
copy_file "#{@@template_path}/rails_config/settings.yml", "config/settings.yml"
|
21
|
+
copy_file "#{@@template_path}/rails_config/settings.local.yml", "config/settings.local.yml"
|
22
|
+
copy_file "#{@@template_path}/rails_config/development.yml", "config/settings/development.yml"
|
23
|
+
copy_file "#{@@template_path}/rails_config/production.yml", "config/settings/production.yml"
|
24
|
+
copy_file "#{@@template_path}/rails_config/test.yml", "config/settings/test.yml"
|
25
25
|
|
26
|
-
|
27
|
-
copy_file
|
26
|
+
## omniauth
|
27
|
+
copy_file "#{@@template_path}/initializers/omniauth.rb", "config/initializers/omniauth.rb"
|
28
28
|
|
29
|
-
|
29
|
+
## routes.rb
|
30
30
|
content = "\n # For OmniAuth\n"
|
31
31
|
content += " get \"/auth/:provider/callback\" => \"sessions#callback\"\n"
|
32
32
|
content += " get \"/auth/failure\" => \"sessions#failure\"\n"
|
33
33
|
content += " get \"/logout\" => \"sessions#destroy\", as: :logout\n"
|
34
34
|
content += "\n"
|
35
|
-
insert_into_file
|
36
|
-
insert_into_file
|
37
|
-
|
38
|
-
#
|
39
|
-
content = " config.time_zone = 'Tokyo'\n"
|
40
|
-
#
|
41
|
-
insert_into_file( "config/application.rb",
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
content
|
46
|
-
|
47
|
-
|
48
|
-
insert_into_file( "config/
|
49
|
-
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
copy_file
|
70
|
-
copy_file
|
71
|
-
|
72
|
-
|
73
|
-
content = File.read( "#{@@template_path}/
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
# ----- .gitignore ----- #
|
35
|
+
insert_into_file "config/routes.rb", content.force_encoding('ASCII-8BIT'), after: "Rails.application.routes.draw do\n"
|
36
|
+
insert_into_file "config/routes.rb", " root to: 'top#index'\n", after: "Rails.application.routes.draw do\n"
|
37
|
+
|
38
|
+
# ## application.rb
|
39
|
+
# content = " config.time_zone = 'Tokyo'\n"
|
40
|
+
# insert_into_file( "config/application.rb", content.force_encoding('ASCII-8BIT'), after: "# config.time_zone = 'Central Time (US & Canada)'\n" )
|
41
|
+
# insert_into_file( "config/application.rb", " config.i18n.default_locale = :ja\nI18n.enforce_available_locales = true\n", after: "# config.i18n.default_locale = :de\n" )
|
42
|
+
# content = " # For Tapp\n"
|
43
|
+
# content += " Tapp.config.default_printer = :awesome_print\n"
|
44
|
+
# content += "\n"
|
45
|
+
# insert_into_file( "config/application.rb", content.force_encoding('ASCII-8BIT'), after: "class Application < Rails::Application\n" )
|
46
|
+
|
47
|
+
# ## production.rb
|
48
|
+
# insert_into_file( "config/environments/production.rb", " config.force_ssl = true\n", after: "# config.force_ssl = true\n" ) # 強制SSL設定
|
49
|
+
|
50
|
+
# ## development.rb
|
51
|
+
# gsub_file "config/environments/development.rb", /(config.assets.debug = true)+/, "# config.assets.debug = true" # コメントアウト追加
|
52
|
+
# insert_into_file( "config/environments/development.rb", " config.assets.debug = false\n", after: "config.assets.debug = true\n" ) # false設定追加
|
53
|
+
|
54
|
+
## ja.yml
|
55
|
+
copy_file "#{@@template_path}/locales/ja.yml", "config/locales/ja.yml"
|
56
|
+
copy_file "#{@@template_path}/locales/translation_ja.yml", "config/locales/translation_ja.yml"
|
57
|
+
|
58
|
+
## migration
|
59
|
+
copy_file "#{@@template_path}/migrate/create_users.rb", "db/migrate/20000101000000_create_users.rb"
|
60
|
+
copy_file "#{@@template_path}/migrate/create_authentications.rb", "db/migrate/20000102000000_create_authentications.rb"
|
61
|
+
|
62
|
+
## models
|
63
|
+
copy_file "#{@@template_path}/models/user.rb", "app/models/user.rb"
|
64
|
+
copy_file "#{@@template_path}/models/authentication.rb", "app/models/authentication.rb"
|
65
|
+
|
66
|
+
## controllers
|
67
|
+
content = File.read("#{@@template_path}/controllers/application_controller.rb", encoding: Encoding::UTF_8)
|
68
|
+
insert_into_file "app/controllers/application_controller.rb", content.force_encoding('ASCII-8BIT'), after: "protect_from_forgery with: :exception\n"
|
69
|
+
copy_file "#{@@template_path}/controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb"
|
70
|
+
copy_file "#{@@template_path}/controllers/top_controller.rb", "app/controllers/top_controller.rb"
|
71
|
+
|
72
|
+
## views
|
73
|
+
# content = File.read( "#{@@template_path}/views/application.html.erb", encoding: Encoding::UTF_8 )
|
74
|
+
# gsub_file "app/views/layouts/application.html.erb", /(<%= yield %>)+/, content.force_encoding('ASCII-8BIT')
|
75
|
+
# gsub_file "app/views/layouts/application.html.erb", Regexp.new("<title>#{app_name}</title>"), "<title><%= Settings.app_name %></title>"
|
76
|
+
|
77
|
+
# copy_file 'app/views/layouts/application.html.erb', 'app/views/layouts/_____application.html.erb'
|
78
|
+
remove_file 'app/views/layouts/application.html.erb'
|
79
|
+
copy_file "#{@@template_path}/views/application.html.haml", 'app/views/layouts/application.html.haml'
|
80
|
+
copy_file "#{@@template_path}/views/_user_icon.html.haml", "app/views/layouts/_user_icon.html.haml"
|
81
|
+
copy_file "#{@@template_path}/views/index.html.haml", "app/views/top/index.html.haml"
|
82
|
+
|
83
|
+
## assets
|
84
|
+
copy_file "#{@@template_path}/stylesheets/scaffolds.css.scss", "app/assets/stylesheets/scaffolds.css.scss"
|
85
|
+
|
86
|
+
## README
|
87
|
+
remove_file 'README.rdoc'
|
88
|
+
copy_file "#{@@template_path}/README.md", "README.md"
|
89
|
+
|
90
|
+
## .gitignore
|
93
91
|
content = "\n# Add\n"
|
94
92
|
content += ".DS_Store\n"
|
95
93
|
content += "vendor/bundle\n"
|
@@ -98,7 +96,7 @@ module Minimum
|
|
98
96
|
content += "config/settings.local.yml\n"
|
99
97
|
content += "config/settings/*.local.yml\n"
|
100
98
|
content += "config/environments/*.local.yml\n"
|
101
|
-
append_file
|
99
|
+
append_file ".gitignore", content.force_encoding('ASCII-8BIT')
|
102
100
|
end
|
103
101
|
end
|
104
102
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class SessionsController < ApplicationController
|
2
|
-
|
2
|
+
skip_before_action :authenticate
|
3
3
|
|
4
4
|
# ログイン
|
5
5
|
def callback
|
@@ -8,7 +8,7 @@ class SessionsController < ApplicationController
|
|
8
8
|
authentication.auth_update(auth)
|
9
9
|
|
10
10
|
# ユーザ取得or作成
|
11
|
-
user = User.find_by(id: authentication.user_id) || User.create_with_auth(authentication)
|
11
|
+
user = User.find_by(id: authentication.user_id) || User.create_with_auth(authentication, request)
|
12
12
|
|
13
13
|
session[:user_id] = user.id
|
14
14
|
flash[:notice] = "ログインしました。"
|
@@ -4,7 +4,7 @@ class User < ActiveRecord::Base
|
|
4
4
|
private
|
5
5
|
|
6
6
|
# ユーザ作成
|
7
|
-
def self.create_with_auth(authentication)
|
7
|
+
def self.create_with_auth(authentication, request)
|
8
8
|
# ユーザ作成
|
9
9
|
user = User.new
|
10
10
|
user.name = (authentication.nickname.presence || authentication.name)
|
@@ -12,6 +12,7 @@ class User < ActiveRecord::Base
|
|
12
12
|
user.email = authentication.email if authentication.email.present?
|
13
13
|
user.last_login_provider = authentication.provider if authentication.provider.present?
|
14
14
|
user.last_login_at = Time.now
|
15
|
+
user.user_agent = request.env['HTTP_USER_AGENT'] rescue 'error'
|
15
16
|
|
16
17
|
# データ保存
|
17
18
|
user.save!
|
@@ -0,0 +1,40 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title= Settings.app_name
|
5
|
+
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
|
6
|
+
= javascript_include_tag 'application', 'data-turbolinks-track' => true
|
7
|
+
= csrf_meta_tags
|
8
|
+
%body{ 'data-no-turbolink' => true }
|
9
|
+
= link_to Settings.app_name, :root
|
10
|
+
|
11
|
+
- if signed_in?
|
12
|
+
= render partial: '/layouts/user_icon', locals: { user: current_user, size: "18x18", klass: "margin_minus2" }
|
13
|
+
= link_to "Top", root_path
|
14
|
+
= link_to "Logout", logout_path
|
15
|
+
- else
|
16
|
+
Login:
|
17
|
+
= link_to 'Twitter', '/auth/twitter'
|
18
|
+
= link_to 'Facebook', '/auth/facebook'
|
19
|
+
= link_to 'GitHub', '/auth/github'
|
20
|
+
|
21
|
+
= simple_format(flash[:notice], style: "color: green;") if flash[:notice].present?
|
22
|
+
= simple_format(flash[:alert], style: "color: red;") if flash[:alert].present?
|
23
|
+
|
24
|
+
= yield
|
25
|
+
|
26
|
+
%br/
|
27
|
+
%br/
|
28
|
+
|
29
|
+
%center
|
30
|
+
Developed by
|
31
|
+
= succeed "," do
|
32
|
+
%a{ href: "https://twitter.com/#{Settings.programmer_twitter_id}/", target: '_blank' }
|
33
|
+
= "@#{Settings.programmer_twitter_id}"
|
34
|
+
Designed by
|
35
|
+
= succeed "," do
|
36
|
+
%a{ href: "https://twitter.com/#{Settings.designer_twitter_id}/", target: '_blank' }
|
37
|
+
= "@#{Settings.designer_twitter_id}"
|
38
|
+
Licence by
|
39
|
+
%a{ href: 'https://creativecommons.org/licenses/by-nc-sa/2.1/jp/', target: '_blank' }
|
40
|
+
CC BY-NC-SA 2.1
|
@@ -0,0 +1 @@
|
|
1
|
+
%h1= "Welcome to #{Settings.app_name}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimum-omniauth-scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shu0115
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -154,8 +154,11 @@ files:
|
|
154
154
|
- lib/minimum/omniauth/scaffold/templates/rails_config/test.yml
|
155
155
|
- lib/minimum/omniauth/scaffold/templates/stylesheets/scaffolds.css.scss
|
156
156
|
- lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.erb
|
157
|
+
- lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.haml
|
157
158
|
- lib/minimum/omniauth/scaffold/templates/views/application.html.erb
|
159
|
+
- lib/minimum/omniauth/scaffold/templates/views/application.html.haml
|
158
160
|
- lib/minimum/omniauth/scaffold/templates/views/index.html.erb
|
161
|
+
- lib/minimum/omniauth/scaffold/templates/views/index.html.haml
|
159
162
|
- lib/minimum/omniauth/scaffold/version.rb
|
160
163
|
- minimum-omniauth-scaffold.gemspec
|
161
164
|
homepage: https://github.com/shu0115/minimum-omniauth-scaffold
|