-
Notifications
You must be signed in to change notification settings - Fork 1
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 #101 from GSA/22/user-can-login-via-rails
[22 | 24] Users can login/logout via Rails app
- Loading branch information
Showing
20 changed files
with
472 additions
and
127 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
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 |
---|---|---|
@@ -1,4 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::Base | ||
helper_method :current_user, :logged_in? | ||
|
||
def current_user | ||
return unless session[:userinfo] | ||
|
||
user_token = session["userinfo"][0]["sub"] | ||
@current_user ||= User.find_by(token: user_token) if user_token | ||
end | ||
|
||
def logged_in? | ||
!!current_user | ||
end | ||
|
||
def sign_in(login_userinfo) | ||
user = User.user_from_userinfo(login_userinfo) | ||
|
||
@current_user = user | ||
session[:userinfo] = login_userinfo | ||
end | ||
|
||
def sign_out | ||
@current_user = nil | ||
session.delete(:userinfo) | ||
end | ||
|
||
def redirect_if_logged_in(path = "/dashboard") | ||
return unless logged_in? | ||
|
||
redirect_to path, notice: I18n.t("already_logged_in_notice") | ||
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class DashboardController < ApplicationController | ||
def index; 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
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,9 @@ | ||
<div class="usa-card__container custom-card col-md-6 rules-of-behavior"> | ||
<div class="usa-card__body"> | ||
<% if logged_in? %> | ||
Logged In Dashboard Index | ||
<% else %> | ||
Logged Out Dashboard Index | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<header class="usa-header usa-header--basic margin-bottom-2"> | ||
<div class="usa-nav-container"> | ||
<div class="usa-navbar"> | ||
<div class="usa-logo"> | ||
<em class="usa-logo__text"> | ||
<a href="/" title="Challenge Platform">Challenge Platform</a> | ||
</em> | ||
</div> | ||
</div> | ||
<nav aria-label="Primary navigation" class="usa-nav"> | ||
<% if logged_in? %> | ||
<%= button_to("Logout", session_path, method: :delete, class: "usa-button usa-nav-link", type: "button") %> | ||
<% else %> | ||
<%= button_to("Login", new_session_path, method: :get, class: "usa-button usa-nav-link", type: "button") %> | ||
<% end %> | ||
</nav> | ||
</div> | ||
</header> |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
</head> | ||
|
||
<body> | ||
<%= render "layouts/header" %> | ||
<%= yield %> | ||
</body> | ||
</html> |
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
Oops, something went wrong.