Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Identifying User Idenity

Identifying User Idenity

Kaigi on Rails 2024 での発表資料です #kaigionrails

https://kaigionrails.org/2024/talks/moro/

MOROHASHI Kyosuke

October 26, 2024
Tweet

More Decks by MOROHASHI Kyosuke

Other Decks in Programming

Transcript

  1. ͜Ε\೚ҙͷϥΠϒϥϦ^ͰҰൃͰ͸ 🤔 w ͦΕ͸ͦ͏ɻ3BJMTͱͦͷΤίγεςϜศརͰ͢Ͷ w ͱ͸͍͑ର৅ྖҬΛΑ͘ཧղ͓ͯ͘͠ͱɺ ϥΠϒϥϦͱ΋ྑ͍ؔ܎ΛอͯΔ w ϥΠϒϥϦ͕΍ͬͯ͘ΕΔ͜ͱͱɺ΍ͬͯ͘Εͳ͍͜ͱ w

    αʔϏεཁٻ͕ϥΠϒϥϦͷػೳʹऩ·Βͳ͍ͱ͖ͷରॲ ;ͩΜʮ֓೦ѹॖʯ͍ͯ͠Δͱ͜Ζ΋ɺඞཁʹԠͯ͡ల։Ͱ͖ΔΑ͏ʹͳ͍ͬͯΔͱྑ͍ͱ͍͏͔
  2. ໊લ͸ ϝΞυ͸ w ໊લ΍ϝΞυ͸CFMPOHT@UPVTFSͳผςʔϒϧʹอଘ͢Δ w \ຊ໊ ϝΞυ ి࿩൪߸^ɺ\ࣗݾ঺հ χοΫωʔϜ^ͳͲɺ ৘ใͷੑ࣭͝ͱʹςʔϒϧΛ෼͚ͯ΋Α͍

    w αʔϏεͱͯ͠΍Γ͍ͨ͜ͱ࣍ୈ w OVMMBCMFͳΧϥϜ͕ݮΔΑ͏ʹ͢Δͱγϡοͱ͢Δ ผςʔϒϧʹ෼͚Δͱ͖ɺVTFS@JEʹ͸GL੍໿͚ͩ͡Όͳͯ͘ϢχʔΫ੍໿΋๨Εͣʹ ܦݧ͋Γʣ
  3. ྫ͑͹͜Μͳςʔϒϧ܈ users PK id human_id created_at user_profiles PK id FK

    user_id region favorite_editor favorite_method ... timestamps user_credentials PK id FK user_id email phone name password_digest ... timestamps
  4. ྫ͑͹͜Μͳ"3Ϟσϧ class User < ApplicationRecord has_one :credential, class_name: 'UserCredential' has_one

    :profile, class_name: 'UserProfile' end class UserCredential < ApplicationRecord belongs_to :user end class UserProfile < ApplicationRecord belongs_to :user end
  5. 3BJMT HFOFSBUFBVUIFOUJDBUJPO🤔 class CreateUsers < ActiveRecord::Migration[8.0] def change create_table :users

    do |t| t.string :email_address, null: false t.string :password_digest, null: false t.timestamps end add_index :users, :email_address, unique: true end end FNBJM@BEESFTT͕ͳ͍ͱVTFSʹͳΕͳ͍͔ɺͱ͍͏ͱͦΜͳ͜ͱ͸ͳ͍͜ͱ͕ଟ͍ͱࢥ͏ͷͰ͢ΑͶ
  6. DVSSFOU@VTFSͷΑ͋͘Δ࣮૷ w TFTTJPO<VTFS@JE>ʹVTFSTJE͕อଘ͞Ε͍ͯΔ w VTFSTςʔϒϧΛݕࡧ͠ɺ6TFSͷΠϯελϯεΛऔಘ͢Δ w ඇϩάΠϯதͳΒOJMΛฦ͢ w ίϯτϩʔϥ૚Ͱऔಘ͠ɺదٓϞσϧ΍Ϗϡʔʹ఻͑Δ w

    ΠϚυΩ͸"DUJWF4VQQPSU$VSSFOU"UUSJCVUF΋͍͍͔΋ɻ 3BJMT͸4FTTJPO"3#BTFͰ%#ʹอଘ͠ɺΫοΩʔʹ͸TFTTJPOTJEΛ࣋ͭΈ͍ͨɻ͜ͷͭ͘ΓͩͱαʔόଆͰͷ ηογϣϯແޮԽͱ͔΋ͭ͘Γ΍ͦ͢͏Ͱ͍͍Ͱ͢ͶɻΠϚυΩ͸ඞਢػೳ͔΋Ͱ͕͢ࠓ೔͸ͦͷ΁ΜলུͰ͢ɻ
  7. *%BB4΍ϥΠϒϥϦ΋࢖͑Δ w ྫ0NOJ"VUI w QSPWJEFSͱͦͷVJE QSPWJEFS͝ͱͷࣝผࢠ ΛೖΕΔςʔϒϧΛɺ CFMPOHT@UPVTFSͰ༻ҙ͓ͯ͘͠ɻ w ͦΕͧΕͷετϥςδʔ͕ೝূ݁ՌΛASFRVFTUFOW<PNOJBVUIBVUI>Aʹ

    ٧ΊͯίʔϧόοΫϝιουΛݺͿɻ w ίʔϧόοΫ಺ͰVJEΛݕࡧ͠ɺඥͮ͘ϢʔβʔΛऔಘ͢Δɻ w ֬ೝͰ͖ͨϢʔβʔͷ*%Ληογϣϯʹอଘ͢Δɻ
  8. ొ࿥தσʔλ6TFS3FHJTUSBUJPOϞσϧ w CFMPOHT@UPVTFS PQUJPOBMUSVF w ϝʔϧΞυϨε΍ࣄલௌऔͷΞϯέʔτͳͲ΋อଘͰ͖Δɻ w ߏ଄͸VTFSTͷϓϩϑΟʔϧ͕ೖΔςʔϒϧͱࣅΔɻ લड़ͷݸਓ৘ใΛ෼͚ΔςΫχοΫͳͲ΋࢖͑Δɻ w

    ֤߲໨ΛۭനՄʹ͓ͯ͘͠ͱʮ௕͍ొ࿥ϑΥʔϜͷ్தอଘʯʹରԠͰ͖Δɻ ࠷ऴεςοϓͰɺ׬ྃͰ͖Δ৘ใ͕଍Γ͍ͯΔ͔όϦσʔγϣϯ͢Δɻ w ϝʔϧ౸ୡ֬ೝͷͨΊͷτʔΫϯͳͲͷσʔλάϥϑ΋dSFHJTUSBUJPOTʹͿΒԼ͛Δɻ
  9. ྫ͑͹͜Μͳςʔϒϧ users PK id human_id created_at user_profiles user_credentials user_registrations PK

    id FK user_id (nullable) FK email_verification_id favorite_editor ... created_at user_registration_ credentials PK id FK user_registration_id email email_verifications PK id token expires_at
  10. ݸਓ৘ใ͸ফ͢͜ͱ͸Ͱ͖Δ w VTFSTϨίʔυ͸ফ͞ͳ͍͕ɺVTFS@DSFEFOUJBMT͸ফͤΔ w ౰ਓ͔͠஌Βͳ͍ΫϨσϯγϟϧͳͷͰαʔϏεͷ໨ۄػೳσʔλ͔Β ґଘ͞ΕͨΓ͍ͯ͠ͳ͍͸ͣɻ w ຊ໊ɺϝΞυɺి࿩൪߸ɺύεϫʔυ μΠδΣετ ͳͲ

    w ୀձޙʹ໊લΛද͍ࣔͨ͠ͱ͖͸ AVTFSDSFEFOUJBMOBNFcc ୀձࡁϢʔβʔ AΈ͍ͨͳ࣮૷΋ΞϦ w෭࣍తʹʮ༗ޮͳϝΞυి࿩൪߸ʯʹϢχʔΫ੍໿Λ͔͚ΒΕΔ ʰ࿦ཧ࡟আ͢Δͳͷձʱͷձһͱͯ͠͸ɺ࿦ཧ࡟আͩͱϢχʔΫ੍໿Λ͔͚ΒΕͳͯ͘ਏ͍ͳͱࢥ͍·͢ɻ
  11. ΋ͪΖΜ࣮૷΋׬શʹ෼͚Δ w Ұൠͷ6TFSϞσϧʹಛผͳॲཧΛ࡞ΔͷͰ͸ͳ͘ɺϞσϧΛ ׬શʹ෼͚Δ w 4UBGGϞσϧͳͲΛ࡞ͬͯɺ෼͚Δ TUBGGQMVSBMJ[FTUBGGT  w ؅ཧ༻ͷػೳ܈΋ɺઐ༻ʹ࡞ͬͯ͠·͏΄͏͕Α͍

    w ࠷ॳ͸໘౗͔΋͠Εͳ͍͚ͲɺγϏΞͳݖݶͷ੍ޚΛͣͬͱҙࣝ͠ଓ͚ΔΑΓ΋ָͳ͸ͣ ɻ w ʮαʔϏεͷ͍ΖΜͳӡӦۀ຿Λ͢ΔͨΊͷػೳ܈ʯͱͯͪ͠ΌΜͱ࡞Ζ͏ɻ ؅ཧը໘޷͖ͳΜͰ͢ΑͶɻ؅ཧը໘ͦΕࣗମͱ͍͏͔ɺͦΕΛ࢖ͬͯࣄۀΛҰॹʹ΍͍ͬͯΔਓͨͪͱͷ ؔ܎ੑ͕޷͖ɻ؅ཧը໘ͪΌΜͱ͢Δ͜ͱ΋·ͨҰͭͷਓؒؔ܎ͷΤΫααΠζͳΘ͚Ͱ͢Αɻ
  12. ࣮૷ͷΘ͚͔ͨ w ؅ཧऀͱͯ͠ͷΞΠσϯςΟςΟ΁ͷΞΫηα΋Θ͚Δ w ίϯτϩʔϥͷجఈΫϥεΛ෼͚ͯ΋͍͍͔΋ class StaffBaseController < ActionController::Base def

    current_staff return @current_staff if defiend?(@current_staff) @current_staff ||= Staff.find_by(id: session[:staff_id]) end def require_staff_login unless current_staff redirect_to :new_staff_session end
  13. ڥքͰΘ͚ͯվળ͍༷ͯ͘͠ࢠ users PK id human_id created_at user_profiles user_credentials user_registrations user_registration_

    credentials email_verifications email_change_requests organizations events attendances event_favorites org_favorites some_sns_uids
  14. ͦ͏͢Δͱͳʹ͕خ͍͠ͷ͔ w ʮϢʔβʔ؅ཧपΓʯ͸͍ΖΜͳෳࡶ͕͞ଘࡏ͢Δ w ͳʹͤେࣄͳΤϯςΟςΟͰ͔͢ΒͶɻ w ෳࡶͳͷ͸͔͕֬ͩɺݪଇʹԊͬͯ੔ཧͰ͖Δɻ ෆ߹ཧͰ͸ͳ͍͠ɺΉ͠Ζ͔͍͍ͬ͜ίʔυʹͰ͖ͯ໘ന͍ w ͍͍ײ͡ʹอͯΔͱɺαʔϏεͷ໨ۄػೳΛ৳͹͢໾ʹ΋ཱͯΔ

    w ΊͰͨ͠ΊͰͨ͠ɻ໘ന͍Ͱ͢Α 3BJMTΞϓϦͰ&3ਤࣗಈੜ੒͢ΔͱͭͷଠཅΈ͍ͨͳςʔϒϧ͕Ͱ͖͕ͪͰɺͻͱͭ͸໨ۄػೳͷத৺ɺ ΋͏Ұํ͕VTFSTͳΘ͚Ͱ͢ɻ͔Α͏ʹେࣄͳΤϯςΟςΟͳͷͰɺΑ͘ߟ͍͖͍͑ͯͨͰ͢Ͷɻ
  15. Ϣʔβʔঢ়ଶΛTUBUVTྻφγͰදݱͰ͖Δ w 6TFS3FHJTUSBUJPOTDPQFTVDDFFEFE \KPJOT VTFS ^ w 6TFS3FHJTUSBUJPOTDPQFFYQJSFE \ XIFSFNJTTJOH

    VTFS XIFSF DSFBUFE@BU/EBZTBHP  ^ w 6TFSTDPQFBDUJWF \KPJOT DSFEFOUJBM ^ w 6TFSTDPQFXJUIESBXO \XIFSFNJTTJOH DSFEFOUJBM ^ ಋग़Մೳͳঢ়ଶΛอ࣋͢ΔྻΛ૿΍ͣ͞ʹදݱͰ͖͍ͯɺ͘͢͝Α͘ͳ͍Ͱ͔͢