forked from External/greenlight
GRN2-155: Begin preparing for removal of Twitter accounts (#615)
* Add twitter deprecation message * Fix rspec test * Extract room switch to its own method * update method name
This commit is contained in:
committed by
Jesus Federico
parent
a3158b5872
commit
40b05b1626
@ -51,6 +51,10 @@ class SessionsController < ApplicationController
|
||||
@auth = request.env['omniauth.auth']
|
||||
@user_exists = check_user_exists
|
||||
|
||||
if !@user_exists && @auth['provider'] == "twitter"
|
||||
return redirect_to root_path, flash: { alert: I18n.t("registration.deprecated.twitter_signup") }
|
||||
end
|
||||
|
||||
# If using invitation registration method, make sure user is invited
|
||||
return redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless passes_invite_reqs
|
||||
|
||||
@ -70,6 +74,16 @@ class SessionsController < ApplicationController
|
||||
invite_registration && !@user_exists
|
||||
|
||||
login(user)
|
||||
|
||||
if @auth['provider'] == "twitter"
|
||||
flash[:alert] = if allow_user_signup? && allow_greenlight_accounts?
|
||||
I18n.t("registration.deprecated.twitter_signin",
|
||||
link: signup_path(old_twitter_user_id: user.id))
|
||||
else
|
||||
I18n.t("registration.deprecated.twitter_signin",
|
||||
link: signin_path(old_twitter_user_id: user.id))
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
logger.error "Error authenticating via omniauth: #{e}"
|
||||
omniauth_fail
|
||||
|
@ -62,6 +62,10 @@ class UsersController < ApplicationController
|
||||
|
||||
# GET /signin
|
||||
def signin
|
||||
unless params[:old_twitter_user_id].nil? && session[:old_twitter_user_id].nil?
|
||||
flash[:alert] = I18n.t("registration.deprecated.new_signin")
|
||||
session[:old_twitter_user_id] = params[:old_twitter_user_id] unless params[:old_twitter_user_id].nil?
|
||||
end
|
||||
end
|
||||
|
||||
# GET /signup
|
||||
@ -75,6 +79,12 @@ class UsersController < ApplicationController
|
||||
session[:invite_token] = params[:invite_token]
|
||||
end
|
||||
|
||||
unless params[:old_twitter_user_id].nil? && session[:old_twitter_user_id].nil?
|
||||
logout
|
||||
flash.now[:alert] = I18n.t("registration.deprecated.new_signin")
|
||||
session[:old_twitter_user_id] = params[:old_twitter_user_id] unless params[:old_twitter_user_id].nil?
|
||||
end
|
||||
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
@ -175,7 +185,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def ensure_unauthenticated
|
||||
redirect_to current_user.main_room if current_user
|
||||
redirect_to current_user.main_room if current_user && params[:old_twitter_user_id].nil?
|
||||
end
|
||||
|
||||
def user_params
|
||||
|
@ -33,7 +33,11 @@ module ApplicationHelper
|
||||
|
||||
# Determines which providers can show a login button in the login modal.
|
||||
def iconset_providers
|
||||
configured_providers & [:google, :twitter, :microsoft_office365]
|
||||
providers = configured_providers & [:google, :twitter, :microsoft_office365]
|
||||
|
||||
providers.delete(:twitter) if session[:old_twitter_user_id]
|
||||
|
||||
providers
|
||||
end
|
||||
|
||||
# Generates the login URL for a specific provider.
|
||||
|
@ -19,6 +19,8 @@
|
||||
module SessionsHelper
|
||||
# Logs a user into GreenLight.
|
||||
def login(user)
|
||||
migrate_twitter_user(user)
|
||||
|
||||
session[:user_id] = user.id
|
||||
|
||||
# If there are not terms, or the user has accepted them, check for email verification
|
||||
@ -97,4 +99,24 @@ module SessionsHelper
|
||||
hd_opts
|
||||
end
|
||||
end
|
||||
|
||||
def migrate_twitter_user(user)
|
||||
if !session["old_twitter_user_id"].nil? && user.provider != "twitter"
|
||||
old_user = User.find(session["old_twitter_user_id"])
|
||||
|
||||
old_user.rooms.each do |room|
|
||||
room.owner = user
|
||||
|
||||
room.name = "Old " + room.name if room.id == old_user.main_room.id
|
||||
|
||||
room.save!
|
||||
end
|
||||
|
||||
# Query for the old user again so the migrated rooms don't get deleted
|
||||
old_user.reload
|
||||
old_user.destroy!
|
||||
|
||||
session["old_twitter_user_id"] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,17 +17,17 @@
|
||||
<% if key.eql? "success" %>
|
||||
<div class="alert alert-success alert-dismissible text-center mb-0">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<%= value %>
|
||||
<%= value.html_safe %>
|
||||
</div>
|
||||
<% elsif key.eql? "alert" %>
|
||||
<div class="alert alert-danger alert-dismissible text-center mb-0">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<%= value %>
|
||||
<%= value.html_safe %>
|
||||
</div>
|
||||
<% elsif key.eql? "info" %>
|
||||
<div class="alert alert-info alert-dismissible text-center mb-0">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<%= value %>
|
||||
<%= value.html_safe %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
Reference in New Issue
Block a user