mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 05:48:23 +08:00
Perform the where(...).first to find_by(...) refactoring.
This refactoring was automated using the command: bundle exec "ruby refactorings/where_dot_first_to_find_by/app.rb"
This commit is contained in:
@ -24,7 +24,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
current_user = nil
|
||||
|
||||
if auth_token && auth_token.length == 32
|
||||
current_user = User.where(auth_token: auth_token).first
|
||||
current_user = User.find_by(auth_token: auth_token)
|
||||
end
|
||||
|
||||
if current_user && (current_user.suspended? || !current_user.active)
|
||||
@ -53,7 +53,7 @@ class Auth::DefaultCurrentUserProvider
|
||||
raise Discourse::InvalidAccess.new if api_username && (api_key.user.username_lower != api_username.downcase)
|
||||
current_user = api_key.user
|
||||
elsif api_username
|
||||
current_user = User.where(username_lower: api_username.downcase).first
|
||||
current_user = User.find_by(username_lower: api_username.downcase)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -17,10 +17,10 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
|
||||
result.extra_data = facebook_hash
|
||||
|
||||
user_info = FacebookUserInfo.where(facebook_user_id: facebook_hash[:facebook_user_id]).first
|
||||
user_info = FacebookUserInfo.find_by(facebook_user_id: facebook_hash[:facebook_user_id])
|
||||
result.user = user_info.try(:user)
|
||||
|
||||
if !result.user && !email.blank? && result.user = User.where(email: Email.downcase(email)).first
|
||||
if !result.user && !email.blank? && result.user = User.find_by(email: Email.downcase(email))
|
||||
FacebookUserInfo.create({user_id: result.user.id}.merge(facebook_hash))
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Auth::GithubAuthenticator < Auth::Authenticator
|
||||
github_screen_name: screen_name,
|
||||
}
|
||||
|
||||
user_info = GithubUserInfo.where(github_user_id: github_user_id).first
|
||||
user_info = GithubUserInfo.find_by(github_user_id: github_user_id)
|
||||
|
||||
if user_info
|
||||
user = user_info.user
|
||||
|
@ -20,7 +20,7 @@ class Auth::OAuth2Authenticator < Auth::Authenticator
|
||||
result.email = email = data[:email]
|
||||
result.name = name = data[:name]
|
||||
|
||||
oauth2_user_info = Oauth2UserInfo.where(uid: oauth2_uid, provider: oauth2_provider).first
|
||||
oauth2_user_info = Oauth2UserInfo.find_by(uid: oauth2_uid, provider: oauth2_provider)
|
||||
|
||||
if !oauth2_user_info && @opts[:trusted] && user = User.find_by_email(email)
|
||||
oauth2_user_info = Oauth2UserInfo.create(uid: oauth2_uid,
|
||||
|
@ -21,7 +21,7 @@ class Auth::TwitterAuthenticator < Auth::Authenticator
|
||||
twitter_screen_name: screen_name
|
||||
}
|
||||
|
||||
user_info = TwitterUserInfo.where(twitter_user_id: twitter_user_id).first
|
||||
user_info = TwitterUserInfo.find_by(twitter_user_id: twitter_user_id)
|
||||
|
||||
result.user = user_info.try(:user)
|
||||
|
||||
|
Reference in New Issue
Block a user