Skip to content

Commit

Permalink
save which auth method was used to user record and use ppy_logout if …
Browse files Browse the repository at this point in the history
…Passport York was used to login
  • Loading branch information
amtuannguyen committed Jan 7, 2025
1 parent a090c2a commit 4a58f15
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/lib/warden/barcode_auth_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ def authenticate!
Rails.logger.debug "random generated password #{random}"
local_user = User.create! username: alma_user.primary_id, password: random,
yorku_id: univ_id, email: email,
first_name: alma_user.first_name, last_name: alma_user.last_name
first_name: alma_user.first_name, last_name: alma_user.last_name,
auth_method: self.class.name
else
Rails.logger.debug "Updating username=#{alma_user.primary_id} yorku_id=#{univ_id} email=#{email}"
local_user.username = alma_user.primary_id
local_user.yorku_id = univ_id
local_user.email = email
local_user.auth_method = self.class.name
local_user.save
end

Expand Down
4 changes: 3 additions & 1 deletion app/lib/warden/ppy_auth_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ def authenticate!
Rails.logger.debug "random generated password #{random}"
local_user = User.create! username: alma_user.primary_id, password: random,
yorku_id: univ_id, email: email,
first_name: alma_user.first_name, last_name: alma_user.last_name
first_name: alma_user.first_name, last_name: alma_user.last_name,
auth_method: self.class.name
else
Rails.logger.debug "Updating username=#{alma_user.primary_id} yorku_id=#{univ_id} email=#{email}"
local_user.username = alma_user.primary_id
local_user.yorku_id = univ_id
local_user.email = email
local_user.auth_method = self.class.name
local_user.save
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/shared/top_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</li>
<% end %>
<li class="nav-item">
<%= link_to 'Logout', destroy_user_session_path, class: "nav-link" %>
<%= link_to 'Logout', current_user.auth_method == 'Warden::PpyAuthStrategy' ? ppy_logout_path : destroy_user_session_path, class: "nav-link" %>
</li>
</ul>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250107110450_add_auth_method_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAuthMethodToUser < ActiveRecord::Migration[7.0]
def change
add_column :users, :auth_method, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_11_20_101610) do
ActiveRecord::Schema[7.0].define(version: 2025_01_07_110450) do
create_table "alma_fees", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "fee_id"
t.string "fee_type"
Expand Down Expand Up @@ -119,6 +119,7 @@
t.datetime "became_admin_at"
t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at"
t.string "auth_method"
t.index ["yorku_id"], name: "index_users_on_yorku_id", unique: true
end

Expand Down

0 comments on commit 4a58f15

Please sign in to comment.