Module: Remotty::BaseUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/remotty/base_user.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
-
#add_oauth_info(auth) ⇒ Object
oauth authentication 추가.
-
#avatar_remote_url=(url) ⇒ Object
remote url attachment helper.
- #generate_auth_token!(auth_source) ⇒ Object
- #with_token(token) ⇒ Object
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
14 15 16 |
# File 'app/models/remotty/base_user.rb', line 14 def auth_token @auth_token end |
Instance Method Details
#add_oauth_info(auth) ⇒ Object
oauth authentication 추가
-
auth
: auth 정보-
provider, uid, info(name, image), credentials(token, secret, expires_at)
-
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/remotty/base_user.rb', line 40 def add_oauth_info(auth) oauth = OauthAuthentication.find_or_create_by(provider: auth[:provider], uid: auth[:uid]) if oauth oauth.update_with_credential(auth[:credentials]) oauth.user = self oauth.save end if auth[:info][:image] self.avatar_remote_url = auth[:info][:image] self.save end end |
#avatar_remote_url=(url) ⇒ Object
remote url attachment helper
56 57 58 59 60 61 62 63 |
# File 'app/models/remotty/base_user.rb', line 56 def avatar_remote_url=(url) avatar_url = process_uri(url) self.avatar = URI.parse(avatar_url) # Assuming url_value is http://example.com/photos/face.png # avatar_file_name == "face.png" # avatar_content_type == "image/png" @avatar_remote_url = avatar_url end |
#generate_auth_token!(auth_source) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/remotty/base_user.rb', line 16 def generate_auth_token!(auth_source) token = nil loop do token = Devise.friendly_token break token unless self.auth_tokens.where(token: Digest::SHA512.hexdigest(token)).first end auth_token = AuthToken.create({user_id:self.id, token: Digest::SHA512.hexdigest(token)}) auth_token.update_source(auth_source[:source], auth_source[:info]) token end |
#with_token(token) ⇒ Object
30 31 32 33 |
# File 'app/models/remotty/base_user.rb', line 30 def with_token(token) self.auth_token = token; ::UserSerializer.new(self) end |