diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c479bf3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity + + +/tmp +/db/data +/.git* +/.idea diff --git a/.gitignore b/.gitignore index f22dd34..4284248 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,12 @@ # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' +# ignore local_env file for gmail account info +/config/local_env.yml + +#ignore .env +.env + # Ignore bundler config. /.bundle @@ -34,3 +40,6 @@ /yarn-error.log yarn-debug.log* .yarn-integrity + +.env +/db/data diff --git a/.ruby-version b/.ruby-version index ccfb6ef..2eb2fe9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.7.0 +ruby-2.7.2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8702a7d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM ruby:2.7.2 + +# Unimportant Container configuration +RUN apt-get update -qq +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt-get update && apt-get install -y yarn + +# Transfer ownership away from root (bad) to dedicated rails_user (good). +WORKDIR /cc_server +RUN useradd -ms /bin/bash rails_user +RUN chown -R rails_user:rails_user /cc_server +RUN chmod 755 /cc_server +USER rails_user + +# Install all dependencies through `gem` and `yarn` package managers. +COPY --chown=rails_user:rails_user Gemfile /cc_server/Gemfile +COPY --chown=rails_user:rails_user Gemfile.lock /cc_server/Gemfile.lock +RUN gem install bundler:2.2.8 && bundle install + +COPY --chown=rails_user:rails_user package.json /cc_server/package.json +COPY --chown=rails_user:rails_user yarn.lock /cc_server/yarn.lock +RUN yarn install --check-files + +# Expose ports for access either from `dev` (:3000) or `prod` (:80 and :443) +EXPOSE 3000 +EXPOSE 443 +EXPOSE 80 + +# Start the main process. +CMD rm -f tmp/pids/server.pid; rails server -b '0.0.0.0' diff --git a/Gemfile b/Gemfile index 9ddcd33..c13c1a0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,13 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.7.0' +ruby '2.7.2' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.1.1' # Use mysql as the database for Active Record gem 'mysql2', '~> 0.5' +gem 'pg' # Use Puma as the app server gem 'puma', '~> 5.0' # Use SCSS for stylesheets @@ -21,6 +22,8 @@ gem 'jbuilder', '~> 2.7' # gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' +# Use Devise for user sessions and management +gem 'devise', '~> 4.7.1' # Use Active Storage variant # gem 'image_processing', '~> 1.2' @@ -54,3 +57,8 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem "phonelib", "~> 0.6.48" +gem 'semantic-ui-sass' +gem 'purecss' +gem 'faker' diff --git a/Gemfile.lock b/Gemfile.lock index 2a5b745..12aa8e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,29 +62,42 @@ GEM zeitwerk (~> 2.3) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) + bcrypt (3.1.16) + bcrypt (3.1.16-java) bindex (0.8.1) - bootsnap (1.5.1) + bootsnap (1.7.0) msgpack (~> 1.0) builder (3.2.4) byebug (11.1.3) - capybara (3.34.0) + capybara (3.35.3) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.5) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (3.0.0) concurrent-ruby (1.1.8) crass (1.0.6) + devise (4.7.3) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) erubi (1.10.0) + faker (2.15.1) + i18n (>= 1.6, < 2) ffi (1.14.2) + ffi (1.14.2-java) + ffi (1.14.2-x64-mingw32) + ffi (1.14.2-x86-mingw32) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.8.7) + i18n (1.8.8) concurrent-ruby (~> 1.0) - jbuilder (2.11.1) + jbuilder (2.11.2) activesupport (>= 5.0.0) listen (3.4.1) rb-fsevent (~> 0.10, >= 0.10.3) @@ -99,18 +112,42 @@ GEM method_source (1.0.0) mimemagic (0.3.5) mini_mime (1.0.2) + mini_portile2 (2.5.0) minitest (5.14.3) - msgpack (1.3.3) + msgpack (1.4.2) + msgpack (1.4.2-java) mysql2 (0.5.3) nio4r (2.5.4) + nio4r (2.5.4-java) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) + nokogiri (1.11.1-java) + racc (~> 1.4) + nokogiri (1.11.1-x64-mingw32) + racc (~> 1.4) + nokogiri (1.11.1-x86-mingw32) + racc (~> 1.4) nokogiri (1.11.1-x86_64-darwin) racc (~> 1.4) + nokogiri (1.11.1-x86_64-linux) + racc (~> 1.4) + orm_adapter (0.5.0) + pg (1.2.3) + pg (1.2.3-x64-mingw32) + pg (1.2.3-x86-mingw32) + phonelib (0.6.48) public_suffix (4.0.6) - puma (5.1.1) + puma (5.2.0) + nio4r (~> 2.0) + puma (5.2.0-java) nio4r (~> 2.0) + purecss (0.5.0.2) + rails (>= 3.1) racc (1.5.2) + racc (1.5.2-java) rack (2.2.3) - rack-mini-profiler (2.3.0) + rack-mini-profiler (2.3.1) rack (>= 1.2.0) rack-proxy (0.6.5) rack @@ -146,12 +183,22 @@ GEM rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (1.8.2) + regexp_parser (2.0.3) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) rubyzip (2.3.0) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) ffi (~> 1.9) + sassc (2.4.0-x64-mingw32) + ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) @@ -161,6 +208,8 @@ GEM selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) + semantic-ui-sass (2.4.2.0) + sass (>= 3.2) semantic_range (2.3.1) spring (2.1.1) sprockets (4.0.2) @@ -177,6 +226,8 @@ GEM turbolinks-source (5.2.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) + warden (1.2.9) + rack (>= 2.0.9) web-console (4.1.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -193,26 +244,40 @@ GEM semantic_range (>= 2.3.0) websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) + websocket-driver (0.7.3-java) + websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.4.2) PLATFORMS + java + x64-mingw32 + x86-mingw32 + x86-mswin32 x86_64-darwin-19 + x86_64-darwin-20 + x86_64-linux DEPENDENCIES bootsnap (>= 1.4.4) byebug capybara (>= 3.26) + devise (~> 4.7.1) + faker jbuilder (~> 2.7) listen (~> 3.3) mysql2 (~> 0.5) + pg + phonelib (~> 0.6.48) puma (~> 5.0) + purecss rack-mini-profiler (~> 2.0) rails (~> 6.1.1) sass-rails (>= 6) selenium-webdriver + semantic-ui-sass spring turbolinks (~> 5) tzinfo-data @@ -221,7 +286,7 @@ DEPENDENCIES webpacker (~> 5.0) RUBY VERSION - ruby 2.7.0p0 + ruby 2.7.2p137 BUNDLED WITH - 2.2.1 + 2.2.8 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..c56b7de --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bin/rails db:migrate; bin/rails server -p ${PORT:-5000} -e $RAILS_ENV \ No newline at end of file diff --git a/README.md b/README.md index 7db80e4..fa75c5b 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,114 @@ -# README +# Carrie's Closet -This README would normally document whatever steps are necessary to get the -application up and running. +## Getting Started +On windows, make sure you set git [to use unix line endings](https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings) +when checking out and committing. -Things you may want to cover: +If you've already checked out and have windows line endings, you may encounter +an error stating: `env: ruby\r: No such file or directory`. To resolve, run +`find ./ -type f -exec dos2unix {} \;`. -* Ruby version +After a clean install of this repo, you'll need to run `bundle install` inside +the `CarriesCloset` root folder. This will install all needed requirements. + +Additionally, **duplicate** the file `example.env` in the root level directory. +Once duplicated, rename the duplicate, e.g. `example.env (1)`, to just `.env`. +This may cause the `.env` to disapear from your file brower, but don't worry +if you've named the file correctly. -* System dependencies +## Database Creation +You'll need to have MySQL installed and running locally. -* Configuration +## Database Initialization +Depending on whether or not you've run the Rails server recently, or if you're + having troubles with your database/server, you'll want to run the following: +```shell +bin/rails db:drop +bin/rails db:create db:migrate db:seed +``` +## ActionMailer for Confirmation Emails +- You can preview a sample email at http://localhost:3000/rails/mailers/user_mailer/ by clicking on new email. +- Accessing Environment Variables Containing GMAIL Account info: + - Make a copy of `config\EXAMPLE_local_env.yml` in the config file and rename it just `local_env.yml`. This way the SMTP settings will have access to the GMAIL login info. +- When you hit the create request button, + - you can see the html and text versions of the confirmation email in your terminal. + - you should also receive the actual email from Carrie's Closet (carries.closet.confirmations@gmail.com) at the email address you entered on the form, so make sure you enter a valid address. +- If you want to temporarily disable email deliveries (you'll still be able to see them in you terminal): + 1. navigate to `config\environments\development.rb` + 2. search for the line `config.action_mailer.perform_deliveries = true` + 3. change it to `config.action_mailer.perform_deliveries = false` + 4. restart server + + Note: that same line is also in `config\environments\production.rb` and `config\environments\test.rb`, so you can also make that change in those files as well depending on + what environment you are working in. + + Note: When you want to start receiving emails again, just make those lines `config.action_mailer.perform_deliveries = true` again and restart the server. + +- If you get an SMTP Authentication Error, it usually means the environment variable with the GMAIL account info is not working, so follow these steps: + 1. Go to `config\development.rb` and scroll down to the ActionMailer settings where you will see `user_name: ENV["GMAIL_USERNAME"],` and `password: ENV["APP_PASSWORD"]` + 2. Go to `config\EXAMPLE_local_env.yml` and copy the `GMAIL_USERNAME` value and paste it in place of `ENV["GMAIL_USERNAME"]` (leave the comma at the end of the line). + 3. Copy the `APP_PASSWORD` value and paste it in place of `ENV["APP_PASSWORD"]`. + 4. Save and restart server. + + Note: that these same lines are also in `config\environments\production.rb` and `config\environments\test.rb`, so you can also make that change in those files as well + depending on what environment you are working in. -* Database creation + -* Database initialization +## Asset Installation +To install all the packaged Javascript libraries locally (suggested for +performance improvements), run: +```shell +bin/rails webpacker:install +``` -* How to run the test suite +## Running with Docker +To run the full app stack, run the following commands: +```shell +docker-compose build --parallel +docker-compose up -d +docker exec cc_server bin/rails db:create +docker exec cc_server bin/rails db:environment:set RAILS_ENV=development +docker exec cc_server bin/rails db:migrate db:seed +``` -* Services (job queues, cache servers, search engines, etc.) +This will create the `cc_mysql` MySQL Docker container, the `cc_redis` Redis +caching store, and the `cc_server` Rails server. Both commands should complete +without error to let you know everything is running properly. The Rails server +will run on http://127.0.0.1:3000 in most environments. -* Deployment instructions +## General Rails Tips +- Always use `bin/rails` when running commands from the terminal (this will + point to the proper Carrie's Closet project) +- `bin/rails console --sandbox` will create a sandboxed version of a REPL-style + console, loaded with all the classes and data from your running app. Any + changes made in the sandbox will be reverted when you `exit`. +- `bin/rails generate Tweet user:references body:text likes:integer` will + create a `Tweet` model that belongs to a `User` model. Each `Tweet` will be + stored in the database with a `body` text field and a `likes` counter. +- `bin/rails destroy Tweet` will revert all generated files for the previous + `Tweet` model. + +## Running with Docker +To run the full app stack, run the following commands: +```shell +docker-compose build --parallel && docker-compose up -d +docker exec cc_server sh -c "bin/rails db:create && bin/rails db:migrate && bin/rails db:seed" +docker exec cc_server sh -c "rails webpacker:install" +``` + +Note that on Windows, you may need to run these command seprately. Eg. +``` +docker-compose build --parallel +docker-compose up -d +docker exec cc_server sh -c "bin/rails db:create" +docker exec cc_server sh -c "bin/rails db:migrate" +docker exec cc_server sh -c "bin/rails db:seed" +docker exec cc_server sh -c "rails webpacker:install" +``` + +This will create the `cc_mysql` MySQL Docker container, the `cc_redis` Redis +caching store, and the `cc_server` Rails server. Both commands should complete +without error to let you know everything is running properly. The Rails server +will run on http://127.0.0.1:3000 in most environments. -* ... diff --git a/app/assets/images/back.png b/app/assets/images/back.png new file mode 100644 index 0000000..877a801 Binary files /dev/null and b/app/assets/images/back.png differ diff --git a/app/assets/images/home.png b/app/assets/images/home.png new file mode 100644 index 0000000..d96c762 Binary files /dev/null and b/app/assets/images/home.png differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 0000000..1f1f254 Binary files /dev/null and b/app/assets/images/logo.png differ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f..606bc46 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -12,4 +12,5 @@ * *= require_tree . *= require_self + *= require purecss */ diff --git a/app/assets/stylesheets/public.scss b/app/assets/stylesheets/public.scss new file mode 100644 index 0000000..b6c1c7c --- /dev/null +++ b/app/assets/stylesheets/public.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the public controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/requests.scss b/app/assets/stylesheets/requests.scss new file mode 100644 index 0000000..382f39d --- /dev/null +++ b/app/assets/stylesheets/requests.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Requests controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..bb2597f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,65 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; } + +a { + color: #000; } + +a:visited { + color: #666; } + +a:hover { + color: #fff; + background-color: #000; } + +th { + padding-bottom: 5px; } + +td { + padding: 0 5px 7px; } + +div.field, +div.actions { + margin-bottom: 10px; } + +#notice { + color: green; } + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; } + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; } + +#error_explanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; } + +#error_explanation ul li { + font-size: 12px; + list-style: square; } + +label { + display: block; } diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css new file mode 100644 index 0000000..a364c53 --- /dev/null +++ b/app/assets/stylesheets/style.css @@ -0,0 +1,177 @@ +body { + font-family: Cabin; + font-size: medium; + font-color: #000; + background-color: white; + +} + +p { + font-family: Cabin; + font-size: medium; + font-color: #000; + background-color: white; + +} + +a:link, a:active, a:visited, a:hover { + color: #74b9cb; +} + + +a.home-link:link, a.home-link:active, a.home-link:visited { + background-color: #74b9cb; + color: #1b1b1b; + padding: 1em 1.5em; + text-decoration: none; + margin-left: 5px; + margin-right: 5px; + font-family: Cabin; + border: 2px solid #74b9cb; + border-radius: 5px; + width:100%; + text-align:center; + font-style: normal; + font-weight: normal; + font-size: 24px; + line-height: 29px; + display: inline-block; + width: 80%; + + align-items: center; +} + +a.home-link:hover { + background-color: #e8f6fb; + color: #1b1b1b; + padding: 1em 1.5em; + text-decoration: none; + margin-left: 5px; + margin-right: 5px; + font-family: Cabin; + border: 2px solid #74b9cb; + border-radius: 5px; + width:100%; + text-align:center; + font-style: normal; + font-weight: normal; + font-size: 24px; + line-height: 29px; + display: inline-block; + width: 80%; + + align-items: center; +} + +a.small-link-button:link, a.small-link-button:active,a.small-link-button:visited { + background-color: #e8f6fb; + color: #1b1b1b; + padding: 1em 1.5em; + text-decoration: none; + margin-left: 5px; + margin-right: 5px; + font-family: Cabin; + border: 2px solid #74b9cb; + border-radius: 5px; + text-align:center; + font-style: normal; + font-weight: normal; + font-size: 12px; + display: inline-block; + + align-items: center; +} + +a.small-link-button:hover { + +} + +.margins-needed { + margin-left:1%; +margin-right:1%; +margin-bottom:1%; +margin-top:1%; +} + +.centered-div { + display: flex; + justify-content: center; +} + +input { + margin-bottom: 5px; +} + + +p.contact-info { + font-family: Cabin; + font-size: medium; + font-color: #000; + background-color: white; + line-height: 150%; + border: 2px solid #74b9cb; + padding: 1em 1.5em; + background-color: #e8f6fb; + text-align:center; + width: 60%; + font-size: 18px; + +} + +div#container { + width: 760px; + margin: 0 auto; +} + +div#header { + text-align: center; + padding-bottom: 15px; +} + +div#content { + float: left; + width: 450px; + padding: 10px; +} + +div#content h3 { + margin-top: 15px; +} + +ul#books { + list-style-type: none; +} + +ul#books li { + line-height: 140%; +} + +div#sidebar { + width: 200px; + margin-left: 480px; +} + +ul#subjects { + width: 700px; + text-align: center; + padding: 5px; + background-color: #ececec; + border: 1px solid #ccc; + margin-bottom: 20px; +} + +ul#subjects li { + display: inline; + padding-left: 5px; +} + +.nav-bar { + background-color: #e8f6fb; + width: 100%; + display: flex; + justify-content: center; + align-items: center; +} +.navbar-element { + align-items: center; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..26c72ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,24 @@ class ApplicationController < ActionController::Base + # Basic authorization available to all controllers, allowing for fine-tuned + # access limitation based on defined User roles. To protect a Controller + # method, add something like the following to the top of the Controller: + # + # before_action -> { require_roles(:root, :admin) }, only: :index + # + # Here, the user's roles will only be checked when the visit the `index` + # route on the controller, e.g. `/requests`. If the user fails the check, + # they will be redirected to `:root`, the home route of the project. Finally, + # we configure that only users with `admin` abilities should be able to + # access the protected `index` route. + def require_role(redirect_path, role) + should_reject = false + case role + when :admin; should_reject = true unless current_user.admin? + when :volunteer; should_reject = true unless current_user.volunteer? + when :donee; should_reject = true unless current_user.donee? + when :donor; should_reject = true unless current_user.donor? + end + + redirect_to redirect_path, alert: 'You do not have proper authorization to access the attempted URL.' if should_reject + end end diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb new file mode 100644 index 0000000..2d7105b --- /dev/null +++ b/app/controllers/public_controller.rb @@ -0,0 +1,4 @@ +class PublicController < ApplicationController + def index + end +end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb new file mode 100644 index 0000000..d11be5b --- /dev/null +++ b/app/controllers/requests_controller.rb @@ -0,0 +1,85 @@ +class RequestsController < ApplicationController + before_action :set_request, only: %i[ show edit update destroy ] + + before_action :authenticate_user!, only: %i[ index, my_requests ] + + before_action -> { require_role(:root, :admin) }, only: :index + + # GET /requests or /requests.json + def index + @requests = Request.all + end + + # GET /requests/1 or /requests/1.json + def show + end + + # GET /requests/new + def new + @request = Request.new + end + + # GET /requests/1/edit + def edit + end + + # GET /requests/my-requests + def my_requests + @requests = current_user != nil ? Request.where("email like ?", "%#{current_user.email}%") : nil + end + + # POST /requests or /requests.json + def create + @request = Request.new(request_params) + + respond_to do |format| + if @request.save + + + # ActionMailer should send email immediately after new request creation is saved + UserMailer.with(request: @request).new_email.deliver_later + + + format.html { redirect_to @request, notice: "Request was successfully created." } + format.json { render :show, status: :created, location: @request } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @request.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /requests/1 or /requests/1.json + def update + respond_to do |format| + if @request.update(request_params) + format.html { redirect_to @request, notice: "Request was successfully updated." } + format.json { render :show, status: :ok, location: @request } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @request.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /requests/1 or /requests/1.json + def destroy + @request.destroy + respond_to do |format| + format.html { redirect_to requests_url, notice: "Request was successfully destroyed." } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_request + @request = Request.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def request_params + params.require(:request).permit(:urgency, :full_name, :email, :phone, :relationship, :county, :meet, :address, :availability, :items, :comments) + end +end diff --git a/app/helpers/public_helper.rb b/app/helpers/public_helper.rb new file mode 100644 index 0000000..0d8e188 --- /dev/null +++ b/app/helpers/public_helper.rb @@ -0,0 +1,2 @@ +module PublicHelper +end diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb new file mode 100644 index 0000000..53ac95c --- /dev/null +++ b/app/helpers/requests_helper.rb @@ -0,0 +1,2 @@ +module RequestsHelper +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..1e527e6 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,6 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + #"SenderName " + default from: "Carrie's Closet " + #default from: 'carries.closet.confirmations@gmail.com' layout 'mailer' end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..87af19f --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -0,0 +1,10 @@ +class UserMailer < ApplicationMailer + + + def new_email + # UserMailer.with(user: User.first).welcome_email + @request = params[:request] + mail to: @request.email, + subject: "Donation Request Confirmation" + end +end diff --git a/app/models/request.rb b/app/models/request.rb new file mode 100644 index 0000000..8696c9b --- /dev/null +++ b/app/models/request.rb @@ -0,0 +1,46 @@ +class Request < ApplicationRecord + URGENCIES = { + '': 0, + 'Within 24 hours': 1, + 'Within 48 hours': 2, + 'Within a week': 3, + }.freeze + + RELATIONSHIPS = { + '': 0, + 'Foster Child': 1, + 'Juvenile Detention Center': 2, + 'Domestic Violence Center': 3, + 'Homeless Youth': 4, + 'Refugee/Displaced Person': 5, + }.freeze + + COUNTIES = { + '': 0, + 'Fulton': 1, + 'Dekalb': 2, + 'Gwinnet': 3, + 'Cobb': 4, + 'Clayton': 5, + 'Henry': 6, + 'Muscogee': 7, + 'Other (provide your address below)': 8 + }.freeze + + validates_presence_of :relationship, :full_name, :urgency, :email, :availability, + :county, :meet, :phone, :items + + validates_numericality_of :urgency, :relationship, :county, greater_than: 0, :message => "can't be blank" + + validates :email, format: { with: URI::MailTo::EMAIL_REGEXP } + + validates :phone, phone: true + + validates :address, + presence: true, + length: { in: 7..200 }, + if: Proc.new { |a| a.meet == 2} + + validates :full_name, + length: { in: 2..80 } +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..cd40702 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,13 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable + + # Adds in several different ways to query all `User` objects. For example, to + # get all users marked as administrators, you can use `User.admins`. + scope :admins, -> { where(admin: true) } + scope :volunteers, -> { where(volunteer: true) } + scope :donees, -> { where(donee: true) } + scope :donors, -> { where(donor: true) } +end diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 0000000..b12dd0c --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..dc55f64 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000..32f4ba8 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000..b41daf4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f667dc1 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..41e148b --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..5fbb9ff --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 0000000..9b486b8 --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 0000000..38d95b8 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..d655b66 --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 0000000..5ede964 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,26 @@ +

Log in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "current-password" %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
+ <% end %> + +
+ <%= f.submit "Log in" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_error_messages.html.erb b/app/views/devise/shared/_error_messages.html.erb new file mode 100644 index 0000000..ba7ab88 --- /dev/null +++ b/app/views/devise/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+
    + <% resource.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 0000000..084af70 --- /dev/null +++ b/app/views/devise/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end %> +<% end %> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 0000000..ffc34de --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4a84e16..b181a43 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,16 +1,39 @@ - CarriesCloset + Carrie's Closet <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + <%#= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + + + +

<%= notice %>

+

<%= alert %>

<%= yield %> diff --git a/app/views/public/index.html.erb b/app/views/public/index.html.erb new file mode 100644 index 0000000..ff79d45 --- /dev/null +++ b/app/views/public/index.html.erb @@ -0,0 +1,35 @@ + +
+ <% if current_user != nil %> +
+ <%= link_to "My Requests", "requests/my_requests", class: "home-link" %> +
+
+ + <% if current_user.admin? %> +
+ <%= link_to "All Requests", "requests/", class: "home-link" %> +
+
+ <% end %> + <% end %> + +
+ <%= link_to 'Request Clothing and Hygiene Items', new_request_url, class: "home-link"%> +
+
+
+ <%= link_to "Donate Items", root_path, class: "home-link" %> +
+
+
+ <%= link_to "Volunteer", root_path, class: "home-link" %> +
+
+
+ <%= link_to "Support Our Cause", root_path, class: "home-link" %> +
+
+

Contact Information:
carrie.closets@gmail.com

+
+
\ No newline at end of file diff --git a/app/views/requests/_form.html.erb b/app/views/requests/_form.html.erb new file mode 100644 index 0000000..f777c59 --- /dev/null +++ b/app/views/requests/_form.html.erb @@ -0,0 +1,80 @@ + +<%= form_with(model: request, html: { class: 'pure-form pure-form-stacked' }) do |form| %> + + <% if request.errors.any? %> +
+

<%= pluralize(request.errors.count, "error") %> prohibited this request from being saved:

+ +
    + <% request.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + + +
+ +
+ <%= form.label :urgency, 'How urgently do you need these items?' %> + <%= form.select :urgency, Request::URGENCIES %> +
+ +
+ <%= form.label :full_name, 'Full Name' %> + <%= form.text_field :full_name %> +
+ +
+ <%= form.label :email %> + <%= form.text_field :email %> +
+ +
+ <%= form.label :phone, 'Phone Number' %> + <%= form.text_field :phone %> +
+ +
+ <%= form.label :relationship, 'I am a guardian/foster parent/case manager for a...' %> + <%= form.select :relationship, Request::RELATIONSHIPS %> +
+ +
+ <%= form.label :county, 'Select county' %> + <%= form.select :county, Request::COUNTIES %> +
+ +
+ <%= form.label :meet, 'Can you meet us at your local DFCS office?' %> + <%= form.collection_radio_buttons :meet, [['Yes', 1], ['No, my address is:', 2]], :last, :first %> + <%= form.text_area :address %> +
+ +
+ <%= link_to 'Find your county\'s DFCS location', 'https://dfcs.georgia.gov/locations', target: :_blank %> +
+ +
+ <%= form.label :availability, 'What\'s your availability?' %> + Please indicate your availability between 10 AM and 7 PM, Monday through Friday. + <%= form.text_field :availability %> +
+ +
+ <%= form.label :items, 'What items would you like to request?' %> + Please indicate the quantity, gender, and sizes of requested items. + <%= form.text_field :items %> +
+ +
+ <%= form.label :comments %> + <%= form.text_area :comments %> +
+ +
+ <%= form.submit %> +
+
+<% end %> diff --git a/app/views/requests/_request.json.jbuilder b/app/views/requests/_request.json.jbuilder new file mode 100644 index 0000000..463341f --- /dev/null +++ b/app/views/requests/_request.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! request, :id, :urgency, :full_name, :email, :phone, :relationship, :county, :meet, :address, :availability, :items, :comments, :created_at, :updated_at +json.url request_url(request, format: :json) diff --git a/app/views/requests/edit.html.erb b/app/views/requests/edit.html.erb new file mode 100644 index 0000000..659c7dd --- /dev/null +++ b/app/views/requests/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Request

+ +<%= render 'form', request: @request %> + +<%= link_to 'Show', @request %> | +<%= link_to 'Back', :back %> diff --git a/app/views/requests/index.html.erb b/app/views/requests/index.html.erb new file mode 100644 index 0000000..1599497 --- /dev/null +++ b/app/views/requests/index.html.erb @@ -0,0 +1,47 @@ +

<%= notice %>

+ +

Requests

+ + + + + + + + + + + + + + + + + + + + + <% @requests.each do |request| %> + + + + + + + + + + + + + + + + + <% end %> + +
UrgencyFull nameEmailPhoneRelationshipCountyMeetAddressAvailabilityItemsComments
<%= request.urgency %><%= request.full_name %><%= request.email %><%= request.phone %><%= request.relationship %><%= request.county %><%= request.meet %><%= request.address %><%= request.availability %><%= request.items %><%= request.comments %><%= link_to 'Show', request %><%= link_to 'Edit', edit_request_path(request) %><%= link_to 'Destroy', request, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Request', new_request_path %> diff --git a/app/views/requests/index.json.jbuilder b/app/views/requests/index.json.jbuilder new file mode 100644 index 0000000..03e9ea6 --- /dev/null +++ b/app/views/requests/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @requests, partial: "requests/request", as: :request diff --git a/app/views/requests/my_requests.html.erb b/app/views/requests/my_requests.html.erb new file mode 100644 index 0000000..6c2be12 --- /dev/null +++ b/app/views/requests/my_requests.html.erb @@ -0,0 +1,46 @@ + +

My Donation Requests

+ + + + + + + + + + + + + + + + + + + <% if @requests != nil %> + + <% @requests.each do |request| %> + + + + + + + + + + + + + + + + <% end %> + + <% end %> +
UrgencyFull nameEmailPhoneRelationshipCountyMeetAddressAvailabilityComments
<%= request.urgency %><%= request.full_name %><%= request.email %><%= request.phone %><%= request.relationship %><%= request.county %><%= request.meet %><%= request.address %><%= request.availability %><%= request.comments %><%= link_to 'Show', request %><%= link_to 'Edit', edit_request_path(request) %><%= link_to 'Destroy', request, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Request', new_request_path %> diff --git a/app/views/requests/new.html.erb b/app/views/requests/new.html.erb new file mode 100644 index 0000000..fdf08e3 --- /dev/null +++ b/app/views/requests/new.html.erb @@ -0,0 +1,5 @@ +

New Request

+ +<%= render 'form', request: @request %> + +<%= link_to 'Back', :back %> diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb new file mode 100644 index 0000000..abfcc52 --- /dev/null +++ b/app/views/requests/show.html.erb @@ -0,0 +1,60 @@ + +
+

Request a Donation: Summary

+

Please review and confirm the summary of your request:

+ +

+ Urgency: + <%= Request::URGENCIES.key(@request.urgency) %> +

+ +

+ Full name: + <%= @request.full_name %> +

+ +

+ Email: + <%= @request.email %> +

+ +

+ Phone: + <%= @request.phone %> +

+ +

+ Relationship: + <%= Request::RELATIONSHIPS.key(@request.relationship) %> +

+ +<% if @request.meet == 1 %> +

+ County: + <%= @request.county %> +

+<% else %> +

+ Address: + <%= @request.address %> +

+<% end %> + +

+ Availability: + <%= @request.availability %> +

+ +

+ Items: + <%= @request.items %> +

+ +

+ Comments: + <%= @request.comments %> +

+ +<%= link_to 'Edit', edit_request_path(@request) %> | +<%= link_to 'Back', :back %> +
diff --git a/app/views/requests/show.json.jbuilder b/app/views/requests/show.json.jbuilder new file mode 100644 index 0000000..3294edd --- /dev/null +++ b/app/views/requests/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "requests/request", request: @request diff --git a/app/views/user_mailer/new_email.html.erb b/app/views/user_mailer/new_email.html.erb new file mode 100644 index 0000000..cb292bb --- /dev/null +++ b/app/views/user_mailer/new_email.html.erb @@ -0,0 +1,36 @@ + + + + + + +

Hi <%= @request.full_name %>,

+

Thank you for placing a donation request with Carrie's Closet!

+

+ This message is to confirm that we received your request. We will contact you within a week to + arrange a pickup time. +

+

+ If you have any inquiries, you can reach us at https://carriesclosetofga.org/contact-us. +

+

+ Request Details
+

+

==============================

+

Name: <%= @request.full_name %>

+

Email: <%= @request.email %>

+

Urgency: <%= Request::URGENCIES.key(@request.relationship) %>

+

Relationship to Donee: <%= Request::RELATIONSHIPS.key(@request.relationship) %>

+

County: <%= Request::COUNTIES.key(@request.county) %>

+

Pickup Location: <%= @request.address.empty? ? 'County DFCS Office' : 'My Address' %>

+

Address (if applicable): <%= @request.address %>

+

Phone: <%= @request.phone %>

+

Availability: <%= @request.availability %>

+

Items: <%= @request.items %>

+

Comments: <%= @request.comments %>

+

==============================

+

Thank you!

+

Sincerely,

+

Carrie's Closet Team

+ + \ No newline at end of file diff --git a/app/views/user_mailer/new_email.text.erb b/app/views/user_mailer/new_email.text.erb new file mode 100644 index 0000000..d446da0 --- /dev/null +++ b/app/views/user_mailer/new_email.text.erb @@ -0,0 +1,25 @@ +Hi <%= @request.full_name %>, +Thank you for placing a donation request with Carrie's Closet! +This message is to confirm that we received your request. We will contact you within a week to arrange a pickup time. +If you have any inquiries, you can reach us at https://carriesclosetofga.org/contact-us. + +Request Details + +============================== +Name: <%= @request.full_name %> +Email: <%= @request.email %> +Urgency: <%= Request::URGENCIES.key(@request.relationship) %> +Relationship to Donee: <%= Request::RELATIONSHIPS.key(@request.relationship) %> +County: <%=Request::COUNTIES.key(@request.county) %> +Pickup Location: <%= @request.address.empty? ? 'County DFCS Office' : 'My Address' %> +Address (if applicable): <%= @request.address %> +Phone: <%= @request.phone %> +Availability: <%= @request.availability %> +Items: <%= @request.items %> +Comments: <%= @request.comments %> +============================== + +Thank you! + +Sincerely, +Carrie's Closet Team diff --git a/config/EXAMPLE_local_env.yml b/config/EXAMPLE_local_env.yml new file mode 100644 index 0000000..e0ff2f1 --- /dev/null +++ b/config/EXAMPLE_local_env.yml @@ -0,0 +1,2 @@ +GMAIL_USERNAME: 'carries.closet.confirmations@gmail.com' +APP_PASSWORD: 'wdyningvalfezuqt' \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 4781c4a..2886300 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,5 +18,18 @@ class Application < Rails::Application # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + + # TODO: Remove wildcard matching when a URL is set. + config.hosts << /.*\.herokuapp\.com/ + config.hosts << "127.0.0.1" + + # FOR ACTION MAILER --------------------------------------------------- + config.before_configuration do + env_file = File.join(Rails.root, 'config', 'local_env.yml') + YAML.load(File.open(env_file)).each do |key, value| + ENV[key.to_s] = value + end if File.exists?(env_file) + #--------------------------------------------------------------------- + end end end diff --git a/config/cable.yml b/config/cable.yml index 3685f91..b85b8fd 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -7,4 +7,4 @@ test: production: adapter: redis url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: CarriesCloset_production + channel_prefix: carries_closet_production diff --git a/config/database.yml b/config/database.yml index ebce91c..0a21b5d 100644 --- a/config/database.yml +++ b/config/database.yml @@ -15,7 +15,7 @@ default: &default pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: - socket: /tmp/mysql.sock + host: <%= ENV.fetch('DATABASE_HOST') { "127.0.0.1" } %> development: <<: *default @@ -49,7 +49,8 @@ test: # for a full overview on how database connection configuration can be specified. # production: - <<: *default - database: CarriesCloset_production - username: CarriesCloset - password: <%= ENV['CARRIESCLOSET_DATABASE_PASSWORD'] %> + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + url: <%= ENV['DATABASE_URL'] %> + diff --git a/config/environments/development.rb b/config/environments/development.rb index 7a9f6c3..66c62d2 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -73,4 +73,26 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + + # Configure mailer options for Devise mailers + config.action_mailer.default_url_options = { host: '127.0.0.1', port: 3000 } + + # ----------------------------------Action Mailer------------------------------------------------ + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "gmail.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["APP_PASSWORD"] + } + # can change host when we have a URL + config.action_mailer.default_url_options = {:host => "127.0.0.1:3000"} + config.action_mailer.delivery_method = :smtp + + # ----------------------------------------------------------------------------------------------- end diff --git a/config/environments/production.rb b/config/environments/production.rb index e40af63..b22dcaa 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -60,7 +60,7 @@ # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "CarriesCloset_production" + # config.active_job.queue_name_prefix = "carries_closet_production" config.action_mailer.perform_caching = false @@ -97,6 +97,25 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # ----------------------------------Action Mailer------------------------------------------------ + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "gmail.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["APP_PASSWORD"] + } + # can change host when we have a URL + config.action_mailer.default_url_options = {:host => "127.0.0.1:3000"} + config.action_mailer.delivery_method = :smtp + + # ----------------------------------------------------------------------------------------------- + # Inserts middleware to perform automatic connection switching. # The `database_selector` hash is used to pass options to the DatabaseSelector # middleware. The `delay` is used to determine how long to wait after a write diff --git a/config/environments/test.rb b/config/environments/test.rb index 93ed4f1..5a8cbee 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -41,7 +41,7 @@ # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test + # config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -57,4 +57,23 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + + # ----------------------------------Action Mailer------------------------------------------------ + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "gmail.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["APP_PASSWORD"] + } + # can change host when we have a URL + config.action_mailer.default_url_options = {:host => "127.0.0.1:3000"} + config.action_mailer.delivery_method = :smtp + + # ----------------------------------------------------------------------------------------------- end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000..190f3ce --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,311 @@ +# frozen_string_literal: true + +# Assuming you have not yet modified this file, each configuration option below +# is set to its default value. Note that some are commented out while others +# are not: uncommented lines are intended to protect your configuration from +# breaking changes in upgrades (i.e., in the event that future versions of +# Devise change the default values for those options). +# +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '86c4fb66f1b3419fd2e5b2c2489da12558d76ffcfe9eec685c5adb9bcb4bfc0aed0aef3437bd2d951d86e512a8b16902b6b9d857037ccf2f7d4c88e529faa4a7' + + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'no-reply@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. + # For API-only applications to support authentication "out-of-the-box", you will likely want to + # enable this with :database unless you are using a custom strategy. + # The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 12. If + # using other algorithms, it sets how many times you want the password to be hashed. + # The number of stretches used for generating the hashed password are stored + # with the hashed password. This allows you to change the stretches without + # invalidating existing passwords. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 12 + + # Set up a pepper to generate the hashed password. + # config.pepper = '829daa25bd822917fd1393f64ee93248b1b3af315c94cf95936d051f7e20a49e824282c5809787c7cb4127a8b94675e0996999d8fab5ea3659dd454abe8cd8cb' + + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. + # You can also set it to nil, which will allow the user to access the website + # without confirming their account. + # Default is 0.days, meaning the user cannot access the website without + # confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + config.extend_remember_period = true + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 12..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]{2,}@[^@\s]{2,}\.[^@\s]{2,}\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + config.maximum_attempts = 5 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + config.unlock_in = 8.hours + + # Warn on the last attempt before the account is locked. + config.last_attempt_warning = false + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = %i[get post] + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' + + # ==> Turbolinks configuration + # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: + # + # ActiveSupport.on_load(:devise_failure_app) do + # include Turbolinks::Controller + # end + + # ==> Configuration for :registerable + + # When set to false, does not sign a user in automatically after their password is + # changed. Defaults to true, so a user is signed in automatically after changing a password. + # config.sign_in_after_change_password = true +end diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb new file mode 100644 index 0000000..9526b83 --- /dev/null +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -0,0 +1,67 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Support for inversing belongs_to -> has_many Active Record associations. +# Rails.application.config.active_record.has_many_inversing = true + +# Track Active Storage variants in the database. +# Rails.application.config.active_storage.track_variants = true + +# Apply random variation to the delay when retrying failed jobs. +# Rails.application.config.active_job.retry_jitter = 0.15 + +# Stop executing `after_enqueue`/`after_perform` callbacks if +# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. +# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true + +# Specify cookies SameSite protection level: either :none, :lax, or :strict. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax + +# Generate CSRF tokens that are encoded in URL-safe Base64. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_controller.urlsafe_csrf_tokens = true + +# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an +# UTC offset or a UTC time. +# ActiveSupport.utc_to_local_returns_utc_offset_times = true + +# Change the default HTTP status code to `308` when redirecting non-GET/HEAD +# requests to HTTPS in `ActionDispatch::SSL` middleware. +# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 + +# Use new connection handling API. For most applications this won't have any +# effect. For applications using multiple databases, this new API provides +# support for granular connection swapping. +# Rails.application.config.active_record.legacy_connection_handling = false + +# Make `form_with` generate non-remote forms by default. +# Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Set the default queue name for the analysis job to the queue adapter default. +# Rails.application.config.active_storage.queues.analysis = nil + +# Set the default queue name for the purge job to the queue adapter default. +# Rails.application.config.active_storage.queues.purge = nil + +# Set the default queue name for the incineration job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.incineration = nil + +# Set the default queue name for the routing job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.routing = nil + +# Set the default queue name for the mail deliver job to the queue adapter default. +# Rails.application.config.action_mailer.deliver_later_queue_name = nil + +# Generate a `Link` header that gives a hint to modern browsers about +# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. +# Rails.application.config.action_view.preload_links_header = true diff --git a/config/initializers/phonelib.rb b/config/initializers/phonelib.rb new file mode 100644 index 0000000..faa74eb --- /dev/null +++ b/config/initializers/phonelib.rb @@ -0,0 +1 @@ +Phonelib.default_country = "US" \ No newline at end of file diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000..ab1f070 --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,65 @@ +# Additional translations at https://github.com/heartcombo/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + 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." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + 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." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + 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." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + 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." + 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." + updated: "Your account has been updated successfully." + updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again" + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/routes.rb b/config/routes.rb index c06383a..efb587d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,8 @@ Rails.application.routes.draw do + get '/requests/my_requests' => 'requests#my_requests' + resources :requests + get 'public/index' + devise_for :users # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + root to: "public#index" end diff --git a/db/migrate/20210125202450_create_active_storage_tables.active_storage.rb b/db/migrate/20210125202450_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..8779826 --- /dev/null +++ b/db/migrate/20210125202450_create_active_storage_tables.active_storage.rb @@ -0,0 +1,36 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[5.2] + def change + create_table :active_storage_blobs do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum, null: false + t.datetime :created_at, null: false + + t.index [ :key ], unique: true + end + + create_table :active_storage_attachments do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false + t.references :blob, null: false + + t.datetime :created_at, null: false + + t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records do |t| + t.belongs_to :blob, null: false, index: false + t.string :variation_digest, null: false + + t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end +end diff --git a/db/migrate/20210125202550_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20210125202550_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 0000000..9967a13 --- /dev/null +++ b/db/migrate/20210125202550_add_service_name_to_active_storage_blobs.active_storage.rb @@ -0,0 +1,18 @@ +# This migration comes from active_storage (originally 20190112182829) +class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] + def up + unless column_exists?(:active_storage_blobs, :service_name) + add_column :active_storage_blobs, :service_name, :string + + if configured_service = ActiveStorage::Blob.service.name + ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) + end + + change_column :active_storage_blobs, :service_name, :string, null: false + end + end + + def down + remove_column :active_storage_blobs, :service_name + end +end diff --git a/db/migrate/20210125202600_devise_create_users.rb b/db/migrate/20210125202600_devise_create_users.rb new file mode 100644 index 0000000..cc0991d --- /dev/null +++ b/db/migrate/20210125202600_devise_create_users.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[6.1] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.string :current_sign_in_ip + # t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20210129013218_create_requests.rb b/db/migrate/20210129013218_create_requests.rb new file mode 100644 index 0000000..f35d189 --- /dev/null +++ b/db/migrate/20210129013218_create_requests.rb @@ -0,0 +1,19 @@ +class CreateRequests < ActiveRecord::Migration[6.1] + def change + create_table :requests do |t| + t.integer :urgency + t.string :full_name + t.string :email + t.string :phone + t.integer :relationship + t.integer :county + t.boolean :meet + t.string :address + t.string :availability + t.string :items + t.text :comments + + t.timestamps + end + end +end diff --git a/db/migrate/20210209003059_add_fields_to_user.rb b/db/migrate/20210209003059_add_fields_to_user.rb new file mode 100644 index 0000000..85fd5f7 --- /dev/null +++ b/db/migrate/20210209003059_add_fields_to_user.rb @@ -0,0 +1,8 @@ +class AddFieldsToUser < ActiveRecord::Migration[6.1] + def change + add_column :users, :admin, :bool, default: false + add_column :users, :volunteer, :bool, default: false + add_column :users, :donee, :bool, default: false + add_column :users, :donor, :bool, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..761c434 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,77 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2021_02_09_003059) do + + create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum", null: false + t.datetime "created_at", null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + + create_table "requests", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.integer "urgency" + t.string "full_name" + t.string "email" + t.string "phone" + t.integer "relationship" + t.integer "county" + t.boolean "meet" + t.string "address" + t.string "availability" + t.string "items" + t.text "comments" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + + create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.boolean "admin", default: false + t.boolean "volunteer", default: false + t.boolean "donee", default: false + t.boolean "donor", default: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" +end diff --git a/db/seeds.rb b/db/seeds.rb index f3a0480..a1c8c81 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,30 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) + +require 'faker' + +# Create Default user +@mamie = User.find_by_email('test@example.com') +@mamie = User.create!(email: 'test@example.com', + password: 'secure-password') if @mamie.nil? + +@admin = User.find_by_email('admin@example.com') +@admin = User.create!(email: 'admin@example.com', password: 'admin-password', + admin: true) if @admin.nil? + +loop do + break if Request.count >= 10 + + @request = Request.create! urgency: (1...Request::URGENCIES.count).to_a.sample, + full_name: Faker::Name.name, + email: Faker::Internet.email, + phone: (678_555_0000...678_567_9999).to_a.sample.to_s, + relationship: (1...Request::RELATIONSHIPS.count).to_a.sample, + county: (1...Request::COUNTIES.count).to_a.sample, + meet: 1, + availability: Faker::Lorem.sentence, + comments: Faker::Lorem.sentence, + items: Faker::Lorem.sentence + puts "Request #{Request.count}: '#{@request.full_name}' requests '#{@request.items}'" +end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1051ee7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: "3.7" +services: + cc_server: + build: . + container_name: cc_server + # restart: unless-stopped + env_file: .env + volumes: + - .:/cc_server + ports: + - 3000:3000 + expose: + - 3000 + networks: + - container_network + depends_on: + - cc_mysql + - cc_redis + cc_mysql: + container_name: cc_mysql + image: mysql:8.0 + command: --default-authentication-plugin=mysql_native_password +# restart: always + env_file: .env + ports: + - "127.0.0.1:3306:3306" + expose: + - 3306 + volumes: + - ./db/scripts/:/docker-entrypoint-initdb.d/ + - ./db/data/MySQL/:/var/lib/mysql/ + networks: + - container_network + cap_add: + - SYS_NICE + cc_redis: + container_name: cc_redis + image: redis:latest + command: redis-server --requirepass $REDIS_PASSWORD --bind cc_redis --port 6379 + env_file: .env + ports: + - "127.0.0.1:6379:6379" + expose: + - 6379 + volumes: + - ./db/data/Redis:/data + networks: + - container_network +networks: + container_network: + driver: bridge \ No newline at end of file diff --git a/example.env b/example.env new file mode 100644 index 0000000..531fb41 --- /dev/null +++ b/example.env @@ -0,0 +1,14 @@ + +GMAIL_PASSWORD="CCjlmnn54321" +GMAIL_USERNAME="carries.closet.confirmations@gmail.com" +APP_PASSWORD = "wdyningvalfezuqt" + +RAILS_ENV=development + +DATABASE_NAME=CarriesCloset_development +DATABASE_USER=CarriesCloset_development +MYSQL_ALLOW_EMPTY_PASSWORD=true +DATABASE_HOST=cc_mysql + +REDIS_PASSWORD=password + diff --git a/package.json b/package.json index f5d911f..3741baa 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "version": "0.1.0", "devDependencies": { + "webpack": "^4.43.0", "webpack-dev-server": "^3.11.2" } } diff --git a/test/controllers/public_controller_test.rb b/test/controllers/public_controller_test.rb new file mode 100644 index 0000000..ef11a53 --- /dev/null +++ b/test/controllers/public_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class PublicControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get public_index_url + assert_response :success + end +end diff --git a/test/controllers/requests_controller_test.rb b/test/controllers/requests_controller_test.rb new file mode 100644 index 0000000..aa194e6 --- /dev/null +++ b/test/controllers/requests_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class RequestsControllerTest < ActionDispatch::IntegrationTest + setup do + @request = requests(:one) + end + + test "should get index" do + get requests_url + assert_response :success + end + + test "should get new" do + get new_request_url + assert_response :success + end + + test "should create request" do + assert_difference('Request.count') do + post requests_url, params: { request: { availability: @request.availability, comments: @request.comments, county: @request.county, email: @request.email, full_name: @request.full_name, meet: @request.meet, phone: @request.phone, type: @request.type, urgency: @request.urgency } } + end + + assert_redirected_to request_url(Request.last) + end + + test "should show request" do + get request_url(@request) + assert_response :success + end + + test "should get edit" do + get edit_request_url(@request) + assert_response :success + end + + test "should update request" do + patch request_url(@request), params: { request: { availability: @request.availability, comments: @request.comments, county: @request.county, email: @request.email, full_name: @request.full_name, meet: @request.meet, phone: @request.phone, type: @request.type, urgency: @request.urgency } } + assert_redirected_to request_url(@request) + end + + test "should destroy request" do + assert_difference('Request.count', -1) do + delete request_url(@request) + end + + assert_redirected_to requests_url + end +end diff --git a/test/fixtures/requests.yml b/test/fixtures/requests.yml new file mode 100644 index 0000000..b8bf034 --- /dev/null +++ b/test/fixtures/requests.yml @@ -0,0 +1,25 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + urgency: 1 + full_name: MyString + email: MyString + phone: 1 + type: 1 + county: 1 + meet: false + availability: MyString + comments: MyText + items: 1 shirt, men's medium + +two: + urgency: 1 + full_name: MyString + email: MyString + phone: 1 + type: 1 + county: 1 + meet: false + availability: MyString + comments: MyText + items: 1 pair of shoes, kid's 9 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..5181636 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/mailers/previews/user_mailer_preview.rb b/test/mailers/previews/user_mailer_preview.rb new file mode 100644 index 0000000..55c8771 --- /dev/null +++ b/test/mailers/previews/user_mailer_preview.rb @@ -0,0 +1,18 @@ +# Preview all emails at http://localhost:3000/rails/mailers/user_mailer +class UserMailerPreview < ActionMailer::Preview + def new_email + # Set up a temporary order for the preview + #order = Order.new(name: "Joe Smith", email: "joe@gmail.com", address: "1-2-3 Chuo, Tokyo, 333-0000", phone: "090-7777-8888", message: "I want to place an order!") + fake_request = Request.new(urgency: "1", + full_name: "Jane Doe", + email: "sample@gmail.com", + phone: "1234567890", + relationship: 1, + county: "1", + meet: true, + address: "", + availability: "3 pm", + comments: "Hi, this is a note.") + UserMailer.with(request: fake_request).new_email + end +end diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb new file mode 100644 index 0000000..5f65b81 --- /dev/null +++ b/test/mailers/user_mailer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class UserMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/request_test.rb b/test/models/request_test.rb new file mode 100644 index 0000000..df472d4 --- /dev/null +++ b/test/models/request_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RequestTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..5c07f49 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/requests_test.rb b/test/system/requests_test.rb new file mode 100644 index 0000000..0e52087 --- /dev/null +++ b/test/system/requests_test.rb @@ -0,0 +1,59 @@ +require "application_system_test_case" + +class RequestsTest < ApplicationSystemTestCase + setup do + @request = requests(:one) + end + + test "visiting the index" do + visit requests_url + assert_selector "h1", text: "Requests" + end + + test "creating a Request" do + visit requests_url + click_on "New Request" + + fill_in "Availability", with: @request.availability + fill_in "Comments", with: @request.comments + fill_in "County", with: @request.county + fill_in "Email", with: @request.email + fill_in "Full name", with: @request.full_name + check "Meet" if @request.meet + fill_in "Phone", with: @request.phone + fill_in "Type", with: @request.type + fill_in "Urgency", with: @request.urgency + click_on "Create Request" + + assert_text "Request was successfully created" + click_on "Back" + end + + test "updating a Request" do + visit requests_url + click_on "Edit", match: :first + + fill_in "Availability", with: @request.availability + fill_in "Comments", with: @request.comments + fill_in "County", with: @request.county + fill_in "Email", with: @request.email + fill_in "Full name", with: @request.full_name + check "Meet" if @request.meet + fill_in "Phone", with: @request.phone + fill_in "Type", with: @request.type + fill_in "Urgency", with: @request.urgency + click_on "Update Request" + + assert_text "Request was successfully updated" + click_on "Back" + end + + test "destroying a Request" do + visit requests_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Request was successfully destroyed" + end +end diff --git a/yarn.lock b/yarn.lock index b49d020..f026145 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7457,7 +7457,7 @@ webpack-sources@^1.0.0, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack- source-list-map "^2.0.0" source-map "~0.6.1" -webpack@^4.44.1: +webpack@^4.43.0, webpack@^4.44.1: version "4.46.0" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542" integrity sha512-6jJuJjg8znb/xRItk7bkT0+Q7AHCYjjFnvKIWQPkNIOyRqoCGvkOs0ipeQzrqz4l5FtN5ZI/ukEHroeX/o1/5Q==