From 4e78d64e7a87d1b1e193eae5d215bbd02916b5b6 Mon Sep 17 00:00:00 2001 From: ThaweesukKMUTNB Date: Fri, 28 Oct 2022 23:54:55 +0700 Subject: [PATCH 1/7] part-0 --- rottenpotatoes/Gemfile | 12 ++++++++- rottenpotatoes/Gemfile.lock | 2 +- rottenpotatoes/db/schema.rb | 4 +-- .../features/step_definitions/.gitkeep | 0 rottenpotatoes/features/support/env.rb | 22 ++++++++-------- rottenpotatoes/features/support/paths.rb | 25 ++++++++++++------- rottenpotatoes/lib/tasks/cucumber.rake | 25 +++++++++++++------ 7 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 rottenpotatoes/features/step_definitions/.gitkeep diff --git a/rottenpotatoes/Gemfile b/rottenpotatoes/Gemfile index ff89d89fa..cb5f82f28 100644 --- a/rottenpotatoes/Gemfile +++ b/rottenpotatoes/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.6.3' +ruby '2.6.10' gem 'rails', '4.2.10' gem 'sass-rails', '~> 5.0.3' @@ -11,6 +11,16 @@ gem 'jquery-rails' gem 'haml' gem 'protected_attributes' + +group :test do + gem 'cucumber-rails', :require => false + gem 'cucumber-rails-training-wheels' # some pre-fabbed step definitions + gem 'database_cleaner' # to clear Cucumber's test database between runs + gem 'capybara' # lets Cucumber pretend to be a web browser + gem 'launchy' # a useful debugging aid for user stories +end + + group :development, :test do gem 'sqlite3' gem 'byebug' diff --git a/rottenpotatoes/Gemfile.lock b/rottenpotatoes/Gemfile.lock index cd08724c4..36e54caec 100644 --- a/rottenpotatoes/Gemfile.lock +++ b/rottenpotatoes/Gemfile.lock @@ -211,7 +211,7 @@ DEPENDENCIES uglifier (>= 2.7.1) RUBY VERSION - ruby 2.6.3p62 + ruby 2.6.10p210 BUNDLED WITH 1.17.2 diff --git a/rottenpotatoes/db/schema.rb b/rottenpotatoes/db/schema.rb index 40171ba73..7721abf3f 100644 --- a/rottenpotatoes/db/schema.rb +++ b/rottenpotatoes/db/schema.rb @@ -14,8 +14,8 @@ ActiveRecord::Schema.define(version: 20111119180638) do create_table "movies", force: :cascade do |t| - t.string "title", limit: 255 - t.string "rating", limit: 255 + t.string "title" + t.string "rating" t.text "description" t.datetime "release_date" t.datetime "created_at" diff --git a/rottenpotatoes/features/step_definitions/.gitkeep b/rottenpotatoes/features/step_definitions/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/rottenpotatoes/features/support/env.rb b/rottenpotatoes/features/support/env.rb index b2cf67330..64ddf6108 100644 --- a/rottenpotatoes/features/support/env.rb +++ b/rottenpotatoes/features/support/env.rb @@ -1,20 +1,19 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. require 'cucumber/rails' -# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In -# order to ease the transition to Capybara we set the default here. If you'd -# prefer to use XPath just remove this line and adjust any selectors in your -# steps to use the XPath syntax. -Capybara.default_selector = :css +# Capybara defaults to CSS3 selectors rather than XPath. +# If you'd prefer to use XPath, just uncomment this line and adjust any +# selectors in your step definitions to use the XPath syntax. +# Capybara.default_selector = :xpath # By default, any exception happening in your Rails application will bubble up -# to Cucumber so that your scenario will fail. This is a different from how -# your application behaves in the production environment, where an error page will +# to Cucumber so that your scenario will fail. This is a different from how +# your application behaves in the production environment, where an error page will # be rendered instead. # # Sometimes we want to override this default behaviour and allow Rails to rescue @@ -41,7 +40,10 @@ # See the DatabaseCleaner documentation for details. Example: # # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do -# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]} +# # { :except => [:widgets] } may not do what you expect here +# # as Cucumber::Rails::Database.javascript_strategy overrides +# # this setting. +# DatabaseCleaner.strategy = :truncation # end # # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do diff --git a/rottenpotatoes/features/support/paths.rb b/rottenpotatoes/features/support/paths.rb index c0f7ade34..290543c37 100644 --- a/rottenpotatoes/features/support/paths.rb +++ b/rottenpotatoes/features/support/paths.rb @@ -13,17 +13,24 @@ module NavigationHelpers def path_to(page_name) case page_name - when /^the movies page$/ then '/movies' - - # Here is an example that uses value from the Regexp: - # - # when /^the details page for movie "(.*)"$/ do |movie_name| - # movie_path(Movie.find_by(:name => movie_name)) - # end + when /^the home\s?page$/ + '/' + + # Add more mappings here. + # Here is an example that pulls values out of the Regexp: + # + # when /^(.*)'s profile page$/i + # user_profile_path(User.find_by_login($1)) else - raise "Can't find mapping from \"#{page_name}\" to a path.\n" + - "Now, go and add a mapping in #{__FILE__}" + begin + page_name =~ /^the (.*) page$/ + path_components = $1.split(/\s+/) + self.send(path_components.push('path').join('_').to_sym) + rescue NoMethodError, ArgumentError + raise "Can't find mapping from \"#{page_name}\" to a path.\n" + + "Now, go and add a mapping in #{__FILE__}" + end end end end diff --git a/rottenpotatoes/lib/tasks/cucumber.rake b/rottenpotatoes/lib/tasks/cucumber.rake index 83f79471e..23d9b3eb4 100644 --- a/rottenpotatoes/lib/tasks/cucumber.rake +++ b/rottenpotatoes/lib/tasks/cucumber.rake @@ -1,6 +1,6 @@ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. -# It is recommended to regenerate this file in the future when you upgrade to a -# newer version of cucumber-rails. Consider adding your own code to a new file +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. @@ -14,19 +14,19 @@ begin require 'cucumber/rake/task' namespace :cucumber do - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t| t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. t.fork = true # You may get faster startup if you set this to false t.profile = 'default' end - Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| + Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t| t.binary = vendored_cucumber_bin t.fork = true # You may get faster startup if you set this to false t.profile = 'wip' end - Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| + Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t| t.binary = vendored_cucumber_bin t.fork = true # You may get faster startup if you set this to false t.profile = 'rerun' @@ -40,6 +40,15 @@ begin ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') end + + task :annotations_setup do + Rails.application.configure do + if config.respond_to?(:annotations) + config.annotations.directories << 'features' + config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ } + end + end + end end desc 'Alias for cucumber:ok' task :cucumber => 'cucumber:ok' @@ -50,11 +59,13 @@ begin STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" end - # In case we don't have ActiveRecord, append a no-op task that we can depend upon. - task 'db:test:prepare' do + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. + task 'test:prepare' do end task :stats => 'cucumber:statsetup' + + task :notes => 'cucumber:annotations_setup' rescue LoadError desc 'cucumber rake task not available (cucumber not installed)' task :cucumber do From 100bd0c87b7caf8c4276488ff460eadd185ad4fc Mon Sep 17 00:00:00 2001 From: ThaweesukKMUTNB Date: Sat, 29 Oct 2022 00:49:33 +0700 Subject: [PATCH 2/7] part 1 finish --- rottenpotatoes/features/support/paths.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rottenpotatoes/features/support/paths.rb b/rottenpotatoes/features/support/paths.rb index 290543c37..aec7b6740 100644 --- a/rottenpotatoes/features/support/paths.rb +++ b/rottenpotatoes/features/support/paths.rb @@ -16,6 +16,13 @@ def path_to(page_name) when /^the home\s?page$/ '/' + when /^the RottenPotatoes home page/ + '/movies' + + when /^the Create New Movie page/ + '/movies/new' + + # Add more mappings here. # Here is an example that pulls values out of the Regexp: # From 6ab56f23a72127aaab622b1d516a58353ddbc89d Mon Sep 17 00:00:00 2001 From: ThaweesukKMUTNB Date: Sat, 29 Oct 2022 21:20:59 +0700 Subject: [PATCH 3/7] part 2 finish --- rottenpotatoes/features/step_definitions/movie_steps.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rottenpotatoes/features/step_definitions/movie_steps.rb b/rottenpotatoes/features/step_definitions/movie_steps.rb index 0444d798a..e70a6097f 100644 --- a/rottenpotatoes/features/step_definitions/movie_steps.rb +++ b/rottenpotatoes/features/step_definitions/movie_steps.rb @@ -4,8 +4,13 @@ movies_table.hashes.each do |movie| # each returned element will be a hash whose key is the table header. # you should arrange to add that movie to the database here. + @t = movie["title"] + @r = movie["rating"] + @rd = movie["release_date"] + + Movie.create("title":@t, "rating":@r) end - fail "Unimplemented" + #fail "Unimplemented" end Then /(.*) seed movies should exist/ do | n_seeds | From dc750dd3386c72ebe102b937d8a989f5140a5724 Mon Sep 17 00:00:00 2001 From: ThaweesukKMUTNB Date: Sat, 29 Oct 2022 21:49:41 +0700 Subject: [PATCH 4/7] part 3 finish --- .../features/filter_movie_list.feature | 10 +++++++++- .../features/step_definitions/movie_steps.rb | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/rottenpotatoes/features/filter_movie_list.feature b/rottenpotatoes/features/filter_movie_list.feature index 1a71bad0d..948eaf602 100644 --- a/rottenpotatoes/features/filter_movie_list.feature +++ b/rottenpotatoes/features/filter_movie_list.feature @@ -24,10 +24,18 @@ Background: movies have been added to database Scenario: restrict to movies with 'PG' or 'R' ratings # enter step(s) to check the 'PG' and 'R' checkboxes + Given I check the following ratings: PG R # enter step(s) to uncheck all other checkboxes + And I uncheck the following ratings: G PG-13 # enter step to "submit" the search form on the homepage + When I press "Refresh" # enter step(s) to ensure that PG and R movies are visible + Then I should see "Terminator" + Then I should see "Raiders of the Lost Ark" # enter step(s) to ensure that other movies are not visible - + Then I should not see "The Help" + Then I should not see "Aladdin" Scenario: all ratings selected + Then I should see all the movies + # see assignment diff --git a/rottenpotatoes/features/step_definitions/movie_steps.rb b/rottenpotatoes/features/step_definitions/movie_steps.rb index e70a6097f..5c8efbd98 100644 --- a/rottenpotatoes/features/step_definitions/movie_steps.rb +++ b/rottenpotatoes/features/step_definitions/movie_steps.rb @@ -34,10 +34,24 @@ # HINT: use String#split to split up the rating_list, then # iterate over the ratings and reuse the "When I check..." or # "When I uncheck..." steps in lines 89-95 of web_steps.rb - fail "Unimplemented" + if uncheck + for r in rating_list.split + uncheck("ratings["+r+"]") + end + else + for r in rating_list.split + check("ratings["+r+"]") + end + end + #fail "Unimplemented" end Then /I should see all the movies/ do # Make sure that all the movies in the app are visible in the table - fail "Unimplemented" + count = -1 + page.all('tr').each do |tr| + count +=1 + end + Movie.count.should be count + #fail "Unimplemented" end From a8c581787560a43758194bc8f2b5e594e9befa74 Mon Sep 17 00:00:00 2001 From: golfzakrub Date: Sat, 29 Oct 2022 22:05:02 +0700 Subject: [PATCH 5/7] Part 4 sorting --- rottenpotatoes/features/sort_movie_list.feature | 4 +++- .../features/step_definitions/movie_steps.rb | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rottenpotatoes/features/sort_movie_list.feature b/rottenpotatoes/features/sort_movie_list.feature index c245736ae..e21bd7749 100644 --- a/rottenpotatoes/features/sort_movie_list.feature +++ b/rottenpotatoes/features/sort_movie_list.feature @@ -25,7 +25,9 @@ Background: movies have been added to database Scenario: sort movies alphabetically When I follow "Movie Title" # your steps here - + Then I should see "Aladdin" before "Chocolat" + Scenario: sort movies in increasing order of release date When I follow "Release Date" # your steps here + Then I should see "Raiders of the Lost Ark" before "Chocolat" diff --git a/rottenpotatoes/features/step_definitions/movie_steps.rb b/rottenpotatoes/features/step_definitions/movie_steps.rb index 5c8efbd98..104d1d226 100644 --- a/rottenpotatoes/features/step_definitions/movie_steps.rb +++ b/rottenpotatoes/features/step_definitions/movie_steps.rb @@ -23,7 +23,19 @@ Then /I should see "(.*)" before "(.*)"/ do |e1, e2| # ensure that that e1 occurs before e2. # page.body is the entire content of the page as a string. - fail "Unimplemented" + found_e1 = false + found_e2 = false + e1_b_e2 = nil + page.all('#movies tbody tr td').each do |td| + if td.text == e1 + found_e1 = true + e1_b_e2 = found_e2 ? false : true + elsif td.text == e2 + found_e2 = true + end + end + + #fail "Unimplemented" end # Make it easier to express checking or unchecking several boxes at once From b5e33689f9611120142c10fd9d92f215815da0a0 Mon Sep 17 00:00:00 2001 From: TNKbenz Date: Sun, 30 Oct 2022 16:54:11 +0700 Subject: [PATCH 6/7] Part 5 Finish --- .../app/controllers/movies_controller.rb | 21 ++++++++++++++++ .../app/views/movies/index.html.haml | 9 +++++++ .../app/views/movies/search_tmdb.html.haml | 21 ++++++++++++++++ rottenpotatoes/config/routes.rb | 1 + rottenpotatoes/features/search_tmdb.feature | 24 +++++++++++++++++++ rottenpotatoes/features/support/paths.rb | 3 ++- 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 rottenpotatoes/app/views/movies/search_tmdb.html.haml create mode 100644 rottenpotatoes/features/search_tmdb.feature diff --git a/rottenpotatoes/app/controllers/movies_controller.rb b/rottenpotatoes/app/controllers/movies_controller.rb index 684f924fb..cdfab417b 100644 --- a/rottenpotatoes/app/controllers/movies_controller.rb +++ b/rottenpotatoes/app/controllers/movies_controller.rb @@ -57,4 +57,25 @@ def destroy redirect_to movies_path end + def search_tmdb + title = params[:search_terms] + api = "7b2804a3f134e4e62aaa3e11de3235d5" + uri = URI("https://api.themoviedb.org/3/search/movie?api_key=#{api}&langauge=en-US&query=#{title}&page=1&include_adult=false") + response = Net::HTTP.get_response(uri) + data = JSON.parse(response.body) + + if data["results"].length() ==0 + flash[:warning] = "'#{params[:search_terms]}' was not found in TMDb" + redirect_to movies_path + else + firstdata = data["results"][0] + @movies = { + "title" => firstdata["title"], + "release_date" => firstdata["release_date"] + + } + + return + end + end end diff --git a/rottenpotatoes/app/views/movies/index.html.haml b/rottenpotatoes/app/views/movies/index.html.haml index 9a345e441..f0dd4a15e 100644 --- a/rottenpotatoes/app/views/movies/index.html.haml +++ b/rottenpotatoes/app/views/movies/index.html.haml @@ -26,3 +26,12 @@ %td= link_to "More about #{movie.title}", movie_path(movie) = link_to 'Add new movie', new_movie_path + +%h1 Search TMDb for a movie + += form_tag :action => 'search_tmdb' do + + %label{:for => 'search_terms'} Search Terms + = text_field_tag 'search_terms' + = submit_tag 'Search TMDb' + \ No newline at end of file diff --git a/rottenpotatoes/app/views/movies/search_tmdb.html.haml b/rottenpotatoes/app/views/movies/search_tmdb.html.haml new file mode 100644 index 000000000..a4f197dcd --- /dev/null +++ b/rottenpotatoes/app/views/movies/search_tmdb.html.haml @@ -0,0 +1,21 @@ +%h2 Search Results +%h3 Details about #{@movies["title"]} + +%ul#details + += form_tag movies_path do + %li + = label :movie,:title,'Movie Title:' + %span#title= @movies["title"] + = hidden_field :movie,'title',value: @movies["title"] + %li + = label :movie,:rating,'Rating' + = select :movie,:rating, ['G','PG','PG-13','R','NC-17'] + %li + Released on: + = label :movie, :release_date,"Released On" + =date_select :movie,:release_date,selected: Date.parse(@movies["release_date"]) + + + = submit_tag 'Save to RottenPotatoes',:class => 'btn btn-primary' + \ No newline at end of file diff --git a/rottenpotatoes/config/routes.rb b/rottenpotatoes/config/routes.rb index 3a9dc190f..fa6a0c5c1 100644 --- a/rottenpotatoes/config/routes.rb +++ b/rottenpotatoes/config/routes.rb @@ -2,4 +2,5 @@ resources :movies # map '/' to be a redirect to '/movies' root :to => redirect('/movies') + post '/movies/search_tmdb' => 'movies#search_tmdb', :as => 'search_tmdb' end diff --git a/rottenpotatoes/features/search_tmdb.feature b/rottenpotatoes/features/search_tmdb.feature new file mode 100644 index 000000000..8783449bc --- /dev/null +++ b/rottenpotatoes/features/search_tmdb.feature @@ -0,0 +1,24 @@ +Feature: User can add movie by searching for it in the Movie Database (TMDb) + + As a movie fan + So that I can add new movies without manual tedium + I want to add movies by looking up their details in TMDb + +Scenario: Try to add nonexistent movie (sad path) + + Given I am on the RottenPotatoes home page + Then I should see "Search TMDb for a movie" + When I fill in "Search Terms" with "Movie That Does Not Exist" + And I press "Search TMDb" + Then I should be on the RottenPotatoes home page + And I should see "'Movie That Does Not Exist' was not found in TMDb" + +Scenario: Try to add existing movie (happy path) + + Given I am on the RottenPotatoes home page + Then I should see "Search TMDb for a movie" + When I fill in "Search Terms" with "Inception" + And I press "Search TMDb" + Then I should be on the "Search Results" page + And I should not see "not found" + And I should see "Inception" \ No newline at end of file diff --git a/rottenpotatoes/features/support/paths.rb b/rottenpotatoes/features/support/paths.rb index aec7b6740..7f60b9d1e 100644 --- a/rottenpotatoes/features/support/paths.rb +++ b/rottenpotatoes/features/support/paths.rb @@ -22,7 +22,8 @@ def path_to(page_name) when /^the Create New Movie page/ '/movies/new' - + when /^the "Search Results" page/ then '/movies/search_tmdb' + # Add more mappings here. # Here is an example that pulls values out of the Regexp: # From cb01e02e2462b707da8b3991051aedff093c7126 Mon Sep 17 00:00:00 2001 From: tete192356789 Date: Sun, 30 Oct 2022 18:09:55 +0700 Subject: [PATCH 7/7] SSO DONE. --- rottenpotatoes/Gemfile | 33 +- rottenpotatoes/Gemfile.lock | 288 ++++++++++------ .../moviegoers/confirmations_controller.rb | 30 ++ .../omniauth_callbacks_controller.rb | 62 ++++ .../moviegoers/passwords_controller.rb | 34 ++ .../moviegoers/registrations_controller.rb | 62 ++++ .../moviegoers/sessions_controller.rb | 41 +++ .../moviegoers/unlocks_controller.rb | 30 ++ rottenpotatoes/app/models/moviegoer.rb | 16 + .../app/views/layouts/login_form.html.haml | 6 + .../app/views/movies/index.html.haml | 93 ++++-- rottenpotatoes/bin/bundle | 3 + rottenpotatoes/bin/rails | 4 + rottenpotatoes/bin/rake | 4 + rottenpotatoes/bin/setup | 29 ++ rottenpotatoes/config/database.yml | 35 +- rottenpotatoes/config/environment.rb | 6 +- .../config/environments/development.rb | 40 ++- .../config/environments/production.rb | 85 +++-- rottenpotatoes/config/environments/test.rb | 37 ++- rottenpotatoes/config/initializers/assets.rb | 11 + .../config/initializers/cookies_serializer.rb | 3 + rottenpotatoes/config/initializers/devise.rb | 311 ++++++++++++++++++ .../initializers/filter_parameter_logging.rb | 4 + .../config/initializers/inflections.rb | 12 +- .../config/initializers/mime_types.rb | 1 - .../config/initializers/session_store.rb | 7 +- .../config/initializers/wrap_parameters.rb | 12 +- rottenpotatoes/config/routes.rb | 67 +++- rottenpotatoes/config/secrets.yml | 22 ++ rottenpotatoes/db/development.splite3 | Bin 0 -> 32768 bytes ...20221022162801_devise_create_moviegoers.rb | 47 +++ 32 files changed, 1207 insertions(+), 228 deletions(-) create mode 100644 rottenpotatoes/app/controllers/moviegoers/confirmations_controller.rb create mode 100644 rottenpotatoes/app/controllers/moviegoers/omniauth_callbacks_controller.rb create mode 100644 rottenpotatoes/app/controllers/moviegoers/passwords_controller.rb create mode 100644 rottenpotatoes/app/controllers/moviegoers/registrations_controller.rb create mode 100644 rottenpotatoes/app/controllers/moviegoers/sessions_controller.rb create mode 100644 rottenpotatoes/app/controllers/moviegoers/unlocks_controller.rb create mode 100644 rottenpotatoes/app/models/moviegoer.rb create mode 100644 rottenpotatoes/app/views/layouts/login_form.html.haml create mode 100755 rottenpotatoes/bin/bundle create mode 100755 rottenpotatoes/bin/rails create mode 100755 rottenpotatoes/bin/rake create mode 100755 rottenpotatoes/bin/setup create mode 100644 rottenpotatoes/config/initializers/assets.rb create mode 100644 rottenpotatoes/config/initializers/cookies_serializer.rb create mode 100644 rottenpotatoes/config/initializers/devise.rb create mode 100644 rottenpotatoes/config/initializers/filter_parameter_logging.rb create mode 100644 rottenpotatoes/config/secrets.yml create mode 100644 rottenpotatoes/db/development.splite3 create mode 100644 rottenpotatoes/db/migrate/20221022162801_devise_create_moviegoers.rb diff --git a/rottenpotatoes/Gemfile b/rottenpotatoes/Gemfile index cb5f82f28..fa882b1bb 100644 --- a/rottenpotatoes/Gemfile +++ b/rottenpotatoes/Gemfile @@ -1,8 +1,7 @@ source 'https://rubygems.org' -ruby '2.6.10' +ruby '2.6.3' gem 'rails', '4.2.10' - gem 'sass-rails', '~> 5.0.3' gem 'coffee-rails', '~> 4.1.0' gem 'uglifier', '>= 2.7.1' @@ -11,18 +10,15 @@ gem 'jquery-rails' gem 'haml' gem 'protected_attributes' - -group :test do - gem 'cucumber-rails', :require => false - gem 'cucumber-rails-training-wheels' # some pre-fabbed step definitions - gem 'database_cleaner' # to clear Cucumber's test database between runs - gem 'capybara' # lets Cucumber pretend to be a web browser - gem 'launchy' # a useful debugging aid for user stories -end - +gem 'omniauth-google-oauth2' +gem 'omniauth-rails_csrf_protection' +gem 'devise' +gem 'omniauth' group :development, :test do - gem 'sqlite3' + #gem 'pg' ,'~> 0.15' + + gem 'sqlite3' , '~> 1.3.6' gem 'byebug' gem 'database_cleaner' gem 'capybara' @@ -35,5 +31,16 @@ group :development, :test do end group :production do - gem 'pg' + gem 'pg' ,'~> 0.21' + gem 'rails_12factor' +end + +group :test do + gem 'cucumber-rails', :require => false + gem 'cucumber-rails-training-wheels' + gem 'database_cleaner' + gem 'capybara' + gem 'launchy' + #gem 'pg' ,'~> 0.15' + #gem 'sqlite3' , '~> 1.3.6' end diff --git a/rottenpotatoes/Gemfile.lock b/rottenpotatoes/Gemfile.lock index 36e54caec..6cc5a99cd 100644 --- a/rottenpotatoes/Gemfile.lock +++ b/rottenpotatoes/Gemfile.lock @@ -35,89 +35,162 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.4.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) arel (6.0.4) - builder (3.2.3) - byebug (9.0.5) - capybara (2.7.1) + bcrypt (3.1.18) + builder (3.2.4) + byebug (11.1.3) + capybara (3.36.0) addressable - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (~> 2.0) - coderay (1.1.2) + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + coderay (1.1.3) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.5) - crass (1.0.4) - cucumber (2.4.0) - builder (>= 2.1.2) - cucumber-core (~> 1.5.0) - cucumber-wire (~> 0.0.1) - diff-lcs (>= 1.1.3) - gherkin (~> 4.0) - multi_json (>= 1.7.5, < 2.0) - multi_test (>= 0.1.2) - cucumber-core (1.5.0) - gherkin (~> 4.0) - cucumber-rails (1.4.3) - capybara (>= 1.1.2, < 3) - cucumber (>= 1.3.8, < 3) - mime-types (>= 1.16, < 4) - nokogiri (~> 1.5) - railties (>= 3, < 5) + coffee-script-source (1.12.2) + concurrent-ruby (1.1.10) + crass (1.0.6) + cucumber (4.1.0) + builder (~> 3.2, >= 3.2.3) + cucumber-core (~> 7.1, >= 7.1.0) + cucumber-create-meta (~> 1.0.0, >= 1.0.0) + cucumber-cucumber-expressions (~> 10.1, >= 10.1.0) + cucumber-gherkin (~> 14.0, >= 14.0.1) + cucumber-html-formatter (~> 7.0, >= 7.0.0) + cucumber-messages (~> 12.2, >= 12.2.0) + cucumber-wire (~> 3.1, >= 3.1.0) + diff-lcs (~> 1.3, >= 1.3, < 1.4) + multi_test (~> 0.1, >= 0.1.2) + sys-uname (~> 1.0, >= 1.0.2) + cucumber-core (7.1.0) + cucumber-gherkin (~> 14.0, >= 14.0.1) + cucumber-messages (~> 12.2, >= 12.2.0) + cucumber-tag-expressions (~> 2.0, >= 2.0.4) + cucumber-create-meta (1.0.0) + cucumber-messages (~> 12.2, >= 12.2.0) + sys-uname (~> 1.2, >= 1.2.1) + cucumber-cucumber-expressions (10.3.0) + cucumber-gherkin (14.2.0) + cucumber-messages (~> 12.4, >= 12.4.0) + cucumber-html-formatter (7.2.0) + cucumber-messages (~> 12.4, >= 12.4.0) + cucumber-messages (12.4.0) + protobuf-cucumber (~> 3.10, >= 3.10.8) + cucumber-rails (2.1.0) + capybara (>= 2.12, < 4) + cucumber (>= 3.0.2, < 5) + mime-types (>= 2.0, < 4) + nokogiri (~> 1.8) + rails (>= 4.2, < 7) cucumber-rails-training-wheels (1.0.0) cucumber-rails (>= 1.1.1) - cucumber-wire (0.0.1) - database_cleaner (1.5.3) - diff-lcs (1.2.5) + cucumber-tag-expressions (2.0.4) + cucumber-wire (3.1.0) + cucumber-core (~> 7.1, >= 7.1.0) + cucumber-cucumber-expressions (~> 10.1, >= 10.1.0) + cucumber-messages (~> 12.2, >= 12.2.0) + database_cleaner (1.99.0) + devise (4.8.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) + diff-lcs (1.3) erubis (2.7.0) - execjs (2.7.0) - gherkin (4.0.0) - globalid (0.4.1) + execjs (2.8.1) + faraday (2.6.0) + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.1) + ffi (1.15.5) + globalid (0.4.2) activesupport (>= 4.2.0) - haml (4.0.7) + haml (6.0.7) + temple (>= 0.8.2) + thor tilt + hashie (5.0.0) i18n (0.9.5) concurrent-ruby (~> 1.0) - jquery-rails (4.1.1) + jquery-rails (4.5.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - launchy (2.4.3) - addressable (~> 2.3) - loofah (2.2.2) + jwt (2.5.0) + launchy (2.5.0) + addressable (~> 2.7) + loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) - method_source (0.9.0) - mime-types (3.1) + matrix (0.4.2) + method_source (1.0.0) + middleware (0.1.0) + mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.3) - multi_json (1.12.1) + mime-types-data (3.2022.0105) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) multi_test (0.1.2) - nokogiri (1.8.3) - mini_portile2 (~> 2.3.0) - pg (1.1.4) - protected_attributes (1.1.3) + multi_xml (0.6.0) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) + oauth2 (2.0.9) + faraday (>= 0.17.3, < 3.0) + jwt (>= 1.0, < 3.0) + multi_xml (~> 0.5) + rack (>= 1.2, < 4) + snaky_hash (~> 2.0) + version_gem (~> 1.1) + omniauth (2.0.4) + hashie (>= 3.4.6) + rack (>= 1.6.2, < 3) + rack-protection + omniauth-google-oauth2 (1.1.1) + jwt (>= 2.0) + oauth2 (~> 2.0.6) + omniauth (~> 2.0) + omniauth-oauth2 (~> 1.8.0) + omniauth-oauth2 (1.8.0) + oauth2 (>= 1.4, < 3) + omniauth (~> 2.0) + omniauth-rails_csrf_protection (1.0.1) + actionpack (>= 4.2) + omniauth (~> 2.0) + orm_adapter (0.5.0) + pg (0.21.0) + protected_attributes (1.1.4) activemodel (>= 4.0.1, < 5.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.4.3) - byebug (>= 9.0, < 9.1) + protobuf-cucumber (3.10.8) + activesupport (>= 3.2) + middleware + thor + thread_safe + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.8.0) + byebug (~> 11.0) pry (~> 0.10) - rack (1.6.10) + public_suffix (5.0.0) + racc (1.6.0) + rack (1.6.13) + rack-protection (3.0.2) + rack rack-test (0.6.3) rack (>= 1.0) rails (4.2.10) @@ -131,61 +204,87 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.2.10) sprockets-rails - rails-deprecated_sanitizer (1.0.3) + rails-deprecated_sanitizer (1.0.4) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.9) activesupport (>= 4.2.0, < 5.0) nokogiri (~> 1.6) rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) railties (4.2.10) actionpack (= 4.2.10) activesupport (= 4.2.10) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.3.1) - rspec-core (3.4.4) - rspec-support (~> 3.4.0) - rspec-expectations (3.4.0) + rake (13.0.6) + rb-fsevent (0.11.2) + rb-inotify (0.10.1) + ffi (~> 1.0) + regexp_parser (2.6.0) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.4.0) - rspec-mocks (3.4.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.4.0) - rspec-rails (3.4.2) - actionpack (>= 3.0, < 4.3) - activesupport (>= 3.0, < 4.3) - railties (>= 3.0, < 4.3) - rspec-core (~> 3.4.0) - rspec-expectations (~> 3.4.0) - rspec-mocks (~> 3.4.0) - rspec-support (~> 3.4.0) - rspec-support (3.4.1) - sass (3.4.22) - sass-rails (5.0.4) - railties (>= 4.0.0, < 5.0) + rspec-support (~> 3.12.0) + rspec-rails (4.1.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + ruby2_keywords (0.0.5) + 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.0.7) + railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + snaky_hash (2.0.1) + hashie + version_gem (~> 1.1, >= 1.1.1) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.11) - thor (0.20.0) + sqlite3 (1.3.13) + sys-uname (1.2.2) + ffi (~> 1.1) + temple (0.9.1) + thor (1.2.1) thread_safe (0.3.6) - tilt (2.0.5) - tzinfo (1.2.5) + tilt (2.0.11) + tzinfo (1.2.10) thread_safe (~> 0.1) - uglifier (3.0.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - xpath (2.0.0) - nokogiri (~> 1.3) + version_gem (1.1.1) + warden (1.2.7) + rack (>= 1.0) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby @@ -197,21 +296,26 @@ DEPENDENCIES cucumber-rails cucumber-rails-training-wheels database_cleaner + devise haml jquery-rails launchy - pg + omniauth + omniauth-google-oauth2 + omniauth-rails_csrf_protection + pg (~> 0.21) protected_attributes pry pry-byebug rails (= 4.2.10) + rails_12factor rspec-rails sass-rails (~> 5.0.3) - sqlite3 + sqlite3 (~> 1.3.6) uglifier (>= 2.7.1) RUBY VERSION - ruby 2.6.10p210 + ruby 2.6.3p62 BUNDLED WITH - 1.17.2 + 2.0.0.pre.3 diff --git a/rottenpotatoes/app/controllers/moviegoers/confirmations_controller.rb b/rottenpotatoes/app/controllers/moviegoers/confirmations_controller.rb new file mode 100644 index 000000000..ed097453d --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Moviegoers::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/rottenpotatoes/app/controllers/moviegoers/omniauth_callbacks_controller.rb b/rottenpotatoes/app/controllers/moviegoers/omniauth_callbacks_controller.rb new file mode 100644 index 000000000..086dcd92c --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/omniauth_callbacks_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Moviegoers::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + def google_oauth2 + moviegoer = Moviegoer.from_omniauth(auth) + + if moviegoer.present? + sign_out_all_scopes + flash[:success] = t 'devise.omniauth_callbacks.success', kind: 'Google' + sign_in_and_redirect moviegoer, event: :authentication + else + flash[:alert] = + t 'devise.omniauth_callbacks.failure',kind: 'Google', reason: "#{auth.info.email} is not authorized" + redirect_to new_moviegoer_session_path + + end + + + + end + + #protected + #def after_omniauth_failure_path_for(_scope) + # new_moviegoer_session_path + #end + + #def after_sign_in_path_for(resource_or_scope) + # stroed_location_for(resource_or_scope) || movies_path + #end + + + # More info at: + # https://github.com/heartcombo/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when OmniAuth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end + private + def auth + @auth ||= request.env['omniauth.auth'] + end + +end diff --git a/rottenpotatoes/app/controllers/moviegoers/passwords_controller.rb b/rottenpotatoes/app/controllers/moviegoers/passwords_controller.rb new file mode 100644 index 000000000..8777f4d81 --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Moviegoers::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/rottenpotatoes/app/controllers/moviegoers/registrations_controller.rb b/rottenpotatoes/app/controllers/moviegoers/registrations_controller.rb new file mode 100644 index 000000000..0ae950456 --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Moviegoers::RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/rottenpotatoes/app/controllers/moviegoers/sessions_controller.rb b/rottenpotatoes/app/controllers/moviegoers/sessions_controller.rb new file mode 100644 index 000000000..0c0f4a2bd --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/sessions_controller.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class Moviegoers::SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + + #def destroy + #super + # @authen = current_moviegoer.authenticatable_salt.find(params[:id]) + #@authen.destroy + + #end + + def after_sign_out_path_for(_resource_or_scope) + + movies_path + end + + def after_sign_in_path_for(resource_or_scope) + stored_location_for(resource_or_scope) || movies_path + end + + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end +end diff --git a/rottenpotatoes/app/controllers/moviegoers/unlocks_controller.rb b/rottenpotatoes/app/controllers/moviegoers/unlocks_controller.rb new file mode 100644 index 000000000..6a987d683 --- /dev/null +++ b/rottenpotatoes/app/controllers/moviegoers/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Moviegoers::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/rottenpotatoes/app/models/moviegoer.rb b/rottenpotatoes/app/models/moviegoer.rb new file mode 100644 index 000000000..cf07fc8aa --- /dev/null +++ b/rottenpotatoes/app/models/moviegoer.rb @@ -0,0 +1,16 @@ +class Moviegoer < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable, + :omniauthable, omniauth_providers: [:google_oauth2] + + def self.from_omniauth(auth) + where(provider: auth.provider, uid: auth.uid).first_or_create do |moviegoer| + moviegoer.email = auth.info.email + moviegoer.password = Devise.friendly_token[0,20] + moviegoer.full_name = auth.info.name + moviegoer.avatar_url = auth.info.image + end + end +end diff --git a/rottenpotatoes/app/views/layouts/login_form.html.haml b/rottenpotatoes/app/views/layouts/login_form.html.haml new file mode 100644 index 000000000..f9c470368 --- /dev/null +++ b/rottenpotatoes/app/views/layouts/login_form.html.haml @@ -0,0 +1,6 @@ +#login + - if @current_user + %p.Welcome Welcome, #{@current_user.name}! + = link_to 'Log Out', logout_path + - else + %p.login= link_to 'Log in with your Twitter account', login_path diff --git a/rottenpotatoes/app/views/movies/index.html.haml b/rottenpotatoes/app/views/movies/index.html.haml index f0dd4a15e..59aeef1cc 100644 --- a/rottenpotatoes/app/views/movies/index.html.haml +++ b/rottenpotatoes/app/views/movies/index.html.haml @@ -1,37 +1,68 @@ -# This file is app/views/movies/index.html.haml -%h2 All Movies - -= form_tag movies_path, :method => :get, :id => 'ratings_form' do - = hidden_field_tag "title_sort", true if @title_header - = hidden_field_tag ":release_date_sort", true if @date_header - Include: - - @all_ratings.each do |rating| - = rating - = check_box_tag "ratings[#{rating}]", 1, @selected_ratings.include?(rating), :id => "ratings_#{rating}" - = submit_tag 'Refresh', :id => 'ratings_submit', :class => 'btn btn-primary' - -%table#movies.table.table-striped.col-md-12 - %thead - %tr - %th{:class => @title_header}= link_to 'Movie Title', movies_path(:sort => 'title', :ratings => @selected_ratings), :id => 'title_header' - %th Rating - %th{:class => @date_header}= link_to 'Release Date', movies_path(:sort => 'release_date', :ratings => @selected_ratings), :id => 'release_date_header' - %th More Info - %tbody - - @movies.each do |movie| + +//<% if current_user %> +/

<%= current_user.email %>

+/<%= link_to "Edit Account" , edit_moviegoer_registration_path %> +/<%= button_to "Logout",destroy_moviegoer_session_path, data: {turbo: "false"}, method: :delete %> +/<% else %> +/<%= link_to "Login", new_moviegoer_session_path %> +//<%= link_to "Create Account", new_moviegoer_registration_path %> +//<% end %> +/= link_to 'Add new movie', new_movie_path + +- if current_moviegoer + =image_tag asset_path(current_moviegoer.avatar_url) + = "Welcome #{current_moviegoer.email} to RottenPotatoes" + = link_to 'Logout', destroy_moviegoer_session_path, :method => :delete + + + = form_tag movies_path, :method => :get, :id => 'ratings_form' do + = hidden_field_tag "title_sort", true if @title_header + = hidden_field_tag ":release_date_sort", true if @date_header + Include: + - @all_ratings.each do |rating| + = rating + = check_box_tag "ratings[#{rating}]", 1, @selected_ratings.include?(rating), :id => "ratings_#{rating}" + = submit_tag 'Refresh', :id => 'ratings_submit', :class => 'btn btn-primary' + + %table#movies.table.table-striped.col-md-12 + %thead %tr - %td= movie.title - %td= movie.rating - %td= movie.release_date - %td= link_to "More about #{movie.title}", movie_path(movie) + %th{:class => @title_header}= link_to 'Movie Title', movies_path(:sort => 'title', :ratings => @selected_ratings), :id => 'title_header' + %th Rating + %th{:class => @date_header}= link_to 'Release Date', movies_path(:sort => 'release_date', :ratings => @selected_ratings), :id => 'release_date_header' + %th More Info + %tbody + - @movies.each do |movie| + %tr + %td= movie.title + %td= movie.rating + %td= movie.release_date + %td= link_to "More about #{movie.title}", movie_path(movie) + + = link_to 'Add new movie', new_movie_path + + %h1 Search TMDb for a movie + + = form_tag :action => 'search_tmdb' do + + %label{:for => 'search_terms'} Search Terms + = text_field_tag 'search_terms' + = submit_tag 'Search TMDb' + +- else + = link_to 'Login' , new_moviegoer_session_path + -= link_to 'Add new movie', new_movie_path + %h2 All Movies -%h1 Search TMDb for a movie -= form_tag :action => 'search_tmdb' do + = form_tag movies_path, :method => :get, :id => 'ratings_form' do + = hidden_field_tag "title_sort", true if @title_header + = hidden_field_tag ":release_date_sort", true if @date_header + Include: + - @all_ratings.each do |rating| + = rating + = check_box_tag "ratings[#{rating}]", 1, @selected_ratings.include?(rating), :id => "ratings_#{rating}" + = submit_tag 'Refresh', :id => 'ratings_submit', :class => 'btn btn-primary' - %label{:for => 'search_terms'} Search Terms - = text_field_tag 'search_terms' - = submit_tag 'Search TMDb' - \ No newline at end of file diff --git a/rottenpotatoes/bin/bundle b/rottenpotatoes/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/rottenpotatoes/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/rottenpotatoes/bin/rails b/rottenpotatoes/bin/rails new file mode 100755 index 000000000..5191e6927 --- /dev/null +++ b/rottenpotatoes/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/rottenpotatoes/bin/rake b/rottenpotatoes/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/rottenpotatoes/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/rottenpotatoes/bin/setup b/rottenpotatoes/bin/setup new file mode 100755 index 000000000..acdb2c138 --- /dev/null +++ b/rottenpotatoes/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/rottenpotatoes/config/database.yml b/rottenpotatoes/config/database.yml index 699867ec9..f564bb588 100644 --- a/rottenpotatoes/config/database.yml +++ b/rottenpotatoes/config/database.yml @@ -4,8 +4,10 @@ # Ensure the SQLite 3 gem is defined in your Gemfile # gem 'sqlite3' development: + + adapter: sqlite3 - database: db/development.sqlite3 + database: db/development.splite3 pool: 5 timeout: 5000 @@ -13,16 +15,39 @@ development: # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: &test - adapter: sqlite3 - database: db/test.sqlite3 + + adapter: postgresql + database: test_database pool: 5 timeout: 5000 production: - adapter: sqlite3 - database: db/production.sqlite3 + host: <%= ENV['DB_HOST'] %> + adapter: postgresql + database: <%= ENV['DB'] %> + username: <%= ENV['DB_USERNAME'] %> + password: <%= ENV['DB_PASSWORD'] %> pool: 5 timeout: 5000 + # url: <%= ENV['DATABASE_URL'] %> + +cucumber: + <<: *test + +cucumber: + <<: *test + +cucumber: + <<: *test + +cucumber: + <<: *test + +cucumber: + <<: *test + +cucumber: + <<: *test cucumber: <<: *test diff --git a/rottenpotatoes/config/environment.rb b/rottenpotatoes/config/environment.rb index a1bbe1044..ee8d90dc6 100644 --- a/rottenpotatoes/config/environment.rb +++ b/rottenpotatoes/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application +# Load the Rails application. require File.expand_path('../application', __FILE__) -# Initialize the rails application -Rottenpotatoes::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/rottenpotatoes/config/environments/development.rb b/rottenpotatoes/config/environments/development.rb index cdb042b29..4a5e9eb9d 100644 --- a/rottenpotatoes/config/environments/development.rb +++ b/rottenpotatoes/config/environments/development.rb @@ -1,31 +1,43 @@ -Rottenpotatoes::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development + # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. + ENV['GOOGLE_OAUTH_CLIENT_ID'] = '604430754479-3qq3oeb0egs4iqjhh6gashhvmt561b48.apps.googleusercontent.com' + ENV['GOOGLE_OAUTH_CLIENT_SECRET'] = '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' config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - #config.whiny_nils = true + # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Don't care if the mailer can't send + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - #config.action_dispatch.best_standards_support = :builtin + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load - # Do not compress assets - #config.assets.compress = false - - # Expands the lines which load the assets + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/rottenpotatoes/config/environments/production.rb b/rottenpotatoes/config/environments/production.rb index 00e4af44f..9a4df5098 100644 --- a/rottenpotatoes/config/environments/production.rb +++ b/rottenpotatoes/config/environments/production.rb @@ -1,63 +1,80 @@ -Rottenpotatoes::Application.configure do - # Settings specified here will take precedence over those in config/application.rb - - # Code is not reloaded between requests +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + ENV['GOOGLE_OAUTH_CLIENT_ID'] = '604430754479-3qq3oeb0egs4iqjhh6gashhvmt561b48.apps.googleusercontent.com' + ENV['GOOGLE_OAUTH_CLIENT_SECRET'] = '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' + # Code is not reloaded between requests. config.cache_classes = true - # Full error reports are disabled and caching is turned on + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true - config.eager_load = true - + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true - # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? - # Compress JavaScripts and CSS + # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass - # DO fallback to assets pipeline if a precompiled asset is missed - config.assets.compile = true + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false - # Generate digests for assets URLs + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. config.assets.digest = true - # Defaults to Rails.root.join("public/assets") - # config.assets.manifest = YOUR_PATH + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb - # Specifies the header that your server uses for sending files - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # See everything in the log (default is :info) - # config.log_level = :debug + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug - # Use a different logger for distributed setups - # config.logger = SyslogLogger.new + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] - # Use a different cache store in production - # config.cache_store = :mem_cache_store + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - # Enable serving of images, stylesheets, and JavaScripts from an asset server - # config.action_controller.asset_host = "http://assets.example.com" + # Use a different cache store in production. + # config.cache_store = :mem_cache_store - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - # config.assets.precompile += %w( search.js ) + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' - # Disable delivery errors, bad email addresses will be ignored + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) + # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false end diff --git a/rottenpotatoes/config/environments/test.rb b/rottenpotatoes/config/environments/test.rb index e89bfd00a..1c19f08b2 100644 --- a/rottenpotatoes/config/environments/test.rb +++ b/rottenpotatoes/config/environments/test.rb @@ -1,41 +1,42 @@ -Rottenpotatoes::Application.configure do - # Settings specified here will take precedence over those in config/application.rb +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that + # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! + # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false # 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 - # Use SQL instead of Active Record's schema dumper when creating the test database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql + # Randomize the order test cases are executed. + config.active_support.test_order = :random - # Print deprecation notices to the stderr + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets - config.assets.allow_debugging = true + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/rottenpotatoes/config/initializers/assets.rb b/rottenpotatoes/config/initializers/assets.rb new file mode 100644 index 000000000..01ef3e663 --- /dev/null +++ b/rottenpotatoes/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/rottenpotatoes/config/initializers/cookies_serializer.rb b/rottenpotatoes/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..ac5f8b663 --- /dev/null +++ b/rottenpotatoes/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/rottenpotatoes/config/initializers/devise.rb b/rottenpotatoes/config/initializers/devise.rb new file mode 100644 index 000000000..2f7fc0099 --- /dev/null +++ b/rottenpotatoes/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 = '418d6004ef77613731c9e41379c54ad56f5f7e8f90868a3fe2d18a3717371001fa5eff6456906928043d6a41c3ddda4aa01ff5d45de302930ec6059acdd2b668' + + # ==> 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 = 'please-change-me-at-config-initializers-devise@example.com' + config.omniauth :google_oauth2,ENV['GOOGLE_OAUTH_CLIENT_ID'],ENV['GOOGLE_OAUTH_CLIENT_SECRET'] + # 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 = 'ada132139ea8eddcbae10c7d19ba3df14230a4252736b7e845d01835e1ec9a4fc59f7cff177891597871701ccf45b26002fc237cbc55873186ad3287fdaff742' + + # 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 = false + + # 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 = 6..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]+@[^@\s]+\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 = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> 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 = :delete + + # ==> 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/rottenpotatoes/config/initializers/filter_parameter_logging.rb b/rottenpotatoes/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/rottenpotatoes/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/rottenpotatoes/config/initializers/inflections.rb b/rottenpotatoes/config/initializers/inflections.rb index 9e8b0131f..ac033bf9d 100644 --- a/rottenpotatoes/config/initializers/inflections.rb +++ b/rottenpotatoes/config/initializers/inflections.rb @@ -1,10 +1,16 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/rottenpotatoes/config/initializers/mime_types.rb b/rottenpotatoes/config/initializers/mime_types.rb index 72aca7e44..dc1899682 100644 --- a/rottenpotatoes/config/initializers/mime_types.rb +++ b/rottenpotatoes/config/initializers/mime_types.rb @@ -2,4 +2,3 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/rottenpotatoes/config/initializers/session_store.rb b/rottenpotatoes/config/initializers/session_store.rb index 6a8e3fc91..cbaa4e687 100644 --- a/rottenpotatoes/config/initializers/session_store.rb +++ b/rottenpotatoes/config/initializers/session_store.rb @@ -1,8 +1,3 @@ # Be sure to restart your server when you modify this file. -Rottenpotatoes::Application.config.session_store :cookie_store, key: '_rottenpotatoes_session' - -# Use the database for sessions instead of the cookie-based default, -# which shouldn't be used to store highly confidential information -# (create the session table with "rails generate session_migration") -# Rottenpotatoes::Application.config.session_store :active_record_store +Rails.application.config.session_store :cookie_store, key: '_rottenpotatoes_session' diff --git a/rottenpotatoes/config/initializers/wrap_parameters.rb b/rottenpotatoes/config/initializers/wrap_parameters.rb index 999df2018..33725e95f 100644 --- a/rottenpotatoes/config/initializers/wrap_parameters.rb +++ b/rottenpotatoes/config/initializers/wrap_parameters.rb @@ -1,14 +1,14 @@ # Be sure to restart your server when you modify this file. -# + # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end -# Disable root element in JSON by default. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false -end +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/rottenpotatoes/config/routes.rb b/rottenpotatoes/config/routes.rb index fa6a0c5c1..8292ca891 100644 --- a/rottenpotatoes/config/routes.rb +++ b/rottenpotatoes/config/routes.rb @@ -1,6 +1,69 @@ -Rottenpotatoes::Application.routes.draw do + + +Rails.application.routes.draw do + + + devise_for :moviegoers , controllers: { + sessions: 'moviegoers/sessions', + omniauth_callbacks: 'moviegoers/omniauth_callbacks' + } resources :movies - # map '/' to be a redirect to '/movies' + root :to => redirect('/movies') post '/movies/search_tmdb' => 'movies#search_tmdb', :as => 'search_tmdb' + #devise_for :moviegoers + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end end diff --git a/rottenpotatoes/config/secrets.yml b/rottenpotatoes/config/secrets.yml new file mode 100644 index 000000000..5a549a062 --- /dev/null +++ b/rottenpotatoes/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 473d546c5e7ec67afa11b5a1c83d7fbd00ffb3e7df46d24b00bd781a499fad50b800d63efcdf039d2a26eb4306fb78890e889e484bac2c1ec6d4d7cc348740ef + +test: + secret_key_base: 2ee7682209077a004a3b13b0117cd67e9e564173a55730df36014efbf92a2715e1a0913380fe88f78efef71dc4056319ad12726a66b5ba7708306bff40e62fcd + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/rottenpotatoes/db/development.splite3 b/rottenpotatoes/db/development.splite3 new file mode 100644 index 0000000000000000000000000000000000000000..269b014da219ef52c4e07ad644985a22bf85c3a9 GIT binary patch literal 32768 zcmeI)?Qhyf90zb4l0dRGw38;(7uy^ZEk!NHPY^(>RyWXwl|oCQE$TMQfeWzsf!Zby zmG&a5v_D|~LjRz>+N}51;g{4%r_)Xr{f}CtaI3u4Y@B zLtNr%1KoA^Y^S4n_71TouZV8cOKPLUHLK!nw82mE^*YLUEOK- zbcZXJZmG>mgIimhdXd$34hA0S91l%`dv}TLpyFCNLw#5GbVnOH zM)2&wp);aGoZz_=hba(gCf_BNr|DjT>*yZw`X-^3Im9I97ICz;L+IJgZ2n27g9O8Y zA8fkVaengN+(P{7Rkk%6H20}NS9qFBo(_rCCNqcgQ^PltdBrEYMoT6Se+)rz8f+wBuJ9zZ&@iPh!6np8f|6iWF z4x+&jfB*y_009U<00Izz00bZa0SJ5+PO{U>|Inpya&db7?|=V4znoxVFJj*;zg+&A z?jk_|0uX=z1Rwwb2tWV=5P-l(DbSjaGM8eEN|SfnUr(k)AthxwK`4y=cwv+RIigUI zG6gxu%UM}ba;N8fKNn@2JtzrHG8(vwQ+`hwK|Fg@#GxQG$0uX=z1Rwwb z2tWV=5P$##AaGs;e&N{|Q#+i`uOH^uXroot&B}r(h*DOhKQ36mF}lGdzhe$PYm3+0 zyw_Wm^i@$>-PyR=RC@gOdbi%{Ik$?>D%-G7mby>7Kh?Kx-nsR# zRopip@7}4Z8=GpC-pEre-+fRo(}Q}gR27B1oXh3bvr1Ny^I0*Q$!F!B=MCIKI&Ji1 zzH8fEgA85bv~A0yw}<50wwcz`YQ@a#4dqr&H;G}}|9P3? zXeR_9009U<00Izz00bZa0SG`KD6kr?Exz}^ALI4^YbN$OSQPsZfB*y_009U<00Izz R00bZa0SJ630^u;T_%GElsVo2h literal 0 HcmV?d00001 diff --git a/rottenpotatoes/db/migrate/20221022162801_devise_create_moviegoers.rb b/rottenpotatoes/db/migrate/20221022162801_devise_create_moviegoers.rb new file mode 100644 index 000000000..d62c6ee23 --- /dev/null +++ b/rottenpotatoes/db/migrate/20221022162801_devise_create_moviegoers.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +class DeviseCreateMoviegoers < ActiveRecord::Migration + def change + create_table :moviegoers do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + t.string :full_name + t.string :uid + t.string :avatar_url + t.string :provider + ## 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 :moviegoers, :email, unique: true + add_index :moviegoers, :reset_password_token, unique: true + # add_index :moviegoers, :confirmation_token, unique: true + # add_index :moviegoers, :unlock_token, unique: true + end +end