Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Includes:
- SocialStream::Models::Subject
- Defined in:
- app/models/user.rb
Class Method Summary collapse
-
.find_for_authentication(conditions) ⇒ Object
presence ID and login.
- .find_or_create_for_facebook_oauth(access_token, signed_in_resource = nil) ⇒ Object
- .find_or_create_for_linkedin_oauth(access_token, signed_in_resource = nil) ⇒ Object
-
.find_or_initialize_with_error_by_email(value, error) ⇒ Object
Overwrite devise default method to support finding with actor.email.
- .find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) ⇒ Object
Instance Method Summary collapse
- #recent_groups ⇒ Object
-
#represented ⇒ Object
Subjects this user can acts as.
Class Method Details
.find_for_authentication(conditions) ⇒ Object
presence ID and login
77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/user.rb', line 77 def find_for_authentication(conditions) if ( login = conditions[:email] ).present? if login =~ /@/ find_by_email(login) else find_by_slug(login) end else super end end |
.find_or_create_for_facebook_oauth(access_token, signed_in_resource = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/models/user.rb', line 118 def find_or_create_for_facebook_oauth(access_token,signed_in_resource=nil) data = access_token['extra']['user_hash'] print data auth = Authentication.find_by_provider_and_uid(access_token["provider"],access_token["uid"]) user = User.find_by_email(data["email"]) if user == nil user = User.create!(:name => data["name"], :email => data["email"], :password => Devise.friendly_token[0,20]) end if auth == nil auth = Authentication.create!(:user_id => user.id, :uid =>access_token["uid"], :provider => access_token["provider"]) end user end |
.find_or_create_for_linkedin_oauth(access_token, signed_in_resource = nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/user.rb', line 133 def find_or_create_for_linkedin_oauth(access_token,signed_in_resource=nil) auth = Authentication.find_by_uid_and_provider(access_token["uid"],access_token["provider"]) if auth==nil user = User.create!(:name => access_token["user_info"]["name"], :email => '[email protected]', :password => Devise.friendly_token[0,20]) auth = Authentication.create!(:user_id => user.id, :uid =>access_token["uid"], :provider => access_token["provider"]) user else user = User.find_by_id(auth.user_id) user end end |
.find_or_initialize_with_error_by_email(value, error) ⇒ Object
Overwrite devise default method to support finding with actor.email
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/user.rb', line 98 def find_or_initialize_with_error_by_email(value, error) if value.present? record = find_by_email(value) end unless record record = new if value.present? record.email = value else error = :blank end record.errors.add(:email, error) end record end |
.find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) ⇒ Object
89 90 91 92 93 94 95 |
# File 'app/models/user.rb', line 89 def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) if required_attributes == [:email] find_or_initialize_with_error_by_email(attributes[:email], error) else super end end |
Instance Method Details
#recent_groups ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/user.rb', line 29 def recent_groups contact_subjects(:type => :group, :direction => :sent) do |q| q.select("contacts.created_at"). merge(Contact.recent) end end |
#represented ⇒ Object
Subjects this user can acts as
37 38 39 40 41 42 43 44 45 |
# File 'app/models/user.rb', line 37 def represented candidates = contact_actors(:direction => :sent).map(&:id) contact_subjects(:direction => :received) do |q| q.joins(:sent_ties => { :relation => :permissions }). merge(Permission.represent). where(:id => candidates) end end |