diff --git a/app/models/user.rb b/app/models/user.rb index 31d85328e..d19072fe5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -131,7 +131,8 @@ class User < ApplicationRecord # Get the existing user by email if the provider gives us a verified email. def self.first_or_initialize_for_oauth(auth) oauth_email = auth.info.email - oauth_email_confirmed = oauth_email.present? && (auth.info.verified || auth.info.verified_email) + oauth_verified = auth.info.verified || auth.info.verified_email || auth.info.email_verified + oauth_email_confirmed = oauth_email.present? && oauth_verified oauth_user = User.find_by(email: oauth_email) if oauth_email_confirmed oauth_user || User.new( diff --git a/spec/system/users_auth_spec.rb b/spec/system/users_auth_spec.rb index c41c23e77..8a4b93497 100644 --- a/spec/system/users_auth_spec.rb +++ b/spec/system/users_auth_spec.rb @@ -223,11 +223,10 @@ describe "Users" do end context "Twitter" do - let(:twitter_hash) { { provider: "twitter", uid: "12345", info: { name: "manuela" }} } - let(:twitter_hash_with_email) { { provider: "twitter", uid: "12345", info: { name: "manuela", email: "manuelacarmena@example.com" }} } + let(:twitter_hash) { { uid: "12345", info: { name: "manuela" }} } + let(:twitter_hash_with_email) { { uid: "12345", info: { name: "manuela", email: "manuelacarmena@example.com" }} } let(:twitter_hash_with_verified_email) do { - provider: "twitter", uid: "12345", info: { name: "manuela", @@ -480,13 +479,40 @@ describe "Users" do end end - context "Wordpress" do - let(:wordpress_hash) do - { provider: "wordpress", + context "Google" do + let(:google_hash) do + { uid: "12345", info: { name: "manuela", - email: "manuelacarmena@example.com" }} + email: "manuelacarmena@example.com", + email_verified: "1" + } + } + end + + before { Setting["feature.google_login"] = true } + + scenario "Sign in with an already registered user using a verified google account" do + OmniAuth.config.add_mock(:google_oauth2, google_hash) + create(:user, username: "manuela", email: "manuelacarmena@example.com") + + visit new_user_session_path + click_link "Sign in with Google" + + expect_to_be_signed_in + end + end + + context "Wordpress" do + let(:wordpress_hash) do + { + uid: "12345", + info: { + name: "manuela", + email: "manuelacarmena@example.com" + } + } end before { Setting["feature.wordpress_login"] = true }