Class: User
- Inherits:
-
Object
- Object
- User
- Includes:
- MongoidSetup
- Defined in:
- lib/generators/rails_eve/install/templates/user.rb
Class Method Summary collapse
- .create_from_omniauth(payload) ⇒ Object
- .from_omniauth(auth) ⇒ Object
- .update_counter_caches ⇒ Object
Instance Method Summary collapse
- #character_api ⇒ Object
- #import_character(omniauth_payload) ⇒ Object
- #will_save_change_to_email? ⇒ Boolean
Class Method Details
.create_from_omniauth(payload) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 44 def self.create_from_omniauth(payload) u = new u.uid = payload.uid u.password = SecureRandom.hex u.email = '[email protected]' u.save end |
.from_omniauth(auth) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 37 def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = SecureRandom.hex user.password = Devise.friendly_token[0, 20] end end |
.update_counter_caches ⇒ Object
30 31 32 33 34 35 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 30 def self.update_counter_caches all.each do |user| user.characters_count = user.characters.count user.save end end |
Instance Method Details
#character_api ⇒ Object
52 53 54 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 52 def character_api ESI::CharacterApi.new end |
#import_character(omniauth_payload) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 56 def import_character(omniauth_payload) character_id = omniauth_payload['extra']['raw_info']['CharacterID'] api_character = character_api.get_characters_character_id(character_id) credentials = omniauth_payload['credentials'] character = characters.where(id: character_id, name: api_character.name, corporation_id: api_character.corporation_id, alliance_id: api_character.alliance_id).first_or_create character.update_tokens(credentials) end |
#will_save_change_to_email? ⇒ Boolean
28 |
# File 'lib/generators/rails_eve/install/templates/user.rb', line 28 def will_save_change_to_email?; end |