user.rb
1.2 KB
1
2
3
4
5
6
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
36
37
38
39
40
41
require_dependency 'user'
class User
has_many :oauth_user_providers, :class_name => 'OauthClientPlugin::UserProvider'
has_many :oauth_providers, :through => :oauth_user_providers, :source => :provider
def password_required_with_oauth?
password_required_without_oauth? && oauth_providers.empty?
end
alias_method_chain :password_required?, :oauth
after_create :activate_oauth_user
def activate_oauth_user
# user creation through api does not set oauth_providers
if oauth_providers.empty?
#check if is oauth user, reading oauth_data recorded at cache store
oauth_data = OauthClientPlugin.read_cache_for(self.email)
if oauth_data
oauth_providers = [OauthClientPlugin::Provider.find(oauth_data[:provider])]
OauthClientPlugin.delete_cache_for(self.email)
end
end
unless oauth_providers.empty?
activate
oauth_providers.each do |provider|
OauthClientPlugin::UserProvider.create!(:user => self, :provider => provider, :enabled => true)
end
end
end
def make_activation_code_with_oauth
oauth_providers.blank? ? make_activation_code_without_oauth : nil
end
alias_method_chain :make_activation_code, :oauth
end