<p></p>
<p><b>@tomhughes</b> requested changes on this pull request.</p>

<p dir="auto">Mostly looking good from a backend point of view with just a few minor issues but there is one big question around the new logic you've put in for dealing with linking a social signup to an existing account.</p>
<p dir="auto">Also there's the inconsistent colons on the field labels that already mentioned and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gravitystorm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gravitystorm">@gravitystorm</a> has made some high level design comments in his review and will doubtless have more to say on the UI side before this is ready.</p><hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#discussion_r1477337085">app/controllers/users_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -70,13 +72,16 @@ def new
       # page, instead send them to the home page
       redirect_to @referer || { :controller => "site", :action => "index" }
     elsif params.key?(:auth_provider) && params.key?(:auth_uid)
+      @auth_uid = params[:auth_uid]
+      @auth_provider = params[:auth_provider]
</pre>
<p dir="auto">We're putting both of these in the user object we create which is accessible to the view so I'm not sure we need separate member variables as well?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#discussion_r1477338290">app/controllers/users_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -70,13 +72,16 @@ def new
       # page, instead send them to the home page
       redirect_to @referer || { :controller => "site", :action => "index" }
     elsif params.key?(:auth_provider) && params.key?(:auth_uid)
+      @auth_uid = params[:auth_uid]
+      @auth_provider = params[:auth_provider]
+      @verified_email = params[:verified_email]
+
       self.current_user = User.new(:email => params[:email],
</pre>
<p dir="auto">I realise it's not new but I'm worried about using <code class="notranslate">current_user</code> here because the general assumption is that <code class="notranslate">current_user</code> is the current signed in user and the user isn't signed up yet here so this probably needs to be <code class="notranslate">@user</code> or something instead - obviously that also needs changes to the view and to the login action as well. Maybe <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gravitystorm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gravitystorm">@gravitystorm</a> has more thoughts about whether using <code class="notranslate">current_user</code> is wise though?</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#discussion_r1477339735">app/controllers/users_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -290,8 +241,23 @@ def auth_success
         else
           failed_login t("sessions.new.auth failure")
         end
+      elsif user.nil? && user = User.find_by(:email => email)
</pre>
<p dir="auto">I don't think we need <code class="notranslate">user.nil?</code> here as we would have taken the previous branch if user was set.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#discussion_r1477340627">app/controllers/users_controller.rb</a>:</p>
<pre style='color:#555'>> @@ -290,8 +241,23 @@ def auth_success
         else
           failed_login t("sessions.new.auth failure")
         end
+      elsif user.nil? && user = User.find_by(:email => email)
+        user[:auth_uid] = uid
+        user[:auth_provider] = provider
+        user.save!
+
+        user.deactivate! if user.status == "active" && !email_verified
+
+        if user.status == "active"
+          successful_login(user)
+        else
+          session[:token] = user.tokens.create.token
+          UserMailer.signup_confirm(user, user.tokens.create(:referer => session[:referer])).deliver_later
+          redirect_to :controller => :confirmations, :action => :confirm, :display_name => user.display_name
+        end
</pre>
<p dir="auto">This is trying to deal with the case where somebody does a social signup and there is already an account with the email address the social provider returns and it looks problematic to me for a number of reasons:</p>
<ul dir="auto">
<li>If the user already had a different social provider attached to their account this will overwrite it</li>
<li>If the social provider satisfies our (deliberately weak) definition of providing a verified email then we allow them to attach to the existing account with no further verification but that is very different to allowing creation a new account based on a weak verification</li>
<li>If the social provider email is not considered verified then we send a normal signup confirmation but the working of that will be a bit odd in this case I think plus we actual deactivate the account until that confirmation happens</li>
</ul>
<p dir="auto">There's a definite problem here, that I had a case of only this week, where somebody tries a social signup and they already have an account but I think we need to send a confirmation email in all cases and probably make it a different one saying that we need to confirm the social signup link and just use it to confirm the link rather than doing a deactivate first.</p>
<p dir="auto">I'm not sure what to do where there is already a different provider attached though though arguably that's fine if we only change the auth provider after email confirmation and the email says we will be replacing the old one.</p>

<hr>

<p>In <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#discussion_r1477341956">app/models/user.rb</a>:</p>
<pre style='color:#555'>> @@ -181,11 +181,9 @@ def self.authenticate(options)
       transitions :from => :pending, :to => :active
     end
 
-    # Used in test suite, not something that we would normally need to do.
-    if Rails.env.test?
</pre>
<p dir="auto">This is only being removed so that we can deactivate while revalidating an auth id association and as explained above I don't think we can do that so this can then be left as is.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4455#pullrequestreview-1861453314">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLINTJKPORCMA4DTYJTYR6RIZAVCNFSM6AAAAABBLOL2OWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNRRGQ2TGMZRGQ">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJBPINWJPWJRX5KPPDYR6RIZA5CNFSM6AAAAABBLOL2OWWGG33NNVSW45C7OR4XAZNRKB2WY3CSMVYXKZLTORJGK5TJMV32UY3PNVWWK3TUL5UWJTTO6ODAE.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4455/review/1861453314</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4455#pullrequestreview-1861453314",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4455#pullrequestreview-1861453314",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>