Skip to content
Browse files

Adding a few more refactors to the authorization model.

  • Loading branch information...
1 parent 52e7a41 commit f1d4ff2fc9b456ebf05c1b5e3d7569c59d87950d Kurtis Rainbolt-Greene committed
Showing with 15 additions and 18 deletions.
  1. +15 −18 models/authorization.rb
View
33 models/authorization.rb
@@ -9,8 +9,8 @@ class Authorization
# sense.
belongs_to :user
- key :uid, Integer, :required => true
- key :provider, String, :required => true
+ key :uid, Integer, required: true
+ key :provider, String, required: true
key :oauth_token, String
key :oauth_secret, String
key :nickname
@@ -18,7 +18,7 @@ class Authorization
# Super cool validations. We don't want to let two people sign up with the
# same external auth, but just in case there's a clash between providers,
# we scope it. So easy!
- validates_uniqueness_of :uid, :scope => :provider
+ validates_uniqueness_of :uid, scope: :provider
# Locates an authorization from data provided from a successful omniauth
# authentication response
@@ -33,27 +33,24 @@ def self.find_from_hash(hash)
end
# Creates an authorization from a sucessful omniauth authentication response
+ # TODO: Figure out why BASE_URI is here.
def self.create_from_hash(hash, base_uri, user = nil)
+
+ # If there isn't a user, create a user and author.
if user.blank?
author = Author.create_from_hash! hash
-
user = User.create! author: author, username: author.username
end
- uid = hash['uid']
- provider = hash['provider']
- nickname = hash['user_info']['nickname']
- token = hash['credentials']['token']
- secret = hash['credentials']['secret']
-
- create!(
- user: user,
- uid: uid,
- provider: provider,
- nickname: nickname,
- oauth_token: token,
- oauth_secret: secret
- )
+ # Grab the user information from the hash
+ uid, provider, nickname = hash['uid'], hash['provider'], hash['user_info']['nickname']
+
+ # Grab teh credentials, including token and secret, from the hash
+ credentials = hash['credentials']
+ token, secret = credentials['token'], credentials['secret']
+
+ # Create a new authorization with the provided details
+ create! user: user, uid: uid, provider: provider, nickname: nickname, oauth_token: token, oauth_secret: secret
end
timestamps!

0 comments on commit f1d4ff2

Please sign in to comment.
Something went wrong with that request. Please try again.