forked from External/greenlight
		
	Users are redirected to the url they clicked login/signup from (#446)
This commit is contained in:
		
				
					committed by
					
						 Jesus Federico
						Jesus Federico
					
				
			
			
				
	
			
			
			
						parent
						
							d39a11059e
						
					
				
				
					commit
					a14007743f
				
			| @@ -15,6 +15,11 @@ | ||||
| // with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. | ||||
|  | ||||
| $(document).on('turbolinks:load', function(){ | ||||
|   // Stores the current url when the user clicks the sign in button | ||||
|   $(".sign-in-button").click(function(){ | ||||
|     document.cookie ="return_to=" + window.location.href | ||||
|   }) | ||||
|  | ||||
|   // Checks to see if the user provided an image url and displays it if they did | ||||
|   $("#user-image") | ||||
|     .on("load", function() { | ||||
|   | ||||
| @@ -32,7 +32,17 @@ module SessionsHelper | ||||
|   # If email verification is disabled, or the user has verified, go to their room | ||||
|   def check_email_verified(user) | ||||
|     if user.activated? | ||||
|       redirect_to user.main_room | ||||
|       # Get the url to redirect the user to | ||||
|       url = if cookies[:return_to] && cookies[:return_to] != root_url | ||||
|         cookies[:return_to] | ||||
|       else | ||||
|         user.main_room | ||||
|       end | ||||
|  | ||||
|       # Delete the cookie if it exists | ||||
|       cookies.delete :return_to if cookies[:return_to] | ||||
|  | ||||
|       redirect_to url | ||||
|     else | ||||
|       redirect_to resend_path | ||||
|     end | ||||
|   | ||||
| @@ -59,15 +59,15 @@ | ||||
|         <% else %> | ||||
|           <% allow_greenlight_accounts = allow_greenlight_accounts? %> | ||||
|           <% if Rails.configuration.omniauth_ldap %> | ||||
|             <%= link_to t("login"), omniauth_login_url(:ldap), :class => "btn btn-pill btn-outline-primary mx-2" %> | ||||
|             <%= link_to t("login"), omniauth_login_url(:ldap), :class => "btn btn-pill btn-outline-primary mx-2 sign-in-button" %> | ||||
|           <% elsif allow_greenlight_accounts %> | ||||
|             <%= link_to t("login"), "#loginModal", :class => "btn btn-pill btn-outline-primary mx-2", "data-toggle": "modal" %> | ||||
|             <%= link_to t("login"), "#loginModal", :class => "btn btn-pill btn-outline-primary mx-2 sign-in-button", "data-toggle": "modal" %> | ||||
|           <% else %> | ||||
|             <%= link_to t("login"), omniauth_login_url(:bn_launcher), :class => "btn btn-pill btn-outline-primary mx-2" %> | ||||
|             <%= link_to t("login"), omniauth_login_url(:bn_launcher), :class => "btn btn-pill btn-outline-primary mx-2 sign-in-button" %> | ||||
|           <% end %> | ||||
|  | ||||
|           <% if allow_user_signup? && allow_greenlight_accounts %> | ||||
|             <%= link_to t("signup.title"), signup_path, :class => "btn btn-pill btn-outline-primary mx-2" %> | ||||
|             <%= link_to t("signup.title"), signup_path, :class => "btn btn-pill btn-outline-primary mx-2 sign-in-button" %> | ||||
|           <% end %> | ||||
|  | ||||
|           <%= render "shared/modals/login_modal" %> | ||||
|   | ||||
| @@ -89,6 +89,57 @@ describe SessionsController, type: :controller do | ||||
|       expect(@request.session[:user_id]).to be_nil | ||||
|       expect(response).to redirect_to(account_activation_path(email: @user3.email)) | ||||
|     end | ||||
|  | ||||
|     it "redirects the user to the page they clicked sign in from" do | ||||
|       user = create(:user, provider: "greenlight", | ||||
|         password: "example", password_confirmation: 'example') | ||||
|  | ||||
|       url = Faker::Internet.domain_name | ||||
|  | ||||
|       @request.cookies[:return_to] = url | ||||
|  | ||||
|       post :create, params: { | ||||
|         session: { | ||||
|           email: user.email, | ||||
|           password: 'example', | ||||
|         }, | ||||
|       } | ||||
|  | ||||
|       expect(@request.session[:user_id]).to eql(user.id) | ||||
|       expect(response).to redirect_to(url) | ||||
|     end | ||||
|  | ||||
|     it "redirects the user to their home room if they clicked the sign in button from root" do | ||||
|       user = create(:user, provider: "greenlight", | ||||
|         password: "example", password_confirmation: 'example') | ||||
|  | ||||
|       @request.cookies[:return_to] = root_url | ||||
|  | ||||
|       post :create, params: { | ||||
|         session: { | ||||
|           email: user.email, | ||||
|           password: 'example', | ||||
|         }, | ||||
|       } | ||||
|  | ||||
|       expect(@request.session[:user_id]).to eql(user.id) | ||||
|       expect(response).to redirect_to(user.main_room) | ||||
|     end | ||||
|  | ||||
|     it "redirects the user to their home room if return_to cookie doesn't exist" do | ||||
|       user = create(:user, provider: "greenlight", | ||||
|         password: "example", password_confirmation: 'example') | ||||
|  | ||||
|       post :create, params: { | ||||
|         session: { | ||||
|           email: user.email, | ||||
|           password: 'example', | ||||
|         }, | ||||
|       } | ||||
|  | ||||
|       expect(@request.session[:user_id]).to eql(user.id) | ||||
|       expect(response).to redirect_to(user.main_room) | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "GET/POST #omniauth" do | ||||
|   | ||||
		Reference in New Issue
	
	Block a user