-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from ZeusWPI/feature/521/dummy-dev-login
Feature/521/dummy dev login
- Loading branch information
Showing
6 changed files
with
73 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class UsersController < ApplicationController | ||
before_filter :restrict_to_development | ||
|
||
def login | ||
u = User.find_or_create_by(username: "tnnaesse", admin: true) | ||
u.clubs = Club.where(internal_name: 'zeus') | ||
sign_in(u) | ||
|
||
redirect_to '/' | ||
end | ||
|
||
protected | ||
# this method should be placed in ApplicationController | ||
def restrict_to_development | ||
head(:bad_request) unless Rails.env.development? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="navbar-form <%= classes %>"> | ||
<div class="form-group"> | ||
<% if user_signed_in? %> | ||
<div class="form-group"> | ||
<%= button_to "Logout", destroy_user_session_path(current_user), class: "btn btn-default form-control", method: :delete %> | ||
</div> | ||
<% else %> | ||
<div class="form-group"> | ||
<div class="button-group"> | ||
<%= button_to "Login", new_user_session_path, class: "btn btn-success form-control" %> | ||
</div> | ||
</div> | ||
<% if Rails.env.development? %> | ||
<div class="form-group"> | ||
<div class="button-group"> | ||
<%= button_to "Login (dev)", dev_login_path, class: "btn form-control" %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'test_helper' | ||
|
||
class UsersControllerTest < ActionController::TestCase | ||
test "developer backdoor doesnt work in production" do | ||
stub_env "production" do | ||
assert Rails.env.production? | ||
# Not actually a decent assert as the route didn't exist | ||
# before the environment change as the routes gets also | ||
# skipped in the current test environment ¯\_(ツ)_/¯ | ||
assert_raises(ActionController::UrlGenerationError) do | ||
post :dev_login | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters