forked from OpenNeo/impress
Track neopass_email
when logging in with NeoPass
Gonna use this in the Settings UI to communicate what NeoPass you're connected to!
This commit is contained in:
parent
82aea20679
commit
d5c3bc087e
3 changed files with 18 additions and 1 deletions
|
@ -45,6 +45,8 @@ class AuthUser < AuthRecord
|
|||
|
||||
transaction do
|
||||
find_or_create_by!(provider: auth.provider, uid: auth.uid) do |user|
|
||||
# This account is new! Let's do the initial setup.
|
||||
|
||||
# TODO: Can we somehow get the Neopets username if one exists, instead
|
||||
# of just using total randomness?
|
||||
user.name = build_unique_username
|
||||
|
@ -55,6 +57,15 @@ class AuthUser < AuthRecord
|
|||
# password recovery!)
|
||||
email_exists = AuthUser.where(email: auth.info.email).exists?
|
||||
user.email = auth.info.email unless email_exists
|
||||
end.tap do |user|
|
||||
# Additionally, whether this account is new or existing, make sure
|
||||
# we've saved the latest email to `neopass_email`.
|
||||
#
|
||||
# We track this separately from `email`, which the user can edit, to
|
||||
# use in the Settings UI to indicate what NeoPass you're linked to. (In
|
||||
# practice, this *shouldn't* ever change after initial setup, because
|
||||
# NeoPass emails are immutable? But why not be resilient!)
|
||||
user.update!(neopass_email: auth.info.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddNeoPassEmailToUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :users, :neopass_email, :string
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_04_01_124406) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_04_07_135246) do
|
||||
create_table "users", id: { type: :integer, unsigned: true }, charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
|
||||
t.string "name", limit: 30, null: false
|
||||
t.string "encrypted_password", limit: 64
|
||||
|
@ -31,6 +31,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_04_01_124406) do
|
|||
t.datetime "remember_created_at"
|
||||
t.string "provider"
|
||||
t.string "uid"
|
||||
t.string "neopass_email"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
|
||||
|
|
Loading…
Reference in a new issue