minimum-omniauth-scaffold 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minimum/omniauth/scaffold.rb +11 -11
- data/lib/minimum/omniauth/scaffold/templates/README.md +7 -7
- data/lib/minimum/omniauth/scaffold/templates/controllers/application_controller.rb +2 -6
- data/lib/minimum/omniauth/scaffold/templates/controllers/sessions_controller.rb +1 -5
- data/lib/minimum/omniauth/scaffold/templates/controllers/top_controller.rb +0 -1
- data/lib/minimum/omniauth/scaffold/templates/initializers/omniauth.rb +0 -1
- data/lib/minimum/omniauth/scaffold/templates/migrate/create_users.rb +1 -1
- data/lib/minimum/omniauth/scaffold/templates/models/authentication.rb +24 -27
- data/lib/minimum/omniauth/scaffold/templates/models/user.rb +0 -1
- data/lib/minimum/omniauth/scaffold/templates/rails_config/settings.yml +4 -12
- data/lib/minimum/omniauth/scaffold/templates/views/application.html.haml +5 -9
- data/lib/minimum/omniauth/scaffold/version.rb +1 -1
- metadata +2 -5
- data/lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.erb +0 -3
- data/lib/minimum/omniauth/scaffold/templates/views/application.html.erb +0 -28
- data/lib/minimum/omniauth/scaffold/templates/views/index.html.erb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f48287bf1ddf9d429f7485eef3412005c4ca5354
|
4
|
+
data.tar.gz: cb12d076dc92f7d35b0d1259ea38927e7c4ed196
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08c72bd924eda54f6fc67c81c3a4b62d435ea18dd174f45b758aafd2537a840ce07205f6cfb02dcada10d81962f37ab17b84a10d93df4026dc444e220bb39614
|
7
|
+
data.tar.gz: 9a9094fdb1707500c4258b5eb9b89fe3764bd5fbf0be393aa30b9b622a396498ee25e88582c97e34a21f05bb72fd7046345a669b48c1fff289072ee153b3178c
|
@@ -29,9 +29,9 @@ module Minimum
|
|
29
29
|
|
30
30
|
# routes.rb
|
31
31
|
content = "\n # For OmniAuth\n"
|
32
|
-
content += " get
|
33
|
-
content += " get
|
34
|
-
content += " get
|
32
|
+
content += " get '/auth/:provider/callback', to: 'sessions#callback'\n"
|
33
|
+
content += " get '/auth/failure', to: 'sessions#failure'\n"
|
34
|
+
content += " get '/logout', to: 'sessions#destroy', as: :logout\n"
|
35
35
|
content += "\n"
|
36
36
|
insert_into_file "config/routes.rb", content.force_encoding('ASCII-8BIT'), after: "Rails.application.routes.draw do\n"
|
37
37
|
insert_into_file "config/routes.rb", " root to: 'top#index'\n", after: "Rails.application.routes.draw do\n"
|
@@ -73,14 +73,14 @@ module Minimum
|
|
73
73
|
# assets
|
74
74
|
copy_file "#{@@template_path}/stylesheets/scaffolds.css.scss", "app/assets/stylesheets/scaffolds.css.scss"
|
75
75
|
|
76
|
-
# README
|
77
|
-
begin
|
78
|
-
|
79
|
-
|
80
|
-
rescue => e
|
81
|
-
|
82
|
-
end
|
83
|
-
copy_file "#{@@template_path}/README.md", "README.md"
|
76
|
+
# # README
|
77
|
+
# begin
|
78
|
+
# copy_file "#{@@current_path}/README.md", 'README_BACKUP.md'
|
79
|
+
# remove_file "#{@@current_path}/README.md"
|
80
|
+
# rescue => e
|
81
|
+
# e.tapp
|
82
|
+
# end
|
83
|
+
# copy_file "#{@@template_path}/README.md", "README.md"
|
84
84
|
|
85
85
|
# .gitignore
|
86
86
|
content = "\n# Add\n"
|
@@ -39,7 +39,7 @@ CAPTCHA入力後「Create your Twitter application」を押下
|
|
39
39
|
|
40
40
|
### ローカル用Twitterキー設定
|
41
41
|
|
42
|
-
Create: config/settings.local.yml
|
42
|
+
- Create: config/settings.local.yml
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
# Twitter OAuth Local Setting
|
@@ -51,28 +51,28 @@ twitter_secret: "YOUR_CONSUMER_SECRET"
|
|
51
51
|
|
52
52
|
### Rails起動
|
53
53
|
|
54
|
-
Gemインストール
|
54
|
+
- Gemインストール
|
55
55
|
|
56
56
|
```
|
57
57
|
bundle install --without production
|
58
58
|
```
|
59
59
|
|
60
|
-
ローカルDB作成
|
60
|
+
- ローカルDB作成
|
61
61
|
|
62
62
|
```
|
63
|
-
rake db:
|
63
|
+
bundle exec rake db:migrate
|
64
64
|
```
|
65
65
|
|
66
|
-
ローカルサーバ起動
|
66
|
+
- ローカルサーバ起動
|
67
67
|
|
68
68
|
```
|
69
69
|
bundle exec rails s
|
70
70
|
```
|
71
71
|
|
72
|
-
ページアクセス
|
72
|
+
- ページアクセス
|
73
73
|
|
74
74
|
```
|
75
|
-
http://
|
75
|
+
http://localhost:3000/
|
76
76
|
```
|
77
77
|
|
78
78
|
## Copyright
|
@@ -1,9 +1,8 @@
|
|
1
|
-
before_action :authenticate
|
2
|
-
before_action :reset_session_expires
|
1
|
+
before_action :authenticate
|
2
|
+
before_action :reset_session_expires
|
3
3
|
|
4
4
|
private
|
5
5
|
|
6
|
-
# ログイン認証
|
7
6
|
def authenticate
|
8
7
|
unless signed_in?
|
9
8
|
session[:request_url] = request.url
|
@@ -12,18 +11,15 @@
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
# セッション期限延長
|
16
14
|
def reset_session_expires
|
17
15
|
request.session_options[:expire_after] = 2.weeks
|
18
16
|
end
|
19
17
|
|
20
|
-
# ログインユーザ
|
21
18
|
def current_user
|
22
19
|
@current_user ||= User.find_by(id: session[:user_id])
|
23
20
|
end
|
24
21
|
helper_method :current_user
|
25
22
|
|
26
|
-
# ログイン/ユーザ登録済みチェック
|
27
23
|
def signed_in?
|
28
24
|
User.where(id: session[:user_id]).exists?
|
29
25
|
end
|
@@ -1,19 +1,16 @@
|
|
1
1
|
class SessionsController < ApplicationController
|
2
2
|
skip_before_action :authenticate
|
3
3
|
|
4
|
-
# ログイン
|
5
4
|
def callback
|
6
5
|
auth = request.env["omniauth.auth"]
|
7
6
|
authentication = Authentication.find_by(provider: auth["provider"], uid: auth["uid"]) || Authentication.create_with_omniauth(auth)
|
8
7
|
authentication.auth_update(auth)
|
9
8
|
|
10
|
-
# ユーザ取得or作成
|
11
9
|
user = User.find_by(id: authentication.user_id) || User.create_with_auth(authentication, request)
|
12
10
|
|
13
11
|
session[:user_id] = user.id
|
14
12
|
flash[:notice] = "ログインしました。"
|
15
13
|
|
16
|
-
# 保管URLへリダイレクト
|
17
14
|
unless session[:request_url].blank?
|
18
15
|
redirect_to session[:request_url]
|
19
16
|
session[:request_url] = nil
|
@@ -23,16 +20,15 @@ class SessionsController < ApplicationController
|
|
23
20
|
redirect_to :root and return
|
24
21
|
end
|
25
22
|
|
26
|
-
# ログアウト
|
27
23
|
def destroy
|
28
24
|
session[:user_id] = nil
|
29
25
|
|
30
26
|
redirect_to :root, notice: "ログアウトしました。" and return
|
31
27
|
end
|
32
28
|
|
33
|
-
# ログインエラー
|
34
29
|
def failure
|
35
30
|
flash[:alert] = 'Auth Failure'
|
31
|
+
|
36
32
|
redirect_to :root and return
|
37
33
|
end
|
38
34
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
2
2
|
# Providers
|
3
|
-
# provider :developer unless Rails.env.production?
|
4
3
|
provider :twitter, Settings.twitter_key, Settings.twitter_secret
|
5
4
|
provider :facebook, Settings.facebook_app_id, Settings.facebook_app_secret
|
6
5
|
provider :github, Settings.github_client_id, Settings.github_secret
|
@@ -4,7 +4,7 @@ class CreateUsers < ActiveRecord::Migration
|
|
4
4
|
t.string :name
|
5
5
|
t.string :image
|
6
6
|
t.string :email
|
7
|
-
t.boolean :admin_flag, default: false
|
7
|
+
t.boolean :admin_flag, default: false, null: false
|
8
8
|
t.string :last_login_provider
|
9
9
|
t.timestamp :last_login_at
|
10
10
|
t.text :user_agent
|
@@ -1,56 +1,53 @@
|
|
1
1
|
class Authentication < ActiveRecord::Base
|
2
2
|
belongs_to :user, optional: true
|
3
3
|
|
4
|
-
# バリデーション
|
5
4
|
validates :provider, presence: true
|
6
|
-
validates :uid,
|
5
|
+
validates :uid, presence: true
|
7
6
|
|
8
|
-
# auth情報更新
|
9
7
|
def auth_update(auth)
|
10
|
-
case auth[
|
11
|
-
when
|
8
|
+
case auth['provider']
|
9
|
+
when 'facebook'
|
12
10
|
image_path = "https://graph.facebook.com/#{auth['info']['nickname'].presence || auth["uid"]}/picture?width=200&height=200"
|
13
|
-
when
|
14
|
-
image_path = auth[
|
15
|
-
when
|
11
|
+
when 'twitter'
|
12
|
+
image_path = auth['info']['image'].to_s.gsub('_normal', '') rescue nil
|
13
|
+
when 'github'
|
16
14
|
image_path = "#{auth['info']['image']}&size=200" rescue nil
|
17
15
|
end
|
18
16
|
|
19
|
-
gender = auth[
|
20
|
-
location = (auth[
|
17
|
+
gender = auth['extra']['raw_info']['gender'] rescue nil
|
18
|
+
location = (auth['info']['location'].presence || auth['extra']['raw_info']['location']) rescue nil
|
21
19
|
|
22
|
-
self.name = auth[
|
23
|
-
self.nickname = auth[
|
20
|
+
self.name = auth['info']['name'] if auth['info']['name'].present?
|
21
|
+
self.nickname = auth['info']['nickname'] if auth['info']['nickname'].present?
|
24
22
|
self.image = image_path if image_path.present?
|
25
|
-
self.email = auth[
|
23
|
+
self.email = auth['info']['email'] if auth['info']['email'].present?
|
26
24
|
self.gender = gender if gender.present?
|
27
25
|
self.location = location if location.present?
|
28
26
|
self.save!
|
29
27
|
end
|
30
28
|
|
31
29
|
class << self
|
32
|
-
# auth情報登録
|
33
30
|
def create_with_omniauth(auth)
|
34
31
|
authentication = Authentication.new
|
35
|
-
authentication.provider = auth[
|
36
|
-
authentication.uid = auth[
|
37
|
-
|
38
|
-
if auth[
|
39
|
-
authentication.name = auth[
|
40
|
-
authentication.nickname = auth[
|
41
|
-
authentication.image = auth[
|
42
|
-
authentication.email = auth[
|
43
|
-
authentication.location = auth[
|
32
|
+
authentication.provider = auth['provider']
|
33
|
+
authentication.uid = auth['uid']
|
34
|
+
|
35
|
+
if auth['info'].present?
|
36
|
+
authentication.name = auth['info']['name']
|
37
|
+
authentication.nickname = auth['info']['nickname']
|
38
|
+
authentication.image = auth['info']['image']
|
39
|
+
authentication.email = auth['info']['email']
|
40
|
+
authentication.location = auth['info']['location']
|
44
41
|
end
|
45
42
|
|
46
|
-
if auth[
|
43
|
+
if auth['credentials'].present?
|
47
44
|
authentication.token = auth['credentials']['token']
|
48
45
|
authentication.secret = auth['credentials']['secret']
|
49
46
|
end
|
50
47
|
|
51
|
-
if auth[
|
52
|
-
authentication.gender = auth[
|
53
|
-
authentication.location = auth[
|
48
|
+
if auth['extra'].present? and auth['extra']['raw_info'].present?
|
49
|
+
authentication.gender = auth['extra']['raw_info']['gender']
|
50
|
+
authentication.location = auth['extra']['raw_info']['location'] if authentication.location.blank?
|
54
51
|
end
|
55
52
|
|
56
53
|
authentication.save!
|
@@ -1,13 +1,5 @@
|
|
1
|
-
|
2
|
-
twitter_page: "https://twitter.com/"
|
3
|
-
facebook_page: "https://www.facebook.com/"
|
4
|
-
github_page: "https://github.com/"
|
1
|
+
app_name: 'YOUR_APP_NAME'
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# プログラマTwitterID
|
10
|
-
programmer_twitter_id: "PROGRAMMER_TWITTER_ID"
|
11
|
-
|
12
|
-
# 曜日
|
13
|
-
weekday: ["日", "月", "火", "水", "木", "金", "土"]
|
3
|
+
twitter_page: 'https://twitter.com/'
|
4
|
+
facebook_page: 'https://www.facebook.com/'
|
5
|
+
github_page: 'https://github.com/'
|
@@ -2,10 +2,11 @@
|
|
2
2
|
%html
|
3
3
|
%head
|
4
4
|
%title= Settings.app_name
|
5
|
-
= stylesheet_link_tag 'application', media: 'all'
|
6
|
-
= javascript_include_tag 'application'
|
7
5
|
= csrf_meta_tags
|
8
|
-
|
6
|
+
|
7
|
+
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
|
8
|
+
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
|
9
|
+
%body{ class: [controller_name, action_name], id: [controller_name, action_name] }
|
9
10
|
= link_to Settings.app_name, :root
|
10
11
|
|
11
12
|
- if signed_in?
|
@@ -27,9 +28,4 @@
|
|
27
28
|
%br/
|
28
29
|
|
29
30
|
%center
|
30
|
-
Developed by
|
31
|
-
= link_to "@#{Settings.programmer_twitter_id}", "https://twitter.com/#{Settings.programmer_twitter_id}/", target: '_blank'
|
32
|
-
|
33
|
-
-# Licence by
|
34
|
-
-# %a{ href: 'https://creativecommons.org/licenses/by-nc-sa/2.1/jp/', target: '_blank' }
|
35
|
-
-# CC BY-NC-SA 2.1
|
31
|
+
Developed by YOUR_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.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shu0115
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -139,11 +139,8 @@ files:
|
|
139
139
|
- lib/minimum/omniauth/scaffold/templates/rails_config/settings.yml
|
140
140
|
- lib/minimum/omniauth/scaffold/templates/rails_config/test.yml
|
141
141
|
- lib/minimum/omniauth/scaffold/templates/stylesheets/scaffolds.css.scss
|
142
|
-
- lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.erb
|
143
142
|
- lib/minimum/omniauth/scaffold/templates/views/_user_icon.html.haml
|
144
|
-
- lib/minimum/omniauth/scaffold/templates/views/application.html.erb
|
145
143
|
- lib/minimum/omniauth/scaffold/templates/views/application.html.haml
|
146
|
-
- lib/minimum/omniauth/scaffold/templates/views/index.html.erb
|
147
144
|
- lib/minimum/omniauth/scaffold/templates/views/index.html.haml
|
148
145
|
- lib/minimum/omniauth/scaffold/version.rb
|
149
146
|
- minimum-omniauth-scaffold.gemspec
|
@@ -1,3 +0,0 @@
|
|
1
|
-
<% if user.present? %>
|
2
|
-
<%= link_to_unless(user.name.blank?, image_tag( user.image, size: size, class: klass ), "#{Settings[user.last_login_provider + '_page']}#{user.name}", target: "_blank", title: user.name, rel: "tooltip", "data-original-title" => user.name) %>
|
3
|
-
<% end %>
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<%= link_to Settings.app_name, :root %>
|
2
|
-
|
3
|
-
<% if signed_in? %>
|
4
|
-
<%# ログイン済み %>
|
5
|
-
<%= render partial: '/layouts/user_icon', locals: { user: current_user, size: "18x18", klass: "margin_minus2" } %>
|
6
|
-
<%= link_to "Top", root_path %>
|
7
|
-
<%= link_to "Logout", logout_path %>
|
8
|
-
<% else %>
|
9
|
-
<%# 未ログイン %>
|
10
|
-
Login:
|
11
|
-
<%= link_to "Twitter", "/auth/twitter" %>
|
12
|
-
<%= link_to "Facebook", "/auth/facebook" %>
|
13
|
-
<%= link_to "GitHub", "/auth/github" %>
|
14
|
-
<% end %>
|
15
|
-
|
16
|
-
<%# 通知/エラーメッセージ %>
|
17
|
-
<%= simple_format(flash[:notice], style: "color: green;") if flash[:notice].present? %>
|
18
|
-
<%= simple_format(flash[:alert], style: "color: red;") if flash[:alert].present? %>
|
19
|
-
|
20
|
-
<%= yield %>
|
21
|
-
|
22
|
-
<br /><br />
|
23
|
-
|
24
|
-
<center>
|
25
|
-
Developed by <a href="https://twitter.com/<%= Settings.programmer_twitter_id %>/" target="_blank">@<%= Settings.programmer_twitter_id %></a>,
|
26
|
-
Designed by <a href="https://twitter.com/<%= Settings.designer_twitter_id %>/" target="_blank">@<%= Settings.designer_twitter_id %></a>,
|
27
|
-
Licence by <a href="https://creativecommons.org/licenses/by-nc-sa/2.1/jp/" target="_blank">CC BY-NC-SA 2.1</a>
|
28
|
-
</center>
|