forked from alphagov/e-petitions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove database authentication and replace with omniauth
- Loading branch information
Showing
23 changed files
with
104 additions
and
498 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Admin::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
skip_before_action :require_admin | ||
skip_before_action :verify_authenticity_token, only: %i[developer] | ||
|
||
def developer | ||
@user = AdminUser.find_by(email: omniauth_hash["uid"]) | ||
|
||
if @user.present? | ||
sign_in_and_redirect @user, event: :authentication | ||
set_flash_message(:notice, :signed_in) if is_navigational_format? | ||
else | ||
redirect_to admin_login_url, alert: :invalid_login | ||
end | ||
end | ||
|
||
private | ||
|
||
def after_omniauth_failure_path_for(scope) | ||
admin_login_url | ||
end | ||
|
||
def omniauth_hash | ||
request.env["omniauth.auth"] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
<h1>Sign in</h1> | ||
<div class="grid-row"> | ||
<div class="column-half"> | ||
<%= form_for(resource, as: resource_name, url: admin_login_path) do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :email, "Email", class: "form-label" %> | ||
<%= f.text_field :email, :class => 'form-control', :type => 'email', :autofocus => 'autofocus' %> | ||
</div> | ||
<div class="form-group"> | ||
<%= f.label :password, "Password", class: "form-label" %> | ||
<%= f.password_field :password, :class => 'form-control' %> | ||
</div> | ||
<%= f.submit 'Sign in', :class => 'button' %> | ||
<%= form_tag(admin_auth_developer_path, method: :post) do %> | ||
<button type="submit" class="button">Login with developer strategy</button> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
OmniAuth.configure do |config| | ||
config.logger = Rails.logger | ||
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
Oops, something went wrong.