質問編集履歴
4
h
title
CHANGED
File without changes
|
body
CHANGED
@@ -178,10 +178,6 @@
|
|
178
178
|
end
|
179
179
|
|
180
180
|
private
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
181
|
def auth_hash
|
186
182
|
request.env['omniauth.auth']
|
187
183
|
end
|
3
controller追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -146,4 +146,44 @@
|
|
146
146
|
|
147
147
|
From: /home/rails_user/xxxx/app/controllers/sessions_controller.rb:42 SessionsController#login:
|
148
148
|
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
###翌日追加
|
153
|
+
controllerが抜けてたので追記
|
154
|
+
|
155
|
+
app\controllers\sessions_controller.rb
|
156
|
+
```ruby
|
157
|
+
|
158
|
+
class SessionsController < ApplicationController
|
159
|
+
def new
|
160
|
+
end
|
161
|
+
|
162
|
+
def create
|
163
|
+
# メールアドレスによるログイン
|
164
|
+
# 省略
|
165
|
+
end
|
166
|
+
|
167
|
+
def destroy
|
168
|
+
log_out if logged_in?
|
169
|
+
redirect_to root_url
|
170
|
+
end
|
171
|
+
|
172
|
+
def create_from_SNS
|
173
|
+
if (user = User.find_or_create_from_auth_hash(auth_hash))
|
174
|
+
log_in(user)
|
175
|
+
binding.pry
|
176
|
+
redirect_back_or mypage_path
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
def auth_hash
|
186
|
+
request.env['omniauth.auth']
|
187
|
+
end
|
188
|
+
end
|
149
189
|
```
|
2
さらに追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -116,4 +116,34 @@
|
|
116
116
|
</div>
|
117
117
|
<!-- content content-bgcolor -->
|
118
118
|
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
###同日さらに追加
|
123
|
+
|
124
|
+
ちょっと分かったので追記です。
|
125
|
+
合っているか分かりませんが、ソーシャルログイン時のPOST送信は、googleプロバイダにPOSTして返ってきた値をcontrollerへ返しているようです。
|
126
|
+
そのため、viewからの値が渡らないのかもしれません。
|
127
|
+
|
128
|
+
勘違いしてたらご指摘いただけると幸いです。
|
129
|
+
|
130
|
+
config\routes.rb
|
131
|
+
```ruby
|
132
|
+
get 'auth/:provider/callback', to: 'sessions#create_from_SNS'
|
133
|
+
```
|
134
|
+
|
135
|
+
ログ
|
136
|
+
```ここに言語を入力
|
137
|
+
|
138
|
+
Started POST "/auth/google_oauth2" for ::1 at 2021-10-10 21:54:02 +0900
|
139
|
+
D, [2021-10-10T21:54:02.072597 #3346] DEBUG -- omniauth: (google_oauth2) Request phase initiated.
|
140
|
+
|
141
|
+
Started GET "/auth/google_oauth2/callback?state=b33b81d94be&code=4%2F0AX4XfWga4pb05TboJwU6AFSqUOTdzrJSnS1rzXnW1JCcs5WMhIOwdJtYOL_Qascope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=2&prompt=consent" for ::1 at 2021-10-10 21:55:06 +0900
|
142
|
+
D, [2021-10-10T21:55:06.115749 #3346] DEBUG -- omniauth: (google_oauth2) Callback phase initiated.
|
143
|
+
Processing by SessionsController#create_from_SNS as HTML
|
144
|
+
Parameters: {"state"=>"b33b81d947b10fe981255947c5fb7d127dd65cbe", "code"=>"4/0AX4XfWga4pb05TboJwU6AFSqUOTJCcs5WMhIOwdJtYOL_Qa6x8MaTMIQ", "scope"=>"email profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid", "authuser"=>"2", "prompt"=>"consent", "provider"=>"google_oauth2"}
|
145
|
+
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "test@gmail.com"], ["LIMIT", 1]]
|
146
|
+
|
147
|
+
From: /home/rails_user/xxxx/app/controllers/sessions_controller.rb:42 SessionsController#login:
|
148
|
+
|
119
149
|
```
|
1
html追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -66,4 +66,54 @@
|
|
66
66
|
<!-- content content-bgcolor -->
|
67
67
|
|
68
68
|
<%= javascript_pack_tag 'common/toggle-password' %>
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
###同日追加
|
73
|
+
展開されたHTMLを追記致します。
|
74
|
+
```html
|
75
|
+
<!-- コンテンツ -->
|
76
|
+
<div class="content content-bgcolor">
|
77
|
+
<div class="content__inner-1col">
|
78
|
+
<div class="form__inner">
|
79
|
+
<h2 class="lv2-h">ログイン</h2>
|
80
|
+
</div>
|
81
|
+
|
82
|
+
<form action="/auth/google_oauth2" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="3SJaySs6hbnnBTIxJL8zHPjINBg7xQIc0eYD+aOQn2j0VIe7GuBv+vm0aOnAXEjdJfJCl+0kerHfRa6/xUVmmw==" />
|
83
|
+
<input type="submit" name="commit" value="Googleでログイン" class="btn btn-primary btn-block" data-disable-with="Googleでログイン" />
|
84
|
+
<label>
|
85
|
+
<input name="sns[remember_me]" type="hidden" value="0" /><input class="chk" type="checkbox" value="1" name="sns[remember_me]" id="sns_remember_me" />
|
86
|
+
<span class="chk-text fs14">ログインしたままにする</span>
|
87
|
+
</label>
|
88
|
+
</form>
|
89
|
+
<form action="/login" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="kDmpn6Rj0nndDQbdmgP1ZCOVxNnOmKVtMAuQJ7VMqgCgx72qItpNt7yyIC7QZEWrdN+pBNzRa2E+4CHKgnFexA==" />
|
90
|
+
|
91
|
+
<div class="form__inner">
|
92
|
+
<label class="label label-default fs14" for="login-mail">メールアドレス</label>
|
93
|
+
<input class="input-text" id="login-mail" type="email" name="session[email]" />
|
94
|
+
</div>
|
95
|
+
<div class="form__inner">
|
96
|
+
<label class="label label-default fs14" for="login-password">パスワード</label>
|
97
|
+
<a class="link fs12" href="/password_resets/new">(パスワードを忘れた場合はこちら)</a>
|
98
|
+
<div class="toggle-password">
|
99
|
+
<input class="input-text" id="login-password" type="password" name="session[password]" />
|
100
|
+
<i class="toggle-password-i fa fa-eye-slash"></i>
|
101
|
+
</div>
|
102
|
+
<label>
|
103
|
+
<input name="session[remember_me]" type="hidden" value="0" /><input class="chk" type="checkbox" value="1" name="session[remember_me]" id="session_remember_me" />
|
104
|
+
<span class="chk-text fs14">ログインしたままにする</span>
|
105
|
+
</label>
|
106
|
+
</div>
|
107
|
+
<div class="form__inner">
|
108
|
+
<input type="submit" name="commit" value="ログイン" class="btn btn-primary btn-block" data-disable-with="ログイン" />
|
109
|
+
<br>
|
110
|
+
<div style="text-align: center; padding-top: 20px;">
|
111
|
+
<p class="fs12" >会員登録はお済みですか? <a class="link" href="/signup">会員登録はこちら</a><p>
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
</form> </div>
|
115
|
+
<!-- content__inner-1col -->
|
116
|
+
</div>
|
117
|
+
<!-- content content-bgcolor -->
|
118
|
+
|
69
119
|
```
|