├── .gitattributes
├── .gitignore
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── channels
│ └── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
├── controllers
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ ├── members_controller.rb
│ ├── posts_controller.rb
│ ├── registrations_controller.rb
│ └── sessions_controller.rb
├── images
│ ├── rails.png
│ └── s.png
├── jobs
│ └── application_job.rb
├── mailers
│ └── application_mailer.rb
├── models
│ ├── application_record.rb
│ ├── concerns
│ │ └── .keep
│ ├── jwt_denylist.rb
│ ├── post.rb
│ └── user.rb
└── views
│ └── layouts
│ ├── mailer.html.erb
│ └── mailer.text.erb
├── bin
├── bundle
├── rails
├── rake
├── setup
└── spring
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── application_controller_renderer.rb
│ ├── backtrace_silencers.rb
│ ├── cors.rb
│ ├── devise.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ └── wrap_parameters.rb
├── locales
│ ├── devise.en.yml
│ └── en.yml
├── puma.rb
├── routes.rb
├── spring.rb
└── storage.yml
├── db
├── migrate
│ ├── 20210719192747_devise_create_users.rb
│ ├── 20210719202728_create_jwt_denylist.rb
│ ├── 20210722104524_create_posts.rb
│ └── 20210722110151_add_user_to_posts.rb
├── schema.rb
└── seeds.rb
├── lib
└── tasks
│ └── .keep
├── log
└── .keep
├── public
└── robots.txt
├── storage
└── .keep
├── test
├── channels
│ └── application_cable
│ │ └── connection_test.rb
├── controllers
│ ├── .keep
│ └── posts_controller_test.rb
├── fixtures
│ ├── files
│ │ └── .keep
│ ├── posts.yml
│ └── users.yml
├── integration
│ └── .keep
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── post_test.rb
│ └── user_test.rb
└── test_helper.rb
├── tmp
├── .keep
└── pids
│ └── .keep
└── vendor
└── .keep
/.gitattributes:
--------------------------------------------------------------------------------
1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2 |
3 | # Mark the database schema as having been generated.
4 | db/schema.rb linguist-generated
5 |
6 |
7 | # Mark any vendored files as having been vendored.
8 | vendor/* linguist-vendored
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 | .env
10 |
11 | # Ignore the default SQLite database.
12 | /db/*.sqlite3
13 | /db/*.sqlite3-*
14 |
15 | # Ignore all logfiles and tempfiles.
16 | /log/*
17 | /tmp/*
18 | !/log/.keep
19 | !/tmp/.keep
20 |
21 | # Ignore pidfiles, but keep the directory.
22 | /tmp/pids/*
23 | !/tmp/pids/
24 | !/tmp/pids/.keep
25 |
26 | # Ignore uploaded files in development.
27 | /storage/*
28 | !/storage/.keep
29 | .byebug_history
30 |
31 | # Ignore master key for decrypting credentials and more.
32 | /config/master.key
33 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 3.0.0
2 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5 |
6 | ruby '3.0.0'
7 | gem 'devise-jwt', '~> 0.8.1'
8 | gem 'dotenv-rails'
9 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
10 | gem 'rails', '~> 6.1.4'
11 | # Use sqlite3 as the database for Active Record
12 | # gem 'sqlite3', '~> 1.4'
13 | gem 'pg'
14 | # Use Puma as the app server
15 | gem 'puma', '~> 5.0'
16 | gem 'rack-cors'
17 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
18 | # gem 'jbuilder', '~> 2.7'
19 | # Use Redis adapter to run Action Cable in production
20 | # gem 'redis', '~> 4.0'
21 | # Use Active Model has_secure_password
22 | gem 'bcrypt', '~> 3.1.7'
23 |
24 | # Use Active Storage variant
25 | # gem 'image_processing', '~> 1.2'
26 |
27 | # Reduces boot times through caching; required in config/boot.rb
28 | gem 'bootsnap', '>= 1.4.4', require: false
29 |
30 | # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
31 | # gem 'rack-cors'
32 |
33 | group :development, :test do
34 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
35 | gem 'byebug', platforms: %i[mri mingw x64_mingw]
36 | end
37 |
38 | group :development do
39 | gem 'listen', '~> 3.3'
40 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
41 | gem 'spring'
42 | end
43 |
44 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
45 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
46 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (6.1.4)
5 | actionpack (= 6.1.4)
6 | activesupport (= 6.1.4)
7 | nio4r (~> 2.0)
8 | websocket-driver (>= 0.6.1)
9 | actionmailbox (6.1.4)
10 | actionpack (= 6.1.4)
11 | activejob (= 6.1.4)
12 | activerecord (= 6.1.4)
13 | activestorage (= 6.1.4)
14 | activesupport (= 6.1.4)
15 | mail (>= 2.7.1)
16 | actionmailer (6.1.4)
17 | actionpack (= 6.1.4)
18 | actionview (= 6.1.4)
19 | activejob (= 6.1.4)
20 | activesupport (= 6.1.4)
21 | mail (~> 2.5, >= 2.5.4)
22 | rails-dom-testing (~> 2.0)
23 | actionpack (6.1.4)
24 | actionview (= 6.1.4)
25 | activesupport (= 6.1.4)
26 | rack (~> 2.0, >= 2.0.9)
27 | rack-test (>= 0.6.3)
28 | rails-dom-testing (~> 2.0)
29 | rails-html-sanitizer (~> 1.0, >= 1.2.0)
30 | actiontext (6.1.4)
31 | actionpack (= 6.1.4)
32 | activerecord (= 6.1.4)
33 | activestorage (= 6.1.4)
34 | activesupport (= 6.1.4)
35 | nokogiri (>= 1.8.5)
36 | actionview (6.1.4)
37 | activesupport (= 6.1.4)
38 | builder (~> 3.1)
39 | erubi (~> 1.4)
40 | rails-dom-testing (~> 2.0)
41 | rails-html-sanitizer (~> 1.1, >= 1.2.0)
42 | activejob (6.1.4)
43 | activesupport (= 6.1.4)
44 | globalid (>= 0.3.6)
45 | activemodel (6.1.4)
46 | activesupport (= 6.1.4)
47 | activerecord (6.1.4)
48 | activemodel (= 6.1.4)
49 | activesupport (= 6.1.4)
50 | activestorage (6.1.4)
51 | actionpack (= 6.1.4)
52 | activejob (= 6.1.4)
53 | activerecord (= 6.1.4)
54 | activesupport (= 6.1.4)
55 | marcel (~> 1.0.0)
56 | mini_mime (>= 1.1.0)
57 | activesupport (6.1.4)
58 | concurrent-ruby (~> 1.0, >= 1.0.2)
59 | i18n (>= 1.6, < 2)
60 | minitest (>= 5.1)
61 | tzinfo (~> 2.0)
62 | zeitwerk (~> 2.3)
63 | bcrypt (3.1.16)
64 | bootsnap (1.7.5)
65 | msgpack (~> 1.0)
66 | builder (3.2.4)
67 | byebug (11.1.3)
68 | concurrent-ruby (1.1.9)
69 | crass (1.0.6)
70 | devise (4.8.0)
71 | bcrypt (~> 3.0)
72 | orm_adapter (~> 0.1)
73 | railties (>= 4.1.0)
74 | responders
75 | warden (~> 1.2.3)
76 | devise-jwt (0.8.1)
77 | devise (~> 4.0)
78 | warden-jwt_auth (~> 0.5)
79 | dotenv (2.7.6)
80 | dotenv-rails (2.7.6)
81 | dotenv (= 2.7.6)
82 | railties (>= 3.2)
83 | dry-auto_inject (0.8.0)
84 | dry-container (>= 0.3.4)
85 | dry-configurable (0.12.1)
86 | concurrent-ruby (~> 1.0)
87 | dry-core (~> 0.5, >= 0.5.0)
88 | dry-container (0.8.0)
89 | concurrent-ruby (~> 1.0)
90 | dry-configurable (~> 0.1, >= 0.1.3)
91 | dry-core (0.7.1)
92 | concurrent-ruby (~> 1.0)
93 | erubi (1.10.0)
94 | ffi (1.15.3)
95 | globalid (0.4.2)
96 | activesupport (>= 4.2.0)
97 | i18n (1.8.10)
98 | concurrent-ruby (~> 1.0)
99 | jwt (2.2.3)
100 | listen (3.6.0)
101 | rb-fsevent (~> 0.10, >= 0.10.3)
102 | rb-inotify (~> 0.9, >= 0.9.10)
103 | loofah (2.10.0)
104 | crass (~> 1.0.2)
105 | nokogiri (>= 1.5.9)
106 | mail (2.7.1)
107 | mini_mime (>= 0.1.1)
108 | marcel (1.0.1)
109 | method_source (1.0.0)
110 | mini_mime (1.1.0)
111 | minitest (5.14.4)
112 | msgpack (1.4.2)
113 | nio4r (2.5.7)
114 | nokogiri (1.11.7-x86_64-linux)
115 | racc (~> 1.4)
116 | orm_adapter (0.5.0)
117 | pg (1.2.3)
118 | puma (5.3.2)
119 | nio4r (~> 2.0)
120 | racc (1.5.2)
121 | rack (2.2.3)
122 | rack-cors (1.1.1)
123 | rack (>= 2.0.0)
124 | rack-test (1.1.0)
125 | rack (>= 1.0, < 3)
126 | rails (6.1.4)
127 | actioncable (= 6.1.4)
128 | actionmailbox (= 6.1.4)
129 | actionmailer (= 6.1.4)
130 | actionpack (= 6.1.4)
131 | actiontext (= 6.1.4)
132 | actionview (= 6.1.4)
133 | activejob (= 6.1.4)
134 | activemodel (= 6.1.4)
135 | activerecord (= 6.1.4)
136 | activestorage (= 6.1.4)
137 | activesupport (= 6.1.4)
138 | bundler (>= 1.15.0)
139 | railties (= 6.1.4)
140 | sprockets-rails (>= 2.0.0)
141 | rails-dom-testing (2.0.3)
142 | activesupport (>= 4.2.0)
143 | nokogiri (>= 1.6)
144 | rails-html-sanitizer (1.3.0)
145 | loofah (~> 2.3)
146 | railties (6.1.4)
147 | actionpack (= 6.1.4)
148 | activesupport (= 6.1.4)
149 | method_source
150 | rake (>= 0.13)
151 | thor (~> 1.0)
152 | rake (13.0.6)
153 | rb-fsevent (0.11.0)
154 | rb-inotify (0.10.1)
155 | ffi (~> 1.0)
156 | responders (3.0.1)
157 | actionpack (>= 5.0)
158 | railties (>= 5.0)
159 | spring (2.1.1)
160 | sprockets (4.0.2)
161 | concurrent-ruby (~> 1.0)
162 | rack (> 1, < 3)
163 | sprockets-rails (3.2.2)
164 | actionpack (>= 4.0)
165 | activesupport (>= 4.0)
166 | sprockets (>= 3.0.0)
167 | thor (1.1.0)
168 | tzinfo (2.0.4)
169 | concurrent-ruby (~> 1.0)
170 | warden (1.2.9)
171 | rack (>= 2.0.9)
172 | warden-jwt_auth (0.5.0)
173 | dry-auto_inject (~> 0.6)
174 | dry-configurable (~> 0.9)
175 | jwt (~> 2.1)
176 | warden (~> 1.2)
177 | websocket-driver (0.7.5)
178 | websocket-extensions (>= 0.1.0)
179 | websocket-extensions (0.1.5)
180 | zeitwerk (2.4.2)
181 |
182 | PLATFORMS
183 | x86_64-linux
184 |
185 | DEPENDENCIES
186 | bcrypt (~> 3.1.7)
187 | bootsnap (>= 1.4.4)
188 | byebug
189 | devise-jwt (~> 0.8.1)
190 | dotenv-rails
191 | listen (~> 3.3)
192 | pg
193 | puma (~> 5.0)
194 | rack-cors
195 | rails (~> 6.1.4)
196 | spring
197 | tzinfo-data
198 |
199 | RUBY VERSION
200 | ruby 3.0.0p0
201 |
202 | BUNDLED WITH
203 | 2.2.13
204 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React-Rails Authentication Front-End
2 |
3 |
4 |
React-Rails --> [Rails]
5 |
6 |
7 | This is prepared Rails authentication template, part of `React-Rails authentication`, Rails back-end and logic are built and ready to use.
8 |
9 | Sign in
24 | - Method ==> POST
25 | - Body ==> `{ "user": { "email": "test@example.com", "password": "12345678" } }`
26 | - Response token ==> data.headers.authorization
27 |
28 | **http//localhost:3000/users**
29 | - Route ==> Sign up
30 | - Method ==> POST
31 | - Body ==> `{ "user": { "email": "test@example.com", "password": "12345678" } }`
32 | - Response token ==> data.headers.authorization
33 |
34 | **http//localhost:3000/member**
35 | - Route ==> To know if user logged in?
36 | - Method ==> GET
37 | - headers ==> `token: token you saved from log in or sign up user`
38 | - Response ==> data.data.message=> 'yeppa you did it.'
39 |
40 | **http//localhost:3000/users/sign_out**
41 | - Route ==> To log out
42 | - Method ==> DELETE
43 | - headers ==> `token: token you saved from log in or sign up user`
44 | - Response ==> data.data.message=> 'You are logged out.'
45 |
46 | ## Built With
47 |
48 | - Rails-Api
49 |
50 | - Devise
51 |
52 | - Devise-jwt
53 |
54 | ## Prerequisities
55 |
56 | - Ruby 3
57 | - Rails 6
58 |
59 |
60 | ## Getting Started
61 |
62 | **To get this project set up on your local machine, follow these simple steps:**
63 |
64 |
65 | **Step 1**
66 |
67 | In order to use this project all you have to to is follow these simple steps :
68 |
69 | - Clone the Rails repo and cd inside the project.
70 |
71 | - Run `Rake secret`, this will generate a secret key, hold it for the next step.
72 |
73 | - Create a `.env` file in the root of the project and inside it put this `DEVISE_JWT_SECRET_KEY = < your secret key from previuos step >`
74 |
75 | - Inside `config/initializers/cors.rb` if you it locally you dont need to do this but if you want to use it from specific domain you should change line 12 from `origins '*'` to `origins 'Your domain here'`.
76 |
77 | - Note: If you publish this website and upload it to heroku, do not forget to add a `Config variable` to your app in heroku, simply go to heroku, go to your app, click on setting, click on config vars then put your `DEVISE_JWT_SECRET_KEY` then your secret key.
78 |
79 |
80 | ## 🤝 contributing
81 |
82 | ## Author
83 |
84 | - GitHub: [@arikarim](https://github.com/arikarim)
85 | - LinkedIn: [AriKarim](https://www.linkedin.com/in/ari-karim-523bb81b3)
86 |
87 | ## 🙋♂ show your support
88 |
89 | give a ⭐️ if you like this project!
90 |
91 | ## 📝 license
92 |
93 |
94 |
95 | This project is [MIT](lisenced)
96 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Add your own tasks in files placed in lib/tasks ending in .rake,
4 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5 |
6 | require_relative 'config/application'
7 |
8 | Rails.application.load_tasks
9 |
--------------------------------------------------------------------------------
/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Channel < ActionCable::Channel::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module ApplicationCable
4 | class Connection < ActionCable::Connection::Base
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationController < ActionController::API
4 | respond_to :json
5 |
6 |
7 | # before_action :process_token
8 |
9 | # private
10 |
11 | # # Check for auth headers - if present, decode or send unauthorized response (called always to allow current_user)
12 | # def process_token
13 | # if request.headers['Authorization'].present?
14 | # begin
15 | # jwt_payload = JWT.decode(request.headers['Authorization'].split(' ')[1], Rails.application.secrets.secret_key_base).first
16 | # @current_user_id = jwt_payload['id']
17 | # rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
18 | # head :unauthorized
19 | # end
20 | # end
21 | # end
22 |
23 | # # If user has not signed in, return unauthorized response (called only when auth is needed)
24 | # def authenticate_user!(options = {})
25 | # head :unauthorized unless signed_in?
26 | # end
27 |
28 | # # set Devise's current_user using decoded JWT instead of session
29 | # # def current_user
30 | # # @current_user ||= super || User.find(@current_user_id)
31 | # # end
32 |
33 | # # check that authenticate_user has successfully returned @current_user_id (user is authenticated)
34 | # def signed_in?
35 | # @current_user_id.present?
36 | # end
37 | end
38 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/members_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class MembersController < ApplicationController
4 | before_action :authenticate_user!
5 |
6 | def show
7 | render json: { user: current_user, message: 'Yeppa You did it' }
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/app/controllers/posts_controller.rb:
--------------------------------------------------------------------------------
1 | class PostsController < ApplicationController
2 | before_action :authenticate_user!
3 | before_action :set_post, only: [:show, :update, :destroy]
4 |
5 | # GET /posts
6 | def index
7 | @posts = Post.all
8 |
9 | render json: @posts
10 | end
11 |
12 | # GET /posts/1
13 | def show
14 | render json: @post
15 | end
16 |
17 | # POST /posts
18 | def create
19 | @post = Post.new(post_params)
20 |
21 | if @post.save
22 | render json: @post, status: :created, location: @post
23 | else
24 | render json: @post.errors, status: :unprocessable_entity
25 | end
26 | end
27 |
28 | # PATCH/PUT /posts/1
29 | def update
30 | if @post.update(post_params)
31 | render json: @post
32 | else
33 | render json: @post.errors, status: :unprocessable_entity
34 | end
35 | end
36 |
37 | # DELETE /posts/1
38 | def destroy
39 | @post.destroy
40 | end
41 |
42 | private
43 | # Use callbacks to share common setup or constraints between actions.
44 | def set_post
45 | @post = Post.find(params[:id])
46 | end
47 |
48 | # Only allow a list of trusted parameters through.
49 | def post_params
50 | params.require(:post).permit(:title, :body, :user_id)
51 | end
52 | end
53 |
--------------------------------------------------------------------------------
/app/controllers/registrations_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class RegistrationsController < Devise::RegistrationsController
4 | respond_to :json
5 |
6 | private
7 |
8 | def respond_with(resource, _opts = {})
9 | register_success && return if resource.persisted?
10 |
11 | register_failed
12 | end
13 |
14 | def register_success
15 | render json: { user: current_user, message: 'Signed up sucessfully.' }
16 | end
17 |
18 | def register_failed
19 | render json: { message: 'Something went wrong.' }
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/app/controllers/sessions_controller.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class SessionsController < Devise::SessionsController
4 | respond_to :json
5 |
6 | private
7 |
8 | def respond_with(resource, _opts = {})
9 | if resource.persisted?
10 | # if current_user
11 | # token = current_user.generate_jwt
12 | # end
13 |
14 | h = request.headers['Authorization']
15 | render json: { token: h, message: 'You are logged in.', user: current_user }, status: :ok
16 | else
17 | login_failed
18 | end
19 | end
20 |
21 | def login_failed
22 | render json: { message: 'Something went wrong.' }, status: :unauthorized
23 | end
24 |
25 | def respond_to_on_destroy
26 | log_out_success && return if current_user
27 |
28 | log_out_failure
29 | end
30 |
31 | def log_out_success
32 | render json: { message: 'You are logged out.' }, status: :ok
33 | end
34 |
35 | def log_out_failure
36 | render json: { message: 'Hmm nothing happened.' }, status: :unauthorized
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/app/images/rails.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/app/images/rails.png
--------------------------------------------------------------------------------
/app/images/s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/app/images/s.png
--------------------------------------------------------------------------------
/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationJob < ActiveJob::Base
4 | # Automatically retry jobs that encountered a deadlock
5 | # retry_on ActiveRecord::Deadlocked
6 |
7 | # Most jobs are safe to ignore if the underlying records are no longer available
8 | # discard_on ActiveJob::DeserializationError
9 | end
10 |
--------------------------------------------------------------------------------
/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationMailer < ActionMailer::Base
4 | default from: 'from@example.com'
5 | layout 'mailer'
6 | end
7 |
--------------------------------------------------------------------------------
/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class ApplicationRecord < ActiveRecord::Base
4 | self.abstract_class = true
5 | end
6 |
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/models/jwt_denylist.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class JwtDenylist < ApplicationRecord
4 | include Devise::JWT::RevocationStrategies::Denylist
5 |
6 | self.table_name = 'jwt_denylist'
7 | end
8 |
--------------------------------------------------------------------------------
/app/models/post.rb:
--------------------------------------------------------------------------------
1 | class Post < ApplicationRecord
2 | belongs_to :user
3 | validates :title, presence: true
4 | validates :body, presence: true
5 | end
6 |
--------------------------------------------------------------------------------
/app/models/user.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class User < ApplicationRecord
4 | has_many :posts
5 | # Include default devise modules. Others available are:
6 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
7 | devise :database_authenticatable,
8 | :jwt_authenticatable,
9 | :registerable,
10 | jwt_revocation_strategy: JwtDenylist
11 | end
12 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | #
5 | # This file was generated by Bundler.
6 | #
7 | # The application 'bundle' is installed as part of a gem, and
8 | # this file is here to facilitate running it.
9 | #
10 |
11 | require 'rubygems'
12 |
13 | m = Module.new do
14 | module_function
15 |
16 | def invoked_as_script?
17 | File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
18 | end
19 |
20 | def env_var_version
21 | ENV['BUNDLER_VERSION']
22 | end
23 |
24 | def cli_arg_version
25 | return unless invoked_as_script? # don't want to hijack other binstubs
26 | return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27 |
28 | bundler_version = nil
29 | update_index = nil
30 | ARGV.each_with_index do |a, i|
31 | bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
32 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
33 |
34 | bundler_version = Regexp.last_match(1)
35 | update_index = i
36 | end
37 | bundler_version
38 | end
39 |
40 | def gemfile
41 | gemfile = ENV['BUNDLE_GEMFILE']
42 | return gemfile if gemfile && !gemfile.empty?
43 |
44 | File.expand_path('../Gemfile', __dir__)
45 | end
46 |
47 | def lockfile
48 | lockfile =
49 | case File.basename(gemfile)
50 | when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
51 | else "#{gemfile}.lock"
52 | end
53 | File.expand_path(lockfile)
54 | end
55 |
56 | def lockfile_version
57 | return unless File.file?(lockfile)
58 |
59 | lockfile_contents = File.read(lockfile)
60 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
61 |
62 | Regexp.last_match(1)
63 | end
64 |
65 | def bundler_version
66 | @bundler_version ||=
67 | env_var_version || cli_arg_version ||
68 | lockfile_version
69 | end
70 |
71 | def bundler_requirement
72 | return "#{Gem::Requirement.default}.a" unless bundler_version
73 |
74 | bundler_gem_version = Gem::Version.new(bundler_version)
75 |
76 | requirement = bundler_gem_version.approximate_recommendation
77 |
78 | return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0')
79 |
80 | requirement += '.a' if bundler_gem_version.prerelease?
81 |
82 | requirement
83 | end
84 |
85 | def load_bundler!
86 | ENV['BUNDLE_GEMFILE'] ||= gemfile
87 |
88 | activate_bundler
89 | end
90 |
91 | def activate_bundler
92 | gem_error = activation_error_handling do
93 | gem 'bundler', bundler_requirement
94 | end
95 | return if gem_error.nil?
96 |
97 | require_error = activation_error_handling do
98 | require 'bundler/version'
99 | end
100 | if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
101 | return
102 | end
103 |
104 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
105 | exit 42
106 | end
107 |
108 | def activation_error_handling
109 | yield
110 | nil
111 | rescue StandardError, LoadError => e
112 | e
113 | end
114 | end
115 |
116 | m.load_bundler!
117 |
118 | load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
119 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | load File.expand_path('spring', __dir__)
5 | APP_PATH = File.expand_path('../config/application', __dir__)
6 | require_relative '../config/boot'
7 | require 'rails/commands'
8 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | load File.expand_path('spring', __dir__)
5 | require_relative '../config/boot'
6 | require 'rake'
7 | Rake.application.run
8 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'fileutils'
5 |
6 | # path to your application root.
7 | APP_ROOT = File.expand_path('..', __dir__)
8 |
9 | def system!(*args)
10 | system(*args) || abort("\n== Command #{args} failed ==")
11 | end
12 |
13 | FileUtils.chdir APP_ROOT do
14 | # This script is a way to set up or update your development environment automatically.
15 | # This script is idempotent, so that you can run it at any time and get an expectable outcome.
16 | # Add necessary setup steps to this file.
17 |
18 | puts '== Installing dependencies =='
19 | system! 'gem install bundler --conservative'
20 | system('bundle check') || system!('bundle install')
21 |
22 | # puts "\n== Copying sample files =="
23 | # unless File.exist?('config/database.yml')
24 | # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
25 | # end
26 |
27 | puts "\n== Preparing database =="
28 | system! 'bin/rails db:prepare'
29 |
30 | puts "\n== Removing old logs and tempfiles =="
31 | system! 'bin/rails log:clear tmp:clear'
32 |
33 | puts "\n== Restarting application server =="
34 | system! 'bin/rails restart'
35 | end
36 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | if !defined?(Spring) && [nil, 'development', 'test'].include?(ENV['RAILS_ENV'])
5 | gem 'bundler'
6 | require 'bundler'
7 |
8 | # Load Spring without loading other gems in the Gemfile, for speed.
9 | Bundler.locked_gems&.specs&.find { |spec| spec.name == 'spring' }&.tap do |spring|
10 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
11 | gem 'spring', spring.version
12 | require 'spring/binstub'
13 | rescue Gem::LoadError
14 | # Ignore when Spring is not installed.
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This file is used by Rack-based servers to start the application.
4 |
5 | require_relative 'config/environment'
6 |
7 | run Rails.application
8 | Rails.application.load_server
9 |
10 | # require 'rack/cors'
11 | # use Rack::Cors do
12 | # allow do
13 | # origins '*'
14 |
15 | # resource '*', headers: %w(Authorization),
16 | # methods: :any,
17 | # expose: %w[Authorization]
18 | # end
19 | # end
20 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative 'boot'
4 |
5 | require 'rails'
6 | # Pick the frameworks you want:
7 | require 'active_model/railtie'
8 | require 'active_job/railtie'
9 | require 'active_record/railtie'
10 | require 'active_storage/engine'
11 | require 'action_controller/railtie'
12 | require 'action_mailer/railtie'
13 | require 'action_mailbox/engine'
14 | require 'action_text/engine'
15 | require 'action_view/railtie'
16 | require 'action_cable/engine'
17 | # require "sprockets/railtie"
18 | require 'rails/test_unit/railtie'
19 |
20 | # Require the gems listed in Gemfile, including any gems
21 | # you've limited to :test, :development, or :production.
22 | Bundler.require(*Rails.groups)
23 |
24 | module Appp
25 | class Application < Rails::Application
26 | # Initialize configuration defaults for originally generated Rails version.
27 | config.load_defaults 6.1
28 |
29 | # Configuration for the application, engines, and railties goes here.
30 | #
31 | # These settings can be overridden in specific environments using the files
32 | # in config/environments, which are processed later.
33 | #
34 | # config.time_zone = "Central Time (US & Canada)"
35 | # config.eager_load_paths << Rails.root.join("extras")
36 |
37 | # Only loads a smaller set of middleware suitable for API only apps.
38 | # Middleware like session, flash, cookies can be added back manually.
39 | # Skip views, helpers and assets when generating a new resource.
40 | config.api_only = true
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4 |
5 | require 'bundler/setup' # Set up gems listed in the Gemfile.
6 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
7 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: test
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: appp_production
11 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | 8YzWx6kg7HhxTXTVZU6bU04TJTFegED/ZdWBA9+Z8X7hyrlIPK6bUccLOOE4uyXSBv5z28oWZkOzJprZN5jonNRQ9hPd/QCRfXTG+wydBBpHod18b5Nq9rbm6It4bNTSqLWEiddHBCauoLpdfSGiMfUHH3fYLeoEkAverMt9FS+KKs6kOI2EEXmpicSKBB4S33EuVmCUKyDKDxXNshq6QmbH15lgqltKpXl1u4xwdjv6aoyQemx0WGXBnM3ZGSz+JMFBCp+N3geTPDUkCCrRcC1eGzkPp7dLjVUboz3ZOHeb6M1WqgTDSgHabddu0oM2J7a54wuTBSCikQFaXqMWyc6bWEzzkNaVDSQ5SVF5dhXTxAl0dDTmLrvWUE4JcoLoMsFIceCT8fN/+JvAJt70fCGypZPrzTL4sUeN1g3G+mlBVo0ICPPQo/UvyAojcsdWR7GEsFao2IT2Yi9X9yixAbArUAw9lnztWmCY1rrOi6gz3qwSJiLVKp22qyIaO10DXkEM2HA3XybmvTk3bXMtPoXSWBGuhxG78Kkh+eBAz6cNOBvz5KFE1DYQw6BQ4nVca5inm7/guERzHI439wF67k9q/KSrkg==--CuEEM4q2h6Rcmrt9--z9TK9W9NWztoy+Sw3jmU2w==
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite. Versions 3.8.0 and up are supported.
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | # adapter: sqlite3
9 | adapter: postgresql
10 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
11 | timeout: 5000
12 |
13 | development:
14 | <<: *default
15 | database: arikarimm_development
16 |
17 | # Warning: The database defined as "test" will be erased and
18 | # re-generated from your development database when you run "rake".
19 | # Do not set this db to the same as development or production.
20 | test:
21 | <<: *default
22 | database: arikarimmm_test
23 |
24 | production:
25 | <<: *default
26 | database: arikarimmm_production
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Load the Rails application.
4 | require_relative 'application'
5 |
6 | # Initialize the Rails application.
7 | Rails.application.initialize!
8 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 |
5 | Rails.application.configure do
6 | # Settings specified here will take precedence over those in config/application.rb.
7 |
8 | # In the development environment your application's code is reloaded any time
9 | # it changes. This slows down response time but is perfect for development
10 | # since you don't have to restart the web server when you make code changes.
11 | config.cache_classes = false
12 |
13 | # Do not eager load code on boot.
14 | config.eager_load = false
15 |
16 | # Show full error reports.
17 | config.consider_all_requests_local = true
18 |
19 | # Enable/disable caching. By default caching is disabled.
20 | # Run rails dev:cache to toggle caching.
21 | if Rails.root.join('tmp', 'caching-dev.txt').exist?
22 | config.cache_store = :memory_store
23 | config.public_file_server.headers = {
24 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
25 | }
26 | else
27 | config.action_controller.perform_caching = false
28 |
29 | config.cache_store = :null_store
30 | end
31 |
32 | # Store uploaded files on the local file system (see config/storage.yml for options).
33 | config.active_storage.service = :local
34 |
35 | # Don't care if the mailer can't send.
36 | config.action_mailer.raise_delivery_errors = false
37 |
38 | config.action_mailer.perform_caching = false
39 |
40 | # Print deprecation notices to the Rails logger.
41 | config.active_support.deprecation = :log
42 |
43 | # Raise exceptions for disallowed deprecations.
44 | config.active_support.disallowed_deprecation = :raise
45 |
46 | # Tell Active Support which deprecation messages to disallow.
47 | config.active_support.disallowed_deprecation_warnings = []
48 |
49 | # Raise an error on page load if there are pending migrations.
50 | config.active_record.migration_error = :page_load
51 |
52 | # Highlight code that triggered database queries in logs.
53 | config.active_record.verbose_query_logs = true
54 |
55 | # Raises error for missing translations.
56 | # config.i18n.raise_on_missing_translations = true
57 |
58 | # Annotate rendered view with file names.
59 | # config.action_view.annotate_rendered_view_with_filenames = true
60 |
61 | # Use an evented file watcher to asynchronously detect changes in source code,
62 | # routes, locales, etc. This feature depends on the listen gem.
63 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
64 |
65 | # Uncomment if you wish to allow Action Cable access from any origin.
66 | # config.action_cable.disable_request_forgery_protection = true
67 | end
68 | Rails.application.config.hosts = nil
69 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 | Rails.application.configure do
5 | # Settings specified here will take precedence over those in config/application.rb.
6 |
7 | # Code is not reloaded between requests.
8 | config.cache_classes = true
9 |
10 | # Eager load code on boot. This eager loads most of Rails and
11 | # your application in memory, allowing both threaded web servers
12 | # and those relying on copy on write to perform better.
13 | # Rake tasks automatically ignore this option for performance.
14 | config.eager_load = true
15 |
16 | # Full error reports are disabled and caching is turned on.
17 | config.consider_all_requests_local = false
18 |
19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21 | # config.require_master_key = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
26 |
27 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
28 | # config.asset_host = 'http://assets.example.com'
29 |
30 | # Specifies the header that your server uses for sending files.
31 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
32 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
33 |
34 | # Store uploaded files on the local file system (see config/storage.yml for options).
35 | config.active_storage.service = :local
36 |
37 | # Mount Action Cable outside main process or domain.
38 | # config.action_cable.mount_path = nil
39 | # config.action_cable.url = 'wss://example.com/cable'
40 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
41 |
42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43 | # config.force_ssl = true
44 |
45 | # Include generic and useful information about system operation, but avoid logging too much
46 | # information to avoid inadvertent exposure of personally identifiable information (PII).
47 | config.log_level = :info
48 |
49 | # Prepend all log lines with the following tags.
50 | config.log_tags = [:request_id]
51 |
52 | # Use a different cache store in production.
53 | # config.cache_store = :mem_cache_store
54 |
55 | # Use a real queuing backend for Active Job (and separate queues per environment).
56 | # config.active_job.queue_adapter = :resque
57 | # config.active_job.queue_name_prefix = "appp_production"
58 |
59 | config.action_mailer.perform_caching = false
60 |
61 | # Ignore bad email addresses and do not raise email delivery errors.
62 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
63 | # config.action_mailer.raise_delivery_errors = false
64 |
65 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
66 | # the I18n.default_locale when a translation cannot be found).
67 | config.i18n.fallbacks = true
68 |
69 | # Send deprecation notices to registered listeners.
70 | config.active_support.deprecation = :notify
71 |
72 | # Log disallowed deprecations.
73 | config.active_support.disallowed_deprecation = :log
74 |
75 | # Tell Active Support which deprecation messages to disallow.
76 | config.active_support.disallowed_deprecation_warnings = []
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = ::Logger::Formatter.new
80 |
81 | # Use a different logger for distributed setups.
82 | # require "syslog/logger"
83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
84 |
85 | if ENV['RAILS_LOG_TO_STDOUT'].present?
86 | logger = ActiveSupport::Logger.new($stdout)
87 | logger.formatter = config.log_formatter
88 | config.logger = ActiveSupport::TaggedLogging.new(logger)
89 | end
90 |
91 | # Do not dump schema after migrations.
92 | config.active_record.dump_schema_after_migration = false
93 |
94 | # Inserts middleware to perform automatic connection switching.
95 | # The `database_selector` hash is used to pass options to the DatabaseSelector
96 | # middleware. The `delay` is used to determine how long to wait after a write
97 | # to send a subsequent read to the primary.
98 | #
99 | # The `database_resolver` class is used by the middleware to determine which
100 | # database is appropriate to use based on the time delay.
101 | #
102 | # The `database_resolver_context` class is used by the middleware to set
103 | # timestamps for the last write to the primary. The resolver uses the context
104 | # class timestamps to determine how long to wait before reading from the
105 | # replica.
106 | #
107 | # By default Rails will store a last write timestamp in the session. The
108 | # DatabaseSelector middleware is designed as such you can define your own
109 | # strategy for connection switching and pass that into the middleware through
110 | # these configuration options.
111 | # config.active_record.database_selector = { delay: 2.seconds }
112 | # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
113 | # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
114 | end
115 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 |
5 | # The test environment is used exclusively to run your application's
6 | # test suite. You never need to work with it otherwise. Remember that
7 | # your test database is "scratch space" for the test suite and is wiped
8 | # and recreated between test runs. Don't rely on the data there!
9 |
10 | Rails.application.configure do
11 | # Settings specified here will take precedence over those in config/application.rb.
12 |
13 | config.cache_classes = false
14 | config.action_view.cache_template_loading = true
15 |
16 | # Do not eager load code on boot. This avoids loading your whole application
17 | # just for the purpose of running a single test. If you are using a tool that
18 | # preloads Rails for running tests, you may have to set it to true.
19 | config.eager_load = false
20 |
21 | # Configure public file server for tests with Cache-Control for performance.
22 | config.public_file_server.enabled = true
23 | config.public_file_server.headers = {
24 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
25 | }
26 |
27 | # Show full error reports and disable caching.
28 | config.consider_all_requests_local = true
29 | config.action_controller.perform_caching = false
30 | config.cache_store = :null_store
31 |
32 | # Raise exceptions instead of rendering exception templates.
33 | config.action_dispatch.show_exceptions = false
34 |
35 | # Disable request forgery protection in test environment.
36 | config.action_controller.allow_forgery_protection = false
37 |
38 | # Store uploaded files on the local file system in a temporary directory.
39 | config.active_storage.service = :test
40 |
41 | config.action_mailer.perform_caching = false
42 |
43 | # Tell Action Mailer not to deliver emails to the real world.
44 | # The :test delivery method accumulates sent emails in the
45 | # ActionMailer::Base.deliveries array.
46 | config.action_mailer.delivery_method = :test
47 |
48 | # Print deprecation notices to the stderr.
49 | config.active_support.deprecation = :stderr
50 |
51 | # Raise exceptions for disallowed deprecations.
52 | config.active_support.disallowed_deprecation = :raise
53 |
54 | # Tell Active Support which deprecation messages to disallow.
55 | config.active_support.disallowed_deprecation_warnings = []
56 |
57 | # Raises error for missing translations.
58 | # config.i18n.raise_on_missing_translations = true
59 |
60 | # Annotate rendered view with file names.
61 | # config.action_view.annotate_rendered_view_with_filenames = true
62 | end
63 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Be sure to restart your server when you modify this file.
3 |
4 | # ActiveSupport::Reloader.to_prepare do
5 | # ApplicationController.renderer.defaults.merge!(
6 | # http_host: 'example.org',
7 | # https: false
8 | # )
9 | # end
10 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
6 | # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) }
7 |
8 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
9 | # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
10 | Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE']
11 |
--------------------------------------------------------------------------------
/config/initializers/cors.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Avoid CORS issues when API is called from the frontend app.
6 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
7 |
8 | # Read more: https://github.com/cyu/rack-cors
9 |
10 | Rails.application.config.middleware.insert_before 0, Rack::Cors, debug: true do
11 | allow do
12 | origins '*'
13 |
14 | resource '*', headers: %w(Authorization),
15 | methods: :any,
16 | expose: %w[Authorization]
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Assuming you have not yet modified this file, each configuration option below
4 | # is set to its default value. Note that some are commented out while others
5 | # are not: uncommented lines are intended to protect your configuration from
6 | # breaking changes in upgrades (i.e., in the event that future versions of
7 | # Devise change the default values for those options).
8 | #
9 | # Use this hook to configure devise mailer, warden hooks and so forth.
10 | # Many of these configuration options can be set straight in your model.
11 | Devise.setup do |config|
12 | # The secret key used by Devise. Devise uses this key to generate
13 | # random tokens. Changing this key will render invalid all existing
14 | # confirmation, reset password and unlock tokens in the database.
15 | # Devise will use the `secret_key_base` as its `secret_key`
16 | # by default. You can change it below and use your own secret key.
17 | # config.secret_key = 'e028ab61b48addc62742ce29a5e986a25061ba071519c8873b6d6cd29465a2e7837ecba9048604bf4f7ac6a4c6c59110e3c26f71d2751cb02415e8554bdbb87f'
18 |
19 | # ==> Controller configuration
20 | # Configure the parent class to the devise controllers.
21 | # config.parent_controller = 'DeviseController'
22 |
23 | # ==> Mailer Configuration
24 | # Configure the e-mail address which will be shown in Devise::Mailer,
25 | # note that it will be overwritten if you use your own mailer class
26 | # with default "from" parameter.
27 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
28 |
29 | # Configure the class responsible to send e-mails.
30 | # config.mailer = 'Devise::Mailer'
31 |
32 | # Configure the parent class responsible to send e-mails.
33 | # config.parent_mailer = 'ActionMailer::Base'
34 |
35 | # ==> ORM configuration
36 | # Load and configure the ORM. Supports :active_record (default) and
37 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
38 | # available as additional gems.
39 | require 'devise/orm/active_record'
40 |
41 | # ==> Configuration for any authentication mechanism
42 | # Configure which keys are used when authenticating a user. The default is
43 | # just :email. You can configure it to use [:username, :subdomain], so for
44 | # authenticating a user, both parameters are required. Remember that those
45 | # parameters are used only when authenticating and not when retrieving from
46 | # session. If you need permissions, you should implement that in a before filter.
47 | # You can also supply a hash where the value is a boolean determining whether
48 | # or not authentication should be aborted when the value is not present.
49 | # config.authentication_keys = [:email]
50 |
51 | # Configure parameters from the request object used for authentication. Each entry
52 | # given should be a request method and it will automatically be passed to the
53 | # find_for_authentication method and considered in your model lookup. For instance,
54 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55 | # The same considerations mentioned for authentication_keys also apply to request_keys.
56 | # config.request_keys = []
57 |
58 | # Configure which authentication keys should be case-insensitive.
59 | # These keys will be downcased upon creating or modifying a user and when used
60 | # to authenticate or find a user. Default is :email.
61 | config.case_insensitive_keys = [:email]
62 |
63 | # Configure which authentication keys should have whitespace stripped.
64 | # These keys will have whitespace before and after removed upon creating or
65 | # modifying a user and when used to authenticate or find a user. Default is :email.
66 | config.strip_whitespace_keys = [:email]
67 |
68 | # Tell if authentication through request.params is enabled. True by default.
69 | # It can be set to an array that will enable params authentication only for the
70 | # given strategies, for example, `config.params_authenticatable = [:database]` will
71 | # enable it only for database (email + password) authentication.
72 | # config.params_authenticatable = true
73 |
74 | # Tell if authentication through HTTP Auth is enabled. False by default.
75 | # It can be set to an array that will enable http authentication only for the
76 | # given strategies, for example, `config.http_authenticatable = [:database]` will
77 | # enable it only for database authentication.
78 | # For API-only applications to support authentication "out-of-the-box", you will likely want to
79 | # enable this with :database unless you are using a custom strategy.
80 | # The supported strategies are:
81 | # :database = Support basic authentication with authentication key + password
82 | # config.http_authenticatable = false
83 |
84 | # If 401 status code should be returned for AJAX requests. True by default.
85 | # config.http_authenticatable_on_xhr = true
86 |
87 | # The realm used in Http Basic Authentication. 'Application' by default.
88 | # config.http_authentication_realm = 'Application'
89 |
90 | # It will change confirmation, password recovery and other workflows
91 | # to behave the same regardless if the e-mail provided was right or wrong.
92 | # Does not affect registerable.
93 | # config.paranoid = true
94 |
95 | # By default Devise will store the user in session. You can skip storage for
96 | # particular strategies by setting this option.
97 | # Notice that if you are skipping storage for all authentication paths, you
98 | # may want to disable generating routes to Devise's sessions controller by
99 | # passing skip: :sessions to `devise_for` in your config/routes.rb
100 | config.skip_session_storage = [:http_auth]
101 |
102 | # By default, Devise cleans up the CSRF token on authentication to
103 | # avoid CSRF token fixation attacks. This means that, when using AJAX
104 | # requests for sign in and sign up, you need to get a new CSRF token
105 | # from the server. You can disable this option at your own risk.
106 | # config.clean_up_csrf_token_on_authentication = true
107 | config.jwt do |jwt|
108 | jwt.secret = ENV['DEVISE_JWT_SECRET_KEY']
109 |
110 | jwt.dispatch_requests = [
111 | ['POST', %r{^/users/sign_in$}],
112 | ['GET', %r{^/member$}]
113 | ]
114 | jwt.revocation_requests = [
115 | ['DELETE', %r{^/users/sign_out$}]
116 | ]
117 | jwt.aud_header = 'JWT_AUD'
118 | end
119 | # When false, Devise will not attempt to reload routes on eager load.
120 | # This can reduce the time taken to boot the app but if your application
121 | # requires the Devise mappings to be loaded during boot time the application
122 | # won't boot properly.
123 | # config.reload_routes = true
124 |
125 | # ==> Configuration for :database_authenticatable
126 | # For bcrypt, this is the cost for hashing the password and defaults to 12. If
127 | # using other algorithms, it sets how many times you want the password to be hashed.
128 | # The number of stretches used for generating the hashed password are stored
129 | # with the hashed password. This allows you to change the stretches without
130 | # invalidating existing passwords.
131 | #
132 | # Limiting the stretches to just one in testing will increase the performance of
133 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
134 | # a value less than 10 in other environments. Note that, for bcrypt (the default
135 | # algorithm), the cost increases exponentially with the number of stretches (e.g.
136 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
137 | config.stretches = Rails.env.test? ? 1 : 12
138 |
139 | # Set up a pepper to generate the hashed password.
140 | # config.pepper = '8a3ed1666503918573edee5513e26ef98c32346c8c05ed51085a0f4c95832e9694828f67e498896c94b03126b0ed1cc5f63ca9b9f86d5960e96f92a8a5944f95'
141 |
142 | # Send a notification to the original email when the user's email is changed.
143 | # config.send_email_changed_notification = false
144 |
145 | # Send a notification email when the user's password is changed.
146 | # config.send_password_change_notification = false
147 |
148 | # ==> Configuration for :confirmable
149 | # A period that the user is allowed to access the website even without
150 | # confirming their account. For instance, if set to 2.days, the user will be
151 | # able to access the website for two days without confirming their account,
152 | # access will be blocked just in the third day.
153 | # You can also set it to nil, which will allow the user to access the website
154 | # without confirming their account.
155 | # Default is 0.days, meaning the user cannot access the website without
156 | # confirming their account.
157 | # config.allow_unconfirmed_access_for = 2.days
158 |
159 | # A period that the user is allowed to confirm their account before their
160 | # token becomes invalid. For example, if set to 3.days, the user can confirm
161 | # their account within 3 days after the mail was sent, but on the fourth day
162 | # their account can't be confirmed with the token any more.
163 | # Default is nil, meaning there is no restriction on how long a user can take
164 | # before confirming their account.
165 | # config.confirm_within = 3.days
166 |
167 | # If true, requires any email changes to be confirmed (exactly the same way as
168 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
169 | # db field (see migrations). Until confirmed, new email is stored in
170 | # unconfirmed_email column, and copied to email column on successful confirmation.
171 | config.reconfirmable = true
172 |
173 | # Defines which key will be used when confirming an account
174 | # config.confirmation_keys = [:email]
175 |
176 | # ==> Configuration for :rememberable
177 | # The time the user will be remembered without asking for credentials again.
178 | # config.remember_for = 2.weeks
179 |
180 | # Invalidates all the remember me tokens when the user signs out.
181 | config.expire_all_remember_me_on_sign_out = true
182 |
183 | # If true, extends the user's remember period when remembered via cookie.
184 | # config.extend_remember_period = false
185 |
186 | # Options to be passed to the created cookie. For instance, you can set
187 | # secure: true in order to force SSL only cookies.
188 | # config.rememberable_options = {}
189 |
190 | # ==> Configuration for :validatable
191 | # Range for password length.
192 | config.password_length = 6..128
193 |
194 | # Email regex used to validate email formats. It simply asserts that
195 | # one (and only one) @ exists in the given string. This is mainly
196 | # to give user feedback and not to assert the e-mail validity.
197 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
198 |
199 | # ==> Configuration for :timeoutable
200 | # The time you want to timeout the user session without activity. After this
201 | # time the user will be asked for credentials again. Default is 30 minutes.
202 | # config.timeout_in = 30.minutes
203 |
204 | # ==> Configuration for :lockable
205 | # Defines which strategy will be used to lock an account.
206 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
207 | # :none = No lock strategy. You should handle locking by yourself.
208 | # config.lock_strategy = :failed_attempts
209 |
210 | # Defines which key will be used when locking and unlocking an account
211 | # config.unlock_keys = [:email]
212 |
213 | # Defines which strategy will be used to unlock an account.
214 | # :email = Sends an unlock link to the user email
215 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
216 | # :both = Enables both strategies
217 | # :none = No unlock strategy. You should handle unlocking by yourself.
218 | # config.unlock_strategy = :both
219 |
220 | # Number of authentication tries before locking an account if lock_strategy
221 | # is failed attempts.
222 | # config.maximum_attempts = 20
223 |
224 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
225 | # config.unlock_in = 1.hour
226 |
227 | # Warn on the last attempt before the account is locked.
228 | # config.last_attempt_warning = true
229 |
230 | # ==> Configuration for :recoverable
231 | #
232 | # Defines which key will be used when recovering the password for an account
233 | # config.reset_password_keys = [:email]
234 |
235 | # Time interval you can reset your password with a reset password key.
236 | # Don't put a too small interval or your users won't have the time to
237 | # change their passwords.
238 | config.reset_password_within = 6.hours
239 |
240 | # When set to false, does not sign a user in automatically after their password is
241 | # reset. Defaults to true, so a user is signed in automatically after a reset.
242 | # config.sign_in_after_reset_password = true
243 |
244 | # ==> Configuration for :encryptable
245 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
246 | # You can use :sha1, :sha512 or algorithms from others authentication tools as
247 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
248 | # for default behavior) and :restful_authentication_sha1 (then you should set
249 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
250 | #
251 | # Require the `devise-encryptable` gem when using anything other than bcrypt
252 | # config.encryptor = :sha512
253 |
254 | # ==> Scopes configuration
255 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
256 | # "users/sessions/new". It's turned off by default because it's slower if you
257 | # are using only default views.
258 | # config.scoped_views = false
259 |
260 | # Configure the default scope given to Warden. By default it's the first
261 | # devise role declared in your routes (usually :user).
262 | # config.default_scope = :user
263 |
264 | # Set this configuration to false if you want /users/sign_out to sign out
265 | # only the current scope. By default, Devise signs out all scopes.
266 | # config.sign_out_all_scopes = true
267 |
268 | # ==> Navigation configuration
269 | # Lists the formats that should be treated as navigational. Formats like
270 | # :html, should redirect to the sign in page when the user does not have
271 | # access, but formats like :xml or :json, should return 401.
272 | #
273 | # If you have any extra navigational formats, like :iphone or :mobile, you
274 | # should add them to the navigational formats lists.
275 | #
276 | # The "*/*" below is required to match Internet Explorer requests.
277 | # config.navigational_formats = ['*/*', :html]
278 |
279 | # The default HTTP method used to sign out a resource. Default is :delete.
280 | config.sign_out_via = :delete
281 |
282 | # ==> OmniAuth
283 | # Add a new OmniAuth provider. Check the wiki for more information on setting
284 | # up on your models and hooks.
285 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
286 |
287 | # ==> Warden configuration
288 | # If you want to use other strategies, that are not supported by Devise, or
289 | # change the failure app, you can configure them inside the config.warden block.
290 | #
291 | # config.warden do |manager|
292 | # manager.intercept_401 = false
293 | # manager.default_strategies(scope: :user).unshift :some_external_strategy
294 | # end
295 |
296 | # ==> Mountable engine configurations
297 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
298 | # is mountable, there are some extra configurations to be taken into account.
299 | # The following options are available, assuming the engine is mounted as:
300 | #
301 | # mount MyEngine, at: '/my_engine'
302 | #
303 | # The router that invoked `devise_for`, in the example above, would be:
304 | # config.router_name = :my_engine
305 | #
306 | # When using OmniAuth, Devise cannot automatically set OmniAuth path,
307 | # so you need to do it manually. For the users scope, it would be:
308 | # config.omniauth_path_prefix = '/my_engine/users/auth'
309 |
310 | # ==> Turbolinks configuration
311 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
312 | #
313 | # ActiveSupport.on_load(:devise_failure_app) do
314 | # include Turbolinks::Controller
315 | # end
316 |
317 | # ==> Configuration for :registerable
318 |
319 | # When set to false, does not sign a user in automatically after their password is
320 | # changed. Defaults to true, so a user is signed in automatically after changing a password.
321 | # config.sign_in_after_change_password = true
322 | end
323 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Configure sensitive parameters which will be filtered from the log file.
6 | Rails.application.config.filter_parameters += %i[
7 | passw secret token _key crypt salt certificate otp ssn
8 | ]
9 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Be sure to restart your server when you modify this file.
3 |
4 | # Add new inflection rules using the following format. Inflections
5 | # are locale specific, and you may define rules for as many different
6 | # locales as you wish. All of these examples are active by default:
7 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
8 | # inflect.plural /^(ox)$/i, '\1en'
9 | # inflect.singular /^(ox)en/i, '\1'
10 | # inflect.irregular 'person', 'people'
11 | # inflect.uncountable %w( fish sheep )
12 | # end
13 |
14 | # These inflection rules are supported but not enabled by default:
15 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
16 | # inflect.acronym 'RESTful'
17 | # end
18 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # Be sure to restart your server when you modify this file.
3 |
4 | # Add new mime types for use in respond_to blocks:
5 | # Mime::Type.register "text/richtext", :rtf
6 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # This file contains settings for ActionController::ParamsWrapper which
6 | # is enabled by default.
7 |
8 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
9 | ActiveSupport.on_load(:action_controller) do
10 | wrap_parameters format: [:json]
11 | end
12 |
13 | # To enable root element in JSON for ActiveRecord objects.
14 | # ActiveSupport.on_load(:active_record) do
15 | # self.include_root_in_json = true
16 | # end
17 |
--------------------------------------------------------------------------------
/config/locales/devise.en.yml:
--------------------------------------------------------------------------------
1 | # Additional translations at https://github.com/heartcombo/devise/wiki/I18n
2 |
3 | en:
4 | devise:
5 | confirmations:
6 | confirmed: "Your email address has been successfully confirmed."
7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9 | failure:
10 | already_authenticated: "You are already signed in."
11 | inactive: "Your account is not activated yet."
12 | invalid: "Invalid %{authentication_keys} or password."
13 | locked: "Your account is locked."
14 | last_attempt: "You have one more attempt before your account is locked."
15 | not_found_in_database: "Invalid %{authentication_keys} or password."
16 | timeout: "Your session expired. Please sign in again to continue."
17 | unauthenticated: "You need to sign in or sign up before continuing."
18 | unconfirmed: "You have to confirm your email address before continuing."
19 | mailer:
20 | confirmation_instructions:
21 | subject: "Confirmation instructions"
22 | reset_password_instructions:
23 | subject: "Reset password instructions"
24 | unlock_instructions:
25 | subject: "Unlock instructions"
26 | email_changed:
27 | subject: "Email Changed"
28 | password_change:
29 | subject: "Password Changed"
30 | omniauth_callbacks:
31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
32 | success: "Successfully authenticated from %{kind} account."
33 | passwords:
34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
37 | updated: "Your password has been changed successfully. You are now signed in."
38 | updated_not_active: "Your password has been changed successfully."
39 | registrations:
40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
41 | signed_up: "Welcome! You have signed up successfully."
42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
46 | updated: "Your account has been updated successfully."
47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again."
48 | sessions:
49 | signed_in: "Signed in successfully."
50 | signed_out: "Signed out successfully."
51 | already_signed_out: "Signed out successfully."
52 | unlocks:
53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue."
56 | errors:
57 | messages:
58 | already_confirmed: "was already confirmed, please try signing in"
59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
60 | expired: "has expired, please request a new one"
61 | not_found: "not found"
62 | not_locked: "was not locked"
63 | not_saved:
64 | one: "1 error prohibited this %{resource} from being saved:"
65 | other: "%{count} errors prohibited this %{resource} from being saved:"
66 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at https://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Puma can serve each request in a thread from an internal thread pool.
4 | # The `threads` method setting takes two numbers: a minimum and maximum.
5 | # Any libraries that use thread pools should be configured to match
6 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
7 | # and maximum; this matches the default thread size of Active Record.
8 | #
9 | max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
10 | min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
11 | threads min_threads_count, max_threads_count
12 |
13 | # Specifies the `worker_timeout` threshold that Puma will use to wait before
14 | # terminating a worker in development environments.
15 | #
16 | worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
17 |
18 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
19 | #
20 | port ENV.fetch('PORT', 3000)
21 |
22 | # Specifies the `environment` that Puma will run in.
23 | #
24 | environment ENV.fetch('RAILS_ENV', 'development')
25 |
26 | # Specifies the `pidfile` that Puma will use.
27 | pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
28 |
29 | # Specifies the number of `workers` to boot in clustered mode.
30 | # Workers are forked web server processes. If using threads and workers together
31 | # the concurrency of the application would be max `threads` * `workers`.
32 | # Workers do not work on JRuby or Windows (both of which do not support
33 | # processes).
34 | #
35 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
36 |
37 | # Use the `preload_app!` method when specifying a `workers` number.
38 | # This directive tells Puma to first boot the application and load code
39 | # before forking the application. This takes advantage of Copy On Write
40 | # process behavior so workers use less memory.
41 | #
42 | # preload_app!
43 |
44 | # Allow puma to be restarted by `rails restart` command.
45 | plugin :tmp_restart
46 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Rails.application.routes.draw do
4 | resources :posts
5 | devise_for :users, controllers: {
6 | registrations: :registrations,
7 | sessions: :sessions
8 | }
9 |
10 | root to: 'home#index'
11 | get '/member', to: 'members#show'
12 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
13 | end
14 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Spring.watch(
4 | '.ruby-version',
5 | '.rbenv-vars',
6 | 'tmp/restart.txt',
7 | 'tmp/caching-dev.txt'
8 | )
9 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket
23 |
24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/db/migrate/20210719192747_devise_create_users.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class DeviseCreateUsers < ActiveRecord::Migration[6.1]
4 | def change
5 | create_table :users do |t|
6 | ## Database authenticatable
7 | t.string :email, null: false, default: ''
8 | t.string :encrypted_password, null: false, default: ''
9 |
10 | ## Recoverable
11 | t.string :reset_password_token
12 | t.datetime :reset_password_sent_at
13 |
14 | ## Rememberable
15 | t.datetime :remember_created_at
16 |
17 | ## Trackable
18 | # t.integer :sign_in_count, default: 0, null: false
19 | # t.datetime :current_sign_in_at
20 | # t.datetime :last_sign_in_at
21 | # t.string :current_sign_in_ip
22 | # t.string :last_sign_in_ip
23 |
24 | ## Confirmable
25 | # t.string :confirmation_token
26 | # t.datetime :confirmed_at
27 | # t.datetime :confirmation_sent_at
28 | # t.string :unconfirmed_email # Only if using reconfirmable
29 |
30 | ## Lockable
31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
32 | # t.string :unlock_token # Only if unlock strategy is :email or :both
33 | # t.datetime :locked_at
34 |
35 | t.timestamps null: false
36 | end
37 |
38 | add_index :users, :email, unique: true
39 | add_index :users, :reset_password_token, unique: true
40 | # add_index :users, :confirmation_token, unique: true
41 | # add_index :users, :unlock_token, unique: true
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/db/migrate/20210719202728_create_jwt_denylist.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class CreateJwtDenylist < ActiveRecord::Migration[6.1]
4 | def change
5 | create_table :jwt_denylist do |t|
6 | t.string :jti, null: false
7 | t.datetime :exp, null: false
8 | end
9 | add_index :jwt_denylist, :jti
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/migrate/20210722104524_create_posts.rb:
--------------------------------------------------------------------------------
1 | class CreatePosts < ActiveRecord::Migration[6.1]
2 | def change
3 | create_table :posts do |t|
4 | t.string :title
5 | t.text :body
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20210722110151_add_user_to_posts.rb:
--------------------------------------------------------------------------------
1 | class AddUserToPosts < ActiveRecord::Migration[6.1]
2 | def change
3 | add_reference :posts, :user, null: false, foreign_key: true
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # This file is the source Rails uses to define your schema when running `bin/rails
6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7 | # be faster and is potentially less error prone than running all of your
8 | # migrations from scratch. Old migrations may fail to apply correctly if those
9 | # migrations use external dependencies or application code.
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 2021_07_22_110151) do
14 |
15 | # These are extensions that must be enabled in order to support this database
16 | enable_extension "plpgsql"
17 |
18 | create_table "jwt_denylist", force: :cascade do |t|
19 | t.string "jti", null: false
20 | t.datetime "exp", null: false
21 | t.index ["jti"], name: "index_jwt_denylist_on_jti"
22 | end
23 |
24 | create_table "posts", force: :cascade do |t|
25 | t.string "title"
26 | t.text "body"
27 | t.datetime "created_at", precision: 6, null: false
28 | t.datetime "updated_at", precision: 6, null: false
29 | t.bigint "user_id", null: false
30 | t.index ["user_id"], name: "index_posts_on_user_id"
31 | end
32 |
33 | create_table "users", force: :cascade do |t|
34 | t.string "email", default: "", null: false
35 | t.string "encrypted_password", default: "", null: false
36 | t.string "reset_password_token"
37 | t.datetime "reset_password_sent_at"
38 | t.datetime "remember_created_at"
39 | t.datetime "created_at", precision: 6, null: false
40 | t.datetime "updated_at", precision: 6, null: false
41 | t.index ["email"], name: "index_users_on_email", unique: true
42 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
43 | end
44 |
45 | add_foreign_key "posts", "users"
46 | end
47 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 | # This file should contain all the record creation needed to seed the database with its default values.
3 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
4 | #
5 | # Examples:
6 | #
7 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
8 | # Character.create(name: 'Luke', movie: movies.first)
9 |
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/log/.keep
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 |
--------------------------------------------------------------------------------
/storage/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/storage/.keep
--------------------------------------------------------------------------------
/test/channels/application_cable/connection_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | module ApplicationCable
6 | class ConnectionTest < ActionCable::Connection::TestCase
7 | # test "connects with cookies" do
8 | # cookies.signed[:user_id] = 42
9 | #
10 | # connect
11 | #
12 | # assert_equal connection.user_id, "42"
13 | # end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/test/controllers/.keep
--------------------------------------------------------------------------------
/test/controllers/posts_controller_test.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 |
3 | class PostsControllerTest < ActionDispatch::IntegrationTest
4 | setup do
5 | @post = posts(:one)
6 | end
7 |
8 | test "should get index" do
9 | get posts_url, as: :json
10 | assert_response :success
11 | end
12 |
13 | test "should create post" do
14 | assert_difference('Post.count') do
15 | post posts_url, params: { post: { body: @post.body, title: @post.title } }, as: :json
16 | end
17 |
18 | assert_response 201
19 | end
20 |
21 | test "should show post" do
22 | get post_url(@post), as: :json
23 | assert_response :success
24 | end
25 |
26 | test "should update post" do
27 | patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }, as: :json
28 | assert_response 200
29 | end
30 |
31 | test "should destroy post" do
32 | assert_difference('Post.count', -1) do
33 | delete post_url(@post), as: :json
34 | end
35 |
36 | assert_response 204
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/test/fixtures/files/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/test/fixtures/files/.keep
--------------------------------------------------------------------------------
/test/fixtures/posts.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | title: MyString
5 | body: MyText
6 |
7 | two:
8 | title: MyString
9 | body: MyText
10 |
--------------------------------------------------------------------------------
/test/fixtures/users.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | # This model initially had no columns defined. If you add columns to the
4 | # model remove the '{}' from the fixture names and add the columns immediately
5 | # below each fixture, per the syntax in the comments below
6 | #
7 | one: {}
8 | # column: value
9 | #
10 | two: {}
11 | # column: value
12 |
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/test/integration/.keep
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/test/mailers/.keep
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/test/models/.keep
--------------------------------------------------------------------------------
/test/models/post_test.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 |
3 | class PostTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/user_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class UserTest < ActiveSupport::TestCase
6 | # test "the truth" do
7 | # assert true
8 | # end
9 | end
10 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | ENV['RAILS_ENV'] ||= 'test'
4 | require_relative '../config/environment'
5 | require 'rails/test_help'
6 |
7 | module ActiveSupport
8 | class TestCase
9 | # Run tests in parallel with specified workers
10 | parallelize(workers: :number_of_processors)
11 |
12 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
13 | fixtures :all
14 |
15 | # Add more helper methods to be used by all tests here...
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/tmp/.keep
--------------------------------------------------------------------------------
/tmp/pids/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/tmp/pids/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arikarim/React-Rails-Back-End/d015dfe2a30cfdf24fe87ab3c140081ed7986721/vendor/.keep
--------------------------------------------------------------------------------