Skip to content

Commit

Permalink
Merge pull request #8272 from vpereira/migrate_session_controller_boo…
Browse files Browse the repository at this point in the history
…tstrap

Refactor SessionController routes, controller, views
  • Loading branch information
vpereira committed Sep 5, 2019
2 parents 9ac40a2 + 1ff0226 commit 6e9ae58
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 107 deletions.
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/session_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create

unless user
RabbitmqBus.send_to_bus('metrics', 'login,access_point=webui,failure=unauthenticated value=1')
redirect_to(session_new_path, error: 'Authentication failed')
redirect_to(new_session_path, error: 'Authentication failed')
return
end

Expand Down Expand Up @@ -59,6 +59,6 @@ def redirect_on_logout
end

def referer_was_login?
request.referer && request.referer.end_with?(session_new_path)
request.referer && request.referer.end_with?(new_session_path)
end
end
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/webui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def require_login
flash[:error] = 'Please login to access the requested page.'
mode = CONFIG['proxy_auth_mode'] || :off
if mode == :off
redirect_to session_new_path
redirect_to new_session_path
else
redirect_to root_path
end
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/views/layouts/webui/_personal_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
- else
= link_to 'Create Home', new_project_path(name: User.session!.home_project_name)
|
\#{link_to 'Logout', session_destroy_path, method: :delete, id: 'logout-link'}
\#{link_to 'Logout', session_path, method: :delete, id: 'logout-link'}
- elsif CONFIG['kerberos_mode']
= link_to 'Log In', session_new_path
= link_to 'Log In', new_session_path
- else
- if CONFIG['proxy_auth_mode'] == :on
- unless CONFIG['proxy_auth_register_page'].blank?
= link_to 'Sign Up', "#{CONFIG['proxy_auth_register_page']}?%22"
|
= link_to 'Log In', session_new_path, id: 'login-trigger'
= link_to 'Log In', new_session_path, id: 'login-trigger'
#login-form
= form_tag(CONFIG['proxy_auth_login_page'], method: :post, id: 'login_form', enctype: 'application/x-www-form-urlencoded') do
%p
Expand All @@ -43,9 +43,9 @@
- if can_register
= link_to 'Sign Up', user_register_user_path
|
= link_to 'Log In', session_new_path, id: 'login-trigger'
= link_to 'Log In', new_session_path, id: 'login-trigger'
#login-form
= form_tag(session_create_path) do
= form_tag(session_path, method: :post) do
%p
= label_tag(:username, 'Username')
= text_field_tag(:username, '')
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui/webui.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<% else %>
<li><%= link_to "Create Home Project", new_project_path(name: User.session!.home_project_name) %></li>
<% end %>
<li><%= link_to 'Logout', session_destroy_path, method: :delete %></li>
<li><%= link_to 'Logout', session_path, method: :delete %></li>
</ul>
</div>
<% end -%>
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui2/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%li= link_to('Home Project', project_show_path(User.session!.home_project))
- else
%li= link_to('Create Home Project', new_project_path(name: User.session!.home_project_name))
%li= link_to('Logout', session_destroy_path, method: :delete)
%li= link_to('Logout', session_path, method: :delete)
- if ::Configuration.anonymous
.col
%strong.text-uppercase Locations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
= link_to(new_project_path(name: User.session!.home_project_name), class: 'nav-link') do
Create Home
%li.nav-item
= link_to(session_destroy_path, method: :delete, id: 'logout-link', class: 'nav-link') do
= link_to(session_path, method: :delete, id: 'logout-link', class: 'nav-link') do
Logout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- if User.session
= render partial: 'layouts/webui2/logged_in_user_navigation'
- elsif CONFIG['kerberos_mode']
= link_to 'Log In', session_new_path
= link_to 'Log In', new_session_path
- elsif CONFIG['proxy_auth_mode'] == :on
= render partial: 'layouts/webui2/login_form', locals: { signup_url: "#{CONFIG['proxy_auth_register_page']}?%22",
form_url: CONFIG['proxy_auth_login_page'],
Expand All @@ -11,7 +11,7 @@
can_signup: CONFIG['proxy_auth_register_page'].present? }
- else
= render partial: 'layouts/webui2/login_form', locals: { signup_url: user_signup_path,
form_url: session_create_path,
form_url: session_path,
options: { method: :post },
proxy: false,
can_signup: can_register }
2 changes: 1 addition & 1 deletion src/api/app/views/webui/comment/_new.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- if !User.session
.alert.alert-warning{ role: 'alert' }
Login required, please
= link_to('login', session_new_url)
= link_to('login', new_session_url)
- if can_register
or
= link_to('signup', user_register_user_url)
Expand Down
42 changes: 21 additions & 21 deletions src/api/app/views/webui/session/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
.form#loginform{ title: "Account login" }
%h1= @pagetitle
%p
%label{ for: "user-login" } Username:
%input#user-login{ name: "username", size: "30", type: "text", value: "" }/
%br/
%br/
%label{ for: "user-password" } Password:
%input#user-password{ name: "password", size: "30", type: "password" }/
%p
%input.primary#log-in-button{ name: "login", type: "submit", value: "Log In" }/
%p
- if CONFIG['proxy_auth_mode'] == :on
Or
\#{link_to 'register', CONFIG['proxy_auth_register_page'] + '?%22'}
as a new user.
- else
- unless CONFIG['frontend_ldap_mode'] == :on
Or
= link_to("sign up", controller: :user, action: :register_user)
as a new user.
%h3= pagetitle

= form_tag(form_url, options) do
- if proxy
= hidden_field_tag(:context, 'default')
= hidden_field_tag(:proxypath, 'reserve')
= hidden_field_tag(:message, 'Please log in')
.form-group
= label_tag(:username, 'Username')
= text_field_tag(:username, nil, placeholder: 'User Name', required: true, id: 'user-login', class: 'form-control')
.form-group
= label_tag(:password, 'Password')
= password_field_tag(:password, nil, placeholder: 'Password', required: true, id: 'user-password', class: 'form-control')
= submit_tag('Log In', name: 'login', class: 'btn btn-primary')
%span
- if proxy
or
= link_to('Register', CONFIG['proxy_auth_register_page'] + '?%22')
- elsif CONFIG['frontend_ldap_mode'] != :on
or
= link_to('Sign Up', user_register_user_path)
38 changes: 19 additions & 19 deletions src/api/app/views/webui/session/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
- @pagetitle = "Please Log In"
- if CONFIG['proxy_auth_mode'] == :on
%form{ action: "#{CONFIG['proxy_auth_login_page']}", enctype: "application/x-www-form-urlencoded", method: "post" }
%div
%input{ name: "context", type: "hidden", value: "default" }/
%input{ name: "proxypath", type: "hidden", value: "reverse" }/
%input{ name: "message", type: "hidden", value: "Please log In" }/
= render partial: 'form'
- elsif CONFIG['kerberos_mode']
%h2
Kerberos authentication required
%div
%p
You are seeing this page, because you are not authenticated in the kerberos realm ('#{CONFIG['kerberos_realm']}').
%p
Please ensure you have a valid ticket and try again.
- else
= form_tag controller: :session, action: :create, method: :post do
= render partial: 'form'
- @pagetitle = 'Please Log In'

.card
.card-body#loginform
.col-lg-6.pl-0
- if CONFIG['proxy_auth_mode'] == :on
= render partial: 'form', locals: { form_url: CONFIG['proxy_auth_login_page'],
options: { method: :post, enctype: 'application/x-www-form-urlencoded' },
proxy: true,
pagetitle: @pagetitle }
- elsif CONFIG['kerberos_mode']
%h3 Kerberos authentication required
%p You are seeing this page, because you are not authenticated in the kerberos realm ('#{CONFIG['kerberos_realm']}').
%p Please ensure you have a valid ticket and try again.
- else
= render partial: 'form', locals: { form_url: session_path,
options: { method: :post },
proxy: false,
pagetitle: @pagetitle }
21 changes: 0 additions & 21 deletions src/api/app/views/webui2/webui/session/_form.html.haml

This file was deleted.

19 changes: 0 additions & 19 deletions src/api/app/views/webui2/webui/session/new.html.haml

This file was deleted.

6 changes: 1 addition & 5 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,7 @@ def self.public_or_about_path?(request)

resources :announcements, only: :show, controller: 'webui/announcements'

controller 'webui/session' do
get 'session/new' => :new
post 'session/create' => :create
delete 'session/destroy' => :destroy
end
resource :session, only: [:new, :create, :destroy], controller: 'webui/session'

get 'user/notifications' => :index, constraints: cons, controller: 'webui/users/subscriptions'
put 'user/notifications' => :update, constraints: cons, controller: 'webui/users/subscriptions'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/webui/project_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@
post :edit_comment, params: { project: user.home_project, package: package, text: text, last_comment: 'Last comment', format: 'js' }
end

it { expect(response).to redirect_to(session_new_path) }
it { expect(response).to redirect_to(new_session_path) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/webui/session_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

it 'tells users about wrong credentials' do
post :create, params: { username: user.login, password: 'password123' }
expect(response).to redirect_to session_new_path
expect(response).to redirect_to new_session_path
expect(flash[:error]).to eq('Authentication failed')
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/webui/webui_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def edit
describe 'require_login before filter' do
it 'redirects to main page for new users' do
get :show, params: { id: 1 }
expect(response).to redirect_to(session_new_path)
expect(response).to redirect_to(new_session_path)
expect(flash[:error]).to eq('Please login to access the requested page.')
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/features/webui/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

scenario 'login via login page' do
visit session_new_path
visit new_session_path

within('#loginform') do
fill_in 'username', with: user.login
Expand Down Expand Up @@ -96,7 +96,7 @@
end

it 'allows the user to login via the webui' do
visit session_new_path
visit new_session_path

within('#loginform') do
fill_in 'username', with: 'tux'
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/support/features/features_authentication.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FeaturesAuthentication
def login(user, password = 'buildservice')
visit session_new_path
visit new_session_path
expect(page).to have_text 'Please Log In'
within('#loginform') do
fill_in 'username', with: user.login
Expand All @@ -12,7 +12,7 @@ def login(user, password = 'buildservice')
end

def logout
visit session_destroy_path
visit session_path(method: :delete)
expect(page).to have_no_link('link-to-user-home')
User.session = nil
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def login_king(opts = {})
opts[:do_assert] = false
# no idea why calling it twice would help
WebMock.disable_net_connect!(allow_localhost: true)
visit session_new_path
visit new_session_path
within('#loginform') do
fill_in 'username', with: user
fill_in 'password', with: password
Expand Down

0 comments on commit 6e9ae58

Please sign in to comment.