Skip to content

Commit 88c9a85

Browse files
committed
and add that back in too
1 parent e6350ae commit 88c9a85

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

app/models/user.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
class User < ApplicationRecord
2-
# Include default devise modules. Others available are:
3-
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4-
devise :database_authenticatable, :registerable,
5-
:recoverable, :rememberable, :validatable
1+
class User < ActiveRecord::Base
2+
devise :database_authenticatable, :registerable, :omniauthable,
3+
:recoverable, :rememberable, :trackable, omniauth_providers: [:bike_index]
4+
5+
def self.from_omniauth(uid, auth)
6+
where(email: auth.info.email).first_or_create do |user|
7+
user.email = auth.info.email
8+
user.password = Devise.friendly_token[0, 20]
9+
end
10+
end
11+
12+
def self.new_with_session(params, session)
13+
super.tap do |user|
14+
if data = session['devise.bike_index_email'] && session['devise.bike_index_data']['extra']['raw_info']
15+
user.email = data['email'] if user.email.blank?
16+
end
17+
end
18+
end
619
end

db/migrate/20180902201811_devise_create_users.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def change
3232
# t.string :unlock_token # Only if unlock strategy is :email or :both
3333
# t.datetime :locked_at
3434

35+
# Omniauthable
36+
t.string "provider"
37+
3538

3639
t.timestamps null: false
3740
end

0 commit comments

Comments
 (0)