Skip to content

Commit

Permalink
Remove useless redirection parameter when signin in
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas16 committed Oct 26, 2024
1 parent 05db797 commit a194b22
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 35 deletions.
5 changes: 2 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ def render_with_error(view, obj = nil, error = nil)
# Check that the user is signed in, and if not then redirect to the page "Please sign in to see this page"
def signed_in_user
unless signed_in?
store_location
flash[:danger] = "Vous devez être connecté pour accéder à cette page."
redirect_to signin_path
flash.now[:danger] = "Vous devez être connecté pour accéder à cette page."
render 'sessions/new' and return
end
end

Expand Down
8 changes: 2 additions & 6 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#encoding: utf-8
class SessionsController < ApplicationController
before_action :signed_in_user_danger, only: [:destroy]
before_action :signed_out_user, only: [:create, :new]

# Create a session, i.e. sign in (show the form)
def new
end
before_action :signed_out_user, only: [:create]

# Create a session, i.e. sign in (send the form)
def create
Expand All @@ -23,7 +19,7 @@ def create
@remember_me = params[:session][:remember_me].to_i
user.save
sign_in user
redirect_back_or(root_path) # This method works together with store_location inside signed_in_user, to redirect to the previous location
redirect_back(fallback_location: root_path)
else
flash[:danger] = "Vous devez activer votre compte via l'e-mail qui vous a été envoyé."
redirect_back(fallback_location: root_path)
Expand Down
15 changes: 0 additions & 15 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,4 @@ def sign_out
@current_user = nil
cookies.delete(:remember_token)
end

def redirect_back_or(default)
retour = session[:return_to]
session.delete(:return_to)
# On redirige vers la page "retour" si et seulement si on vient de la page signin!
if(retour and params[:redirection] == "/signin")
redirect_to(retour)
else
redirect_back(fallback_location: default)
end
end

def store_location
session[:return_to] = request.fullpath
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<!-- Formulaire pour se connecter -->
<ul class="dropdown-menu dropdown-menu-end">
<li class="p-3 pb-1">
<%= form_for(:session, url: sessions_path(redirection: request.original_fullpath)) do |f| %>
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.email_field :email, :placeholder => "Adresse e-mail", :class => "form-control", :style => "width:210px;", :id => "header_connect_email" %>
<%= f.password_field :password, :placeholder => "Mot de passe", :class => "form-control mt-2 mb-1", :style => " width:210px;", :id => "header_connect_password" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- On est redirigé ici si on essaye d'accéder à une page qui nécessite d'être connecté -->
<h1><%= title_1("Connexion") %></h1>

<%= form_for(:session, url: sessions_path(redirection: request.original_fullpath)) do |f| %>
<%= form_for(:session, url: sessions_path) do |f| %>
<div class="mb-2">
<%= f.label :email, :class => "form-label" %>
<%= f.email_field :email, :class => "form-control", :style => "width:200px;", :id => "connect_email" %>
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@
end

# Sessions
resources :sessions, only: [:new, :create, :destroy]
match '/signin', to: 'sessions#new', :via => [:get]
resources :sessions, only: [:create, :destroy]
match '/signout', to: 'sessions#destroy', via: :delete

# Static pages
Expand Down
8 changes: 4 additions & 4 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:

# GPTBot makes too many requests.
User-Agent: GPTBot
Disallow: /

# A lot of /users/ and /users pages, so too many requests.
# The /sessions page does not exist but is often wrongly
# visited because of the form to connect on each page.
User-Agent: *
Disallow: /users/
Disallow: /users
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/contestproblems_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

it "renders the sign in page for show" do
get :show, params: {id: contestproblem.id}
expect(response).to redirect_to signin_path
expect(response).to render_template 'sessions/new'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/contests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

it "renders the error page for unfollow" do
get :unfollow, params: {contest_id: contest.id}
expect(response).to redirect_to signin_path
expect(response).to render_template 'sessions/new'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/discussions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
context "if the user is not signed in" do
it "renders the error page for new" do
get :new
expect(response).to redirect_to signin_path
expect(response).to render_template 'sessions/new'
end
end

Expand Down

0 comments on commit a194b22

Please sign in to comment.