Skip to content

Commit

Permalink
Make basic Developer Strategy work
Browse files Browse the repository at this point in the history
Things like redirecting back still don't work though
  • Loading branch information
danidoni committed Feb 8, 2024
1 parent 00d7939 commit b50075c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ gem 'chartkick'
# For tracking changes in models
gem 'paper_trail'

# For authenticating users
gem 'omniauth'
gem "omniauth-rails_csrf_protection"

# FIXME: Required by the mail gem
# See https://github.com/rails/rails/pull/44083
gem 'net-smtp', require: false
Expand Down
10 changes: 10 additions & 0 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ GEM
rubocop (>= 1.0)
sysexits (~> 1.1)
hashdiff (1.1.0)
hashie (5.0.0)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
Expand Down Expand Up @@ -298,6 +299,13 @@ GEM
base64
faraday (>= 1, < 3)
sawyer (~> 0.9)
omniauth (2.1.2)
hashie (>= 3.4.6)
rack (>= 2.2.3)
rack-protection
omniauth-rails_csrf_protection (1.0.1)
actionpack (>= 4.2)
omniauth (~> 2.0)
paper_trail (15.1.0)
activerecord (>= 6.1)
request_store (~> 1.4)
Expand Down Expand Up @@ -588,6 +596,8 @@ DEPENDENCIES
next_rails
nokogiri
octokit
omniauth
omniauth-rails_csrf_protection
paper_trail
pry
pry-byebug
Expand Down
6 changes: 6 additions & 0 deletions src/api/app/views/layouts/webui/_login_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
= password_field_tag(:password, nil, required: true, class: 'form-control', placeholder: 'Password')
.clearfix
= submit_tag('Log In', class: 'btn btn-success w-100')
.login-separator.text-center
%hr.my-4
%span.bg-modal.px-3.text-muted or
= form_tag('/auth/developer', method: 'post', data: { turbo: false }) do
%button{class: 'btn btn-primary', type: 'submit'}
Login with Developer Strategy
- if can_sign_up?
.login-separator.text-center
%hr.my-4
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/views/webui/session/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
- else
%h3= @pagetitle
= render partial: 'form', locals: { with_sign_up: true, with_redirect: true }
= form_tag('/auth/developer', method: 'post', data: { turbo: false }) do
%button{class: 'btn btn-primary', type: 'submit'}
Login with Developer Strategy
7 changes: 7 additions & 0 deletions src/api/config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Rails.application.config.middleware.use OmniAuth::Builder do
unless Rails.env.production?
provider :developer,
:fields => [:username, :password],
:uid_field => :username
end
end
4 changes: 4 additions & 0 deletions src/api/config/routes/webui_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@
end
end

get 'auth/:provider', to: 'webui/session#new'
# By default Omniauth redirects back to here
get 'auth/:provider/callback', to: 'webui/session#create'

scope :my do
resources :tasks, only: [:index], controller: 'webui/users/tasks', as: :my_tasks

Expand Down
Binary file added src/api/vendor/cache/hashie-5.0.0.gem
Binary file not shown.
Binary file added src/api/vendor/cache/omniauth-2.1.2.gem
Binary file not shown.
Binary file not shown.

0 comments on commit b50075c

Please sign in to comment.