diff --git a/.gitattributes b/.gitattributes index 516857104..ea2a81515 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,3 +8,6 @@ yarn.lock linguist-generated # Mark any vendored files as having been vendored. vendor/* linguist-vendored + +Gemfile merge=ours +Gemfile.lock merge=ours \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8ac3419f0..755774a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,14 @@ .tool-versions # Ignore ENV variable file -.env \ No newline at end of file +.env + +# Ignore Gemfiles +Gemfile +Gemfile.lock + +# ignore emacs backup files +*~ +\#*\# +.idea + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..82cf78194 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.exclude": { + "**/.git": false + } +} \ No newline at end of file diff --git a/Gemfile b/Gemfile index 5efe339e6..3bc8c20a0 100644 --- a/Gemfile +++ b/Gemfile @@ -34,10 +34,10 @@ gem "jbuilder" gem "redis", "~> 4.0" # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] -# gem "kredis" +gem "kredis" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" +gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] @@ -45,8 +45,11 @@ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false +# Boostrap +gem 'bootstrap', '~> 4.1.1' + # Use Sass to process CSS -# gem "sassc-rails" +gem "sass-rails", '~> 5.0' # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" @@ -83,3 +86,7 @@ gem 'dotenv-rails' # gem 'paperclip # gem 'uniquify' # gem 'will_paginate' + +gem "nio4r", "~> 2.5" + +gem 'geocoder', '~> 1.3', '>= 1.3.7' diff --git a/Gemfile.lock b/Gemfile.lock index c3e104938..6513414b0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,241 +1,293 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.3.1) - actionpack (= 7.0.3.1) - activesupport (= 7.0.3.1) + actioncable (7.0.8.6) + actionpack (= 7.0.8.6) + activesupport (= 7.0.8.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.3.1) - actionpack (= 7.0.3.1) - activejob (= 7.0.3.1) - activerecord (= 7.0.3.1) - activestorage (= 7.0.3.1) - activesupport (= 7.0.3.1) + actionmailbox (7.0.8.6) + actionpack (= 7.0.8.6) + activejob (= 7.0.8.6) + activerecord (= 7.0.8.6) + activestorage (= 7.0.8.6) + activesupport (= 7.0.8.6) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.3.1) - actionpack (= 7.0.3.1) - actionview (= 7.0.3.1) - activejob (= 7.0.3.1) - activesupport (= 7.0.3.1) + actionmailer (7.0.8.6) + actionpack (= 7.0.8.6) + actionview (= 7.0.8.6) + activejob (= 7.0.8.6) + activesupport (= 7.0.8.6) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.3.1) - actionview (= 7.0.3.1) - activesupport (= 7.0.3.1) - rack (~> 2.0, >= 2.2.0) + actionpack (7.0.8.6) + actionview (= 7.0.8.6) + activesupport (= 7.0.8.6) + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.3.1) - actionpack (= 7.0.3.1) - activerecord (= 7.0.3.1) - activestorage (= 7.0.3.1) - activesupport (= 7.0.3.1) + actiontext (7.0.8.6) + actionpack (= 7.0.8.6) + activerecord (= 7.0.8.6) + activestorage (= 7.0.8.6) + activesupport (= 7.0.8.6) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.3.1) - activesupport (= 7.0.3.1) + actionview (7.0.8.6) + activesupport (= 7.0.8.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.3.1) - activesupport (= 7.0.3.1) + activejob (7.0.8.6) + activesupport (= 7.0.8.6) globalid (>= 0.3.6) - activemodel (7.0.3.1) - activesupport (= 7.0.3.1) - activerecord (7.0.3.1) - activemodel (= 7.0.3.1) - activesupport (= 7.0.3.1) - activestorage (7.0.3.1) - actionpack (= 7.0.3.1) - activejob (= 7.0.3.1) - activerecord (= 7.0.3.1) - activesupport (= 7.0.3.1) + activemodel (7.0.8.6) + activesupport (= 7.0.8.6) + activerecord (7.0.8.6) + activemodel (= 7.0.8.6) + activesupport (= 7.0.8.6) + activestorage (7.0.8.6) + actionpack (= 7.0.8.6) + activejob (= 7.0.8.6) + activerecord (= 7.0.8.6) + activesupport (= 7.0.8.6) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.3.1) + activesupport (7.0.8.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.1) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + autoprefixer-rails (10.4.19.0) + execjs (~> 2) + base64 (0.2.0) + bcrypt (3.1.20) bindex (0.8.1) - bootsnap (1.13.0) + bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) - capybara (3.37.1) + bootstrap (4.1.3) + autoprefixer-rails (>= 6.0.3) + popper_js (>= 1.12.9, < 2) + sass (>= 3.5.2) + builder (3.3.0) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (4.1.0) - concurrent-ruby (1.1.10) + concurrent-ruby (1.3.4) crass (1.0.6) - debug (1.6.2) - irb (>= 1.3.6) - reline (>= 0.3.1) - digest (3.1.0) - dotenv (2.8.1) - dotenv-rails (2.8.1) - dotenv (= 2.8.1) - railties (>= 3.2) - erubi (1.11.0) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.12.0) + csv (3.3.0) + date (3.4.0) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + dotenv (3.1.4) + dotenv-rails (3.1.4) + dotenv (= 3.1.4) + railties (>= 6.1) + erubi (1.13.0) + execjs (2.10.0) + ffi (1.17.0) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + geocoder (1.8.3) + base64 (>= 0.1.0) + csv (>= 3.0.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.6) concurrent-ruby (~> 1.0) - importmap-rails (1.1.5) + importmap-rails (2.0.3) actionpack (>= 6.0.0) + activesupport (>= 6.0.0) railties (>= 6.0.0) - io-console (0.5.11) - irb (1.4.1) - reline (>= 0.3.0) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.13.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - loofah (2.18.0) + kredis (1.7.0) + activemodel (>= 6.0.0) + activesupport (>= 6.0.0) + redis (>= 4.2, < 6) + loofah (2.23.1) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (1.0.2) + net-imap + net-pop + net-smtp + marcel (1.0.4) matrix (0.4.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.16.3) - msgpack (1.5.6) - mysql2 (0.5.4) - net-imap (0.2.3) - digest + method_source (1.1.0) + mini_mime (1.1.5) + minitest (5.25.1) + msgpack (1.7.3) + mysql2 (0.5.6) + net-imap (0.5.0) + date net-protocol - strscan - net-pop (0.1.1) - digest + net-pop (0.1.2) net-protocol + net-protocol (0.2.2) timeout - net-protocol (0.1.3) - timeout - net-smtp (0.3.1) - digest + net-smtp (0.5.0) net-protocol - timeout - nio4r (2.5.8) - nokogiri (1.13.8-arm64-darwin) + nio4r (2.7.4) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.13.8-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - public_suffix (5.0.0) - puma (5.6.5) + popper_js (1.16.1) + psych (5.1.2) + stringio + public_suffix (6.0.1) + puma (5.6.9) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.4) - rack-test (2.0.2) + racc (1.8.1) + rack (2.2.10) + rack-test (2.1.0) rack (>= 1.3) - rails (7.0.3.1) - actioncable (= 7.0.3.1) - actionmailbox (= 7.0.3.1) - actionmailer (= 7.0.3.1) - actionpack (= 7.0.3.1) - actiontext (= 7.0.3.1) - actionview (= 7.0.3.1) - activejob (= 7.0.3.1) - activemodel (= 7.0.3.1) - activerecord (= 7.0.3.1) - activestorage (= 7.0.3.1) - activesupport (= 7.0.3.1) + rails (7.0.8.6) + actioncable (= 7.0.8.6) + actionmailbox (= 7.0.8.6) + actionmailer (= 7.0.8.6) + actionpack (= 7.0.8.6) + actiontext (= 7.0.8.6) + actionview (= 7.0.8.6) + activejob (= 7.0.8.6) + activemodel (= 7.0.8.6) + activerecord (= 7.0.8.6) + activestorage (= 7.0.8.6) + activesupport (= 7.0.8.6) bundler (>= 1.15.0) - railties (= 7.0.3.1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.0.8.6) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) - railties (7.0.3.1) - actionpack (= 7.0.3.1) - activesupport (= 7.0.3.1) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.0.8.6) + actionpack (= 7.0.8.6) + activesupport (= 7.0.8.6) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) - rake (13.0.6) - redis (4.8.0) - regexp_parser (2.5.0) - reline (0.3.1) + rake (13.2.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) + rdoc (6.7.0) + psych (>= 4.0.0) + redis (4.8.1) + regexp_parser (2.9.2) + reline (0.5.10) io-console (~> 0.5) - rexml (3.2.5) + rexml (3.3.9) rubyzip (2.3.2) - selenium-webdriver (4.4.0) - childprocess (>= 0.5, < 5.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 (5.1.0) + railties (>= 5.2.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (4.10.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - sprockets (4.1.1) + sprockets (3.7.5) + base64 concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - stimulus-rails (1.1.0) - railties (>= 6.0.0) - strscan (3.0.4) - tailwindcss-rails (2.0.12-arm64-darwin) - railties (>= 6.0.0) - tailwindcss-rails (2.0.12-x86_64-linux) + stimulus-rails (1.3.4) railties (>= 6.0.0) - thor (1.2.1) - timeout (0.3.0) - turbo-rails (1.1.1) + stringio (3.1.1) + tailwindcss-rails (3.0.0) + railties (>= 7.0.0) + tailwindcss-ruby + tailwindcss-ruby (3.4.14-arm64-darwin) + tailwindcss-ruby (3.4.14-x86_64-darwin) + tailwindcss-ruby (3.4.14-x86_64-linux) + thor (1.3.2) + tilt (2.4.0) + timeout (0.4.1) + turbo-rails (2.0.11) actionpack (>= 6.0.0) - activejob (>= 6.0.0) railties (>= 6.0.0) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webdrivers (5.0.0) + webdrivers (5.3.1) nokogiri (~> 1.6) rubyzip (>= 1.3.0) - selenium-webdriver (~> 4.0) - websocket (1.2.9) - websocket-driver (0.7.5) + selenium-webdriver (~> 4.0, < 4.11) + websocket (1.2.11) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.0) + zeitwerk (2.6.18) PLATFORMS - arm64-darwin-20 + arm64-darwin + arm64-darwin-23 + x86_64-darwin x86_64-linux DEPENDENCIES + bcrypt (~> 3.1.7) bootsnap + bootstrap (~> 4.1.1) capybara debug dotenv-rails + geocoder (~> 1.3, >= 1.3.7) importmap-rails jbuilder + kredis mysql2 (~> 0.5) + nio4r (~> 2.5) puma (~> 5.0) rails (~> 7.0.3, >= 7.0.3.1) redis (~> 4.0) + sass-rails (~> 5.0) selenium-webdriver sprockets-rails stimulus-rails @@ -249,4 +301,4 @@ RUBY VERSION ruby 3.1.2p20 BUNDLED WITH - 2.3.18 + 2.5.18 diff --git a/README.md b/README.md index 85f6c86ae..8ac3209fb 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Smith College CSC223: Software Engineering\ Starter App for ValetBike project +#katie was here :3 + ## Environment Configuration As you configure your environment you should **keep a log** where you **write down all the steps you take** including **each command you type**. You will inevitably run into errors setting up your development environment and maintaining a meticulous log will allow others to help you troubleshoot. Ignore this recommendation at your own peril, but don't say you haven't been warned :] diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index b06fc42ac..a2d906a5b 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,5 +1,6 @@ //= link_tree ../images -//= link_directory ../stylesheets .css +//= link application.css +//= link_directory ../stylesheets .scss //= link_tree ../../javascript .js //= link_tree ../../../vendor/javascript .js //= link_tree ../builds diff --git a/app/assets/images/MHBike.png b/app/assets/images/MHBike.png new file mode 100644 index 000000000..27e6e0eca Binary files /dev/null and b/app/assets/images/MHBike.png differ diff --git a/app/assets/images/MHmoney.jpg b/app/assets/images/MHmoney.jpg new file mode 100644 index 000000000..1fc457e69 Binary files /dev/null and b/app/assets/images/MHmoney.jpg differ diff --git a/app/assets/images/MHvehicle.webp b/app/assets/images/MHvehicle.webp new file mode 100644 index 000000000..bf632d45a Binary files /dev/null and b/app/assets/images/MHvehicle.webp differ diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico new file mode 100644 index 000000000..ffb2aed28 Binary files /dev/null and b/app/assets/images/favicon.ico differ diff --git a/app/assets/images/ghoulia.jpg b/app/assets/images/ghoulia.jpg new file mode 100644 index 000000000..f165cad2c Binary files /dev/null and b/app/assets/images/ghoulia.jpg differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 000000000..db6865363 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 288b9ab71..7c35026b8 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -12,4 +12,5 @@ * *= require_tree . *= require_self - */ + + */ \ No newline at end of file diff --git a/app/assets/stylesheets/form.css b/app/assets/stylesheets/form.css new file mode 100644 index 000000000..0728af263 --- /dev/null +++ b/app/assets/stylesheets/form.css @@ -0,0 +1,55 @@ +.form-container { + background-color: var(--white-color); + margin-top: 5rem; + padding: 2rem; + border-radius: var(--widget-radius); +} + +.form-wrapper { + margin-top: 2rem; +} + +.form-wrapper input[type=submit], .form-wrapper button { + display: block; + margin: auto; + width: 100%; +} + +.form-title { + font-family: var(--title-font); + font-weight: 500; + font-size: 1.5em; + text-align: center; +} + +.form-field label { + font-size: 0.8em; +} + +.form-field .form-control { + border-radius: var(--btn-radius); + border: var(--btn-thickness) solid var(--gray-color); +} + +.error-message { + font-size: 0.8em; + margin-bottom: 0; +} + +.error-message li { + list-style-type: circle; +} + +.form-logo img { + width: 180px; + margin: 0 auto; +} + +.form-links { + margin-top: 1em; + text-align: center; +} + +.form-links p a { + color: var(--theme-color); +} \ No newline at end of file diff --git a/app/assets/stylesheets/global.css b/app/assets/stylesheets/global.css index ff48f1abe..7e0f04c30 100644 --- a/app/assets/stylesheets/global.css +++ b/app/assets/stylesheets/global.css @@ -22,6 +22,22 @@ body { -ms-text-size-adjust:100%; } +caption{ + font-size:15pt; + -webkit-text-size-adjust:100%; + -moz-text-size-adjust:100%; + -ms-text-size-adjust:100%; + text-align: center; +} + +sub-caption{ + font-size:12pt; + -webkit-text-size-adjust:100%; + -moz-text-size-adjust:100%; + -ms-text-size-adjust:100%; + text-align: center; +} + #site-container{ position: relative; width: 100%; @@ -33,3 +49,57 @@ body { color: var(--black-color); background: var(--white-color); } + +.bg-fill { + background-color: var(--theme-color); + position: absolute; + width: 100%; + height: auto; + min-height: 100%; + padding-bottom: 3rem; +} + +.custom-btn { + padding: 0.5rem 1.5rem; + border-radius: var(--btn-radius); + transition: 0.1s ease; +} + +.btn-fill { + background: var(--theme-color); + color: var(--white-color); + border: var(--btn-thickness) solid var(--theme-color); +} + +.btn-fill:hover { + background: var(--white-color); + color: var(--black-color); +} + +img{ + height: 40%; + width: 40%; + margin-top: .5em; + border-radius: 15%; + border: 3px solid whitesmoke; + image-orientation: center; +} +.btn-outline { + background: var(--white-color); + border: var(--btn-thickness) solid var(--theme-color); +} + +.btn-outline:hover { + background: var(--theme-color); + color: var(--white-color); +} + +.btn-danger { + background: var(--danger-color); + color: var(--white-color); +} + +.btn-invalid { + background: var(--invalid-color); + color: var(--white-color); +} diff --git a/app/assets/stylesheets/header.css b/app/assets/stylesheets/header.css new file mode 100644 index 000000000..84b184bb1 --- /dev/null +++ b/app/assets/stylesheets/header.css @@ -0,0 +1,6 @@ +.app-header { + margin-bottom: 3em; + padding: 1.5em 0; + background: rgba(53, 144, 202, 0.95); + position: relative; +} \ No newline at end of file diff --git a/app/assets/stylesheets/variables.css b/app/assets/stylesheets/variables.css index 915c14dd3..68d2c8b17 100644 --- a/app/assets/stylesheets/variables.css +++ b/app/assets/stylesheets/variables.css @@ -9,5 +9,11 @@ --dark-white-color: #F3F2F3; --medium-white-color: #FDFCFD; --white-color: #FFFFFF; + --invalid-color: #B1B1B1; + --theme-color: #905ADB; + --btn-radius: 0.3rem; + --widget-radius: 0.5rem; + --btn-thickness: 2px; + --danger-color: #8B0000; } \ No newline at end of file diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb new file mode 100644 index 000000000..6d98e1537 --- /dev/null +++ b/app/controllers/access_controller.rb @@ -0,0 +1,18 @@ +class AccessController < ApplicationController + def create + # Process log in information + @user = User.find_by(email: params[:email]) + if !!@user && @user&.authenticate(params[:password]) + session[:user_id] = @user[:id] + redirect_to root_path + else + flash[:notice] = "Something went wrong. Please check your email and password." + redirect_to log_in_path + end + end + + def destroy + session[:user_id] = nil + redirect_to root_path + end +end diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb new file mode 100644 index 000000000..dec7e5782 --- /dev/null +++ b/app/controllers/account_controller.rb @@ -0,0 +1,28 @@ +class AccountController < ApplicationController + before_action :get_user_info_from_session + def index + if !logged_in? || !@user + redirect_to log_in_path + end + end + + def destroy + if !!@user + session[:user_id] = nil + @user.destroy + redirect_to root_path + end + end + + private +=begin + def get_user_info_from_session + @user = User.find_by(id: session[:user_id]) + end + + def logged_in? + # Check user's log in status + session[:user_id].present? + end +=end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12a..84808f420 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,13 @@ class ApplicationController < ActionController::Base + + helper_method :get_user_info_from_session + helper_method :logged_in? + + def get_user_info_from_session + @user = User.find_by(id: session[:user_id]) + end + def logged_in? + # Check user's log in status + session[:user_id].present? + end end diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb new file mode 100644 index 000000000..036a4f038 --- /dev/null +++ b/app/controllers/bikes_controller.rb @@ -0,0 +1,12 @@ +class BikesController < ApplicationController + def _row + @bikes = Bike.all.order(identifier: :asc) + end + + def index + end + def show + @bike = Bike.find(params[:id]) + end + +end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb new file mode 100644 index 000000000..4e0b3c61c --- /dev/null +++ b/app/controllers/main_controller.rb @@ -0,0 +1,10 @@ +class MainController < ApplicationController + def index + end + + def pricing + end + + def contact + end +end diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb new file mode 100644 index 000000000..5e9c354a1 --- /dev/null +++ b/app/controllers/password_resets_controller.rb @@ -0,0 +1,50 @@ +class PasswordResetsController < ApplicationController + def create + # Process email and send reset link + @user = User.find_by(email: params[:email]) + + if !!@user + # Send email in the background + PasswordMailer.with(user: @user).reset.deliver_later + flash[:notice] = "An email will be sent with a link to reset your password." + else + flash[:notice] = "An error occured. Please try again." + end + + redirect_to password_reset_url + end + + def edit + # Find the user with the given token + if params[:token] + @user = User.find_signed(params[:token], purpose: "password_reset") + else + redirect_to log_in_path + end + rescue ActiveSupport::MessageVerifier::InvalidSignature + redirect_to password_reset_url, notice: "Your token has expired. Please try again" + end + + def update + # Actually updates the password + @user = User.find_signed(params[:token], purpose: "password_reset") + + if @user.update(password_params) + flash[:notice] = "Your password was reset successfully. Please sign in." + redirect_to log_in_path + else + render :edit, status: 422 # have to set status. otherwise, the errors won't render + end + + rescue ActiveSupport::MessageVerifier::InvalidSignature + redirect_to password_reset_url, notice: "Your token has expired. Please try again" + end + + private + + def password_params + params.require(:user).permit(:password, :password_confirmation) + end + + +end diff --git a/app/controllers/stations_controller.rb b/app/controllers/stations_controller.rb index 88090af16..b8136fa54 100644 --- a/app/controllers/stations_controller.rb +++ b/app/controllers/stations_controller.rb @@ -2,6 +2,21 @@ class StationsController < ApplicationController def index @stations = Station.all.order(identifier: :asc) + @lats = Array.new # array of latitudes + @longs = Array.new # array of longitudes + @stations.each do |s| + puts s.latitude + @lats.append(s.latitude) + @longs.append(s.longitude) + end + end + + def show + @user = get_user_info_from_session + @station = Station.find(params[:id]) + unless @user.current_trip_id.nil? + @trip = Trip.find(@user.current_trip_id) + end end end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 000000000..b14035061 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,49 @@ +class TripsController < ApplicationController + def new + @trip = Trip.new + @bike = Bike.find(params[:bike_id]) + @station = Station.find(params[:station_id]) + @user = User.find(params[:user_id]) + end + + def create + @trip = Trip.new(trip_params) + if @trip.save + @bike = Bike.find(@trip.bike_id) + @station = Station.find(@trip.start_station_is) + @user = User.find(@trip.user_id) + @user.update(current_trip_id: @trip.id) + @bike.update(is_available: false, current_station_id: nil) + redirect_to confirm_path(trip_id: @trip.id) + else + render :new + end + end + def show + @trip = Trip.find(params[:trip_id]) + end + + def confirmation + @trip = Trip.find(params[:trip_id]) + end + + def end_confirmation + @trip = Trip.find(params[:trip_id]) + @user = User.find(@trip.user_id) + @bike = Bike.find(@trip.bike_id) + @user.update(current_trip_id: nil) + @bike.update(is_available: true, current_station_id: params[:end_station_id]) + end + + def update + end + + def edit + end + + def trip_params + params.require(:trip).permit(:bike_id, :user_id, :start_station_is, :start_time) + end + + +end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb new file mode 100644 index 000000000..09dfb94bc --- /dev/null +++ b/app/controllers/user_controller.rb @@ -0,0 +1,25 @@ +class UserController < ApplicationController + def new + # Display the sign up form + @user = User.new + end + + def create + # Process sign up information + @user = User.new(user_params) + if @user.save + redirect_to log_in_path # make them log in + else + render :new, status: 422 + end + end + + private + + def user_params + # Return params that includes only the given fields + # and sets the permitted attribute for the object to true. + # (useful for limiting which attributes should be allowed for updating) + params.require(:user).permit(:email, :password, :password_confirmation) + end +end diff --git a/app/helpers/access_helper.rb b/app/helpers/access_helper.rb new file mode 100644 index 000000000..342c6ff9f --- /dev/null +++ b/app/helpers/access_helper.rb @@ -0,0 +1,2 @@ +module AccessHelper +end diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb new file mode 100644 index 000000000..6d3694a49 --- /dev/null +++ b/app/helpers/account_helper.rb @@ -0,0 +1,2 @@ +module AccountHelper +end diff --git a/app/helpers/bikes_helper.rb b/app/helpers/bikes_helper.rb new file mode 100644 index 000000000..a2645e4e1 --- /dev/null +++ b/app/helpers/bikes_helper.rb @@ -0,0 +1,2 @@ +module BikesHelper +end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb new file mode 100644 index 000000000..826effed9 --- /dev/null +++ b/app/helpers/main_helper.rb @@ -0,0 +1,2 @@ +module MainHelper +end diff --git a/app/helpers/password_resets_helper.rb b/app/helpers/password_resets_helper.rb new file mode 100644 index 000000000..0c9d96ecf --- /dev/null +++ b/app/helpers/password_resets_helper.rb @@ -0,0 +1,2 @@ +module PasswordResetsHelper +end diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb new file mode 100644 index 000000000..04f333d46 --- /dev/null +++ b/app/helpers/trips_helper.rb @@ -0,0 +1,2 @@ +module TripsHelper +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 000000000..0147c3fe6 --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/app/javascript/application.js b/app/javascript/application.js index 0d7b49404..346cc81ed 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,3 +1,6 @@ +//= require bootstrap-sprockets // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" + +import "bootstrap" \ No newline at end of file diff --git a/app/javascript/osm_map.js b/app/javascript/osm_map.js new file mode 100644 index 000000000..59f13322d --- /dev/null +++ b/app/javascript/osm_map.js @@ -0,0 +1,46 @@ +/* +Base for this code pulled from https://stackoverflow.com/questions/925164/openstreetmap-embedding-map-in-webpage-like-google-maps +Answer by user totymedli +*/ + +const northamptonLat = '42.328674'; // what it says on the tag +const northamptonLng = '-72.646'; // rough center of northampton +const center = L.latLng(northamptonLat, northamptonLng); + +/* +initializes the map for future use +TODO + - figure out the tiling thing and how to get an actual image rendered +*/ +function mapInit(element){ + + // Create Leaflet map on map element. + var map = L.map(element); + + // Add OSM tile layer to the Leaflet map. + L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(map); + + // Set map's center to target with zoom 14. + map.setView(center, 14); // consider changing zoom + + return map +} + +/* +adds a marker to the leaflet +TODO + - hoping that the map var is getting set correctly + - add a popup to the marker to link to the station page +*/ +function addMarker(map, lat, lng) { + // Target's GPS coordinates. + var target = L.latLng(lat, lng); + + // Place a marker on the location. + L.marker(target).addTo(map); + + // Set map's center to target with zoom 14. + map.setView(center, 14); // consider changing zoom +} \ No newline at end of file diff --git a/app/mailers/password_mailer.rb b/app/mailers/password_mailer.rb new file mode 100644 index 000000000..aafdc4eb2 --- /dev/null +++ b/app/mailers/password_mailer.rb @@ -0,0 +1,15 @@ +class PasswordMailer < ApplicationMailer + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.password_mailer.reset.subject + # + def reset + @user = params[:user] + + @token = @user.signed_id(expires_in: 15.minutes, purpose: 'password_reset') + + mail to: @user.email + end +end diff --git a/app/models/bike.rb b/app/models/bike.rb index f3648e343..eeb6d33a7 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -4,4 +4,13 @@ class Bike < ApplicationRecord belongs_to :current_station, class_name: :Station, foreign_key: :current_station_id, optional: true + + def available? + is_available + end + + def get_station + Station.find(current_station_id) + end + end diff --git a/app/models/station.rb b/app/models/station.rb index 64b9eaada..1a9430776 100644 --- a/app/models/station.rb +++ b/app/models/station.rb @@ -1,9 +1,14 @@ -class Station < ApplicationRecord +class Station < ApplicationRecord validates_presence_of :identifier, :name, :address validates_uniqueness_of :identifier has_many :docked_bikes, class_name: :Bike, foreign_key: :current_station_id - + + attribute :latitude, type: Float + attribute :longitude, type: Float + + geocoded_by :address + after_validation :geocode end diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 000000000..d265a2ccc --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,3 @@ +class Trip < ApplicationRecord + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..d4562c976 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,16 @@ +class User < ApplicationRecord + has_secure_password + + EMAIL_REGEX = /\A[\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4}\z/ + validates :email, presence: true, + uniqueness: {case_sensitive: false}, + format: {with: EMAIL_REGEX} + has_many :trips, dependent: :destroy + + def has_trip? + unless current_trip_id.nil? + current_trip_id + end + end + +end diff --git a/app/views/access/login.html.erb b/app/views/access/login.html.erb new file mode 100644 index 000000000..84ac41334 --- /dev/null +++ b/app/views/access/login.html.erb @@ -0,0 +1,37 @@ +
<%= link_to('Sign up', sign_up_path) %>
+<%= link_to('Forgot your password', password_reset_path) %>
+If it was you who requested a password reset, please click on the link below to reset your password. The link will expire in 15 minutes.
+ + <%= link_to "Reset Password", password_reset_edit_url(token: @token) %> +<%= link_to('Sign up', sign_up_path) %>
+<%= link_to('Log in', log_in_path) %>
+<%= link_to('Sign up', sign_up_path) %>
+<%= link_to('Log in', log_in_path) %>
+| Bike ID: | +<%= @bike.identifier %> | +
|---|---|
| User ID: | +<%= @user.id %> | +
| Station: | +<%= @station.identifier %> | +
| Pickup Time | +<%= f.time_field(:start_time) %> | +
| Bike ID: | +<%= @bike.identifier %> | +
|---|---|
| User ID: | +<%= @user.id %> | +
| Station: | +<%= @station.identifier %> | +
| Pickup Time | +<%= f.time_field(:start_time) %> | +
<%= link_to('Log in', log_in_path) %>
+