REFACTOR: Prefer `exists?` over `present`.

This commit is contained in:
Guo Xiang Tan 2018-03-01 10:22:41 +08:00
parent 4b17b39e73
commit 5a462b930d
1 changed files with 7 additions and 1 deletions

View File

@ -117,8 +117,14 @@ class Users::OmniauthCallbacksController < ApplicationController
# automatically activate/unstage any account if a provider marked the email valid # automatically activate/unstage any account if a provider marked the email valid
if @auth_result.email_valid && @auth_result.email == user.email if @auth_result.email_valid && @auth_result.email == user.email
user.update!(staged: false) user.update!(staged: false)
# ensure there is an active email token # ensure there is an active email token
user.email_tokens.create(email: user.email) unless EmailToken.where(email: user.email, confirmed: true).present? || user.email_tokens.active.where(email: user.email).exists? unless EmailToken.where(email: user.email, confirmed: true).exists? ||
user.email_tokens.active.where(email: user.email).exists?
user.email_tokens.create!(email: user.email)
end
user.activate user.activate
user.update!(registration_ip_address: request.remote_ip) if user.registration_ip_address.blank? user.update!(registration_ip_address: request.remote_ip) if user.registration_ip_address.blank?
end end