Class: JwtRailsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/jwt_rails/jwt_rails_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_jwt_rails_fileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/jwt_rails/jwt_rails_generator.rb', line 4

def copy_jwt_rails_file
  # Use Json Web Token (JWT) for token based authentication
  gem 'jwt'
  # Use ActiveModel has_secure_password
  gem 'bcrypt', '~> 3.1.7'

  route "resources :users, param: :_username"
  route "post '/auth/login', to: 'authentication#login'"
  route "get '/*a', to: 'application#not_found'"

  copy_file "json_web_token.rb", "lib/json_web_token.rb"
  copy_file "application_controller.rb", "app/controllers/application_controller.rb"

  generate "model", "user name:string username:string email:string password_digest:string"
  copy_file "user.rb", "app/models/user.rb"
  generate "controller", "users"
  copy_file "users_controller.rb", "app/controllers/users_controller.rb"
  generate "controller", "authentication"
  copy_file "authentication_controller.rb", "app/controllers/authentication_controller.rb"

  puts "Genenrate Finish"
end