Class: HasSecurePasskey::PasskeysGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/has_secure_passkey/passkeys/passkeys_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_migrationsObject



54
55
56
57
58
# File 'lib/generators/has_secure_passkey/passkeys/passkeys_generator.rb', line 54

def add_migrations
  generate "migration", "CreatePeople", "email_address:string!:uniq webauthn_id:string!", "--force"
  generate "migration", "CreateSessions", "person:references ip_address:string user_agent:string", "--force"
  generate "migration", "CreatePasskeys", "authenticatable:references{polymorphic} external_id:string public_key:string sign_count:integer last_used_at:datetime name:string", "--force"
end

#configure_application_controllerObject



41
42
43
# File 'lib/generators/has_secure_passkey/passkeys/passkeys_generator.rb', line 41

def configure_application_controller
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController", "  include Authentication\n"
end

#configure_passkey_routesObject



45
46
47
48
49
50
51
52
# File 'lib/generators/has_secure_passkey/passkeys/passkeys_generator.rb', line 45

def configure_passkey_routes
  route "resource :sessions, only: :destroy"
  route "resources :sessions, only: :create"
  route "resources :people, only: :create"
  route "resources :email_verifications, only: :show, param: :webauthn_message"
  route "resource :registration, only: %i(new create)"
  route "mount HasSecurePasskey::Engine => \"/has_secure_passkey\""
end

#create_passkey_filesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/has_secure_passkey/passkeys/passkeys_generator.rb', line 6

def create_passkey_files
  template "app/models/session.rb"
  template "app/models/person.rb"
  template "app/models/current.rb"
  template "app/models/passkey.rb"

  template "app/controllers/concerns/authentication.rb"

  template "app/controllers/registrations_controller.rb"
  template "app/views/registrations/create.turbo_stream.erb"
  template "app/views/registrations/new.html.erb"

  template "app/controllers/email_verifications_controller.rb"
  template "app/views/email_verifications/show.html.erb"

  template "app/controllers/people_controller.rb"

  template "app/controllers/sessions_controller.rb"

  template "app/channels/application_cable/connection.rb" if defined?(ActionCable::Engine)

  template "app/mailers/email_verification_mailer.rb"

  template "app/views/email_verification_mailer/verify.html.erb"
  template "app/views/email_verification_mailer/verify.text.erb"

  template "test/mailers/previews/email_verification_mailer_preview.rb"

  append_to_file "app/javascript/application.js", "import \"has_secure_passkey\"\n"

  insert_into_file "config/environments/development.rb", "  config.x.url = \"http://localhost:3000\"\n", after: "Rails.application.configure do\n"
  insert_into_file "config/environments/test.rb", "  config.x.url = \"http://example.com\"\n", after: "Rails.application.configure do\n"
  insert_into_file "config/environments/production.rb", "  config.x.url = \"https://example.com\"\n", after: "Rails.application.configure do\n"
end