From 1bc17c462a6ca5340ba6c85f18950cd988ccb5a3 Mon Sep 17 00:00:00 2001 From: Dinis Date: Wed, 19 Aug 2020 07:31:31 +0100 Subject: [PATCH] First working version with devise+rails_admin --- .idea/workspace.xml | 92 ++++++++++++++++--- Dockerfile | 1 + Gemfile | 6 +- Gemfile.lock | 39 ++++++++ app/assets/stylesheets/pages.scss | 3 + app/controllers/pages_controller.rb | 4 + app/helpers/pages_helper.rb | 2 + app/javascript/packs/application.js | 3 +- app/javascript/stylesheets/application.scss | 1 + app/models/admin.rb | 3 +- app/views/layouts/application.html.erb | 8 ++ app/views/pages/home.html.erb | 2 + config/initializers/assets.rb | 6 ++ config/initializers/devise.rb | 6 +- config/routes.rb | 2 + .../20200817200957_devise_create_admins.rb | 28 +++--- db/seeds.rb | 1 + package.json | 1 + ss-calculator.iml | 27 +++++- test/controllers/pages_controller_test.rb | 9 ++ yarn.lock | 24 +++-- 21 files changed, 230 insertions(+), 38 deletions(-) create mode 100644 app/assets/stylesheets/pages.scss create mode 100644 app/controllers/pages_controller.rb create mode 100644 app/helpers/pages_helper.rb create mode 100644 app/javascript/stylesheets/application.scss create mode 100644 app/views/pages/home.html.erb create mode 100644 test/controllers/pages_controller_test.rb diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c1b258d..13a6f13 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,17 +2,28 @@ - + + + + + + + + - - - + + + + + + + + + + + + - + - + + + + + + + + + @@ -79,26 +120,43 @@ + + 1597695591871 + + + + + - + - - + + - + + + + + @@ -111,9 +169,21 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 98da29a..0f80b5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp +RUN yarn install --check-files # Add a script to be executed every time the container starts. COPY entrypoint.sh /usr/bin/ diff --git a/Gemfile b/Gemfile index 3b6cb49..e1868e3 100644 --- a/Gemfile +++ b/Gemfile @@ -57,4 +57,8 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'rails_admin', '~> 2.0' # Auth with devise -gem 'devise', '~> 4.7' \ No newline at end of file +gem 'devise', '~> 4.7' +gem 'omniauth-github' +gem 'omniauth-openid' +gem 'omniauth-google-oauth2' +gem 'omniauth-facebook' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 26add5c..85d35e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,6 +86,8 @@ GEM responders warden (~> 1.2.3) erubi (1.9.0) + faraday (1.0.1) + multipart-post (>= 1.2, < 3) ffi (1.13.1) ffi (1.13.1-x64-mingw32) globalid (0.4.2) @@ -93,6 +95,7 @@ GEM haml (5.1.2) temple (>= 0.8.0) tilt + hashie (4.1.0) i18n (1.8.5) concurrent-ruby (~> 1.0) jbuilder (2.10.0) @@ -103,6 +106,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) + jwt (2.2.2) kaminari (1.2.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.1) @@ -132,12 +136,39 @@ GEM minitest (5.14.1) msgpack (1.3.3) msgpack (1.3.3-x64-mingw32) + multi_json (1.15.0) + multi_xml (0.6.0) + multipart-post (2.1.1) nested_form (0.3.2) nio4r (2.5.2) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) nokogiri (1.10.10-x64-mingw32) mini_portile2 (~> 2.4.0) + oauth2 (1.4.4) + faraday (>= 0.8, < 2.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.9.1) + hashie (>= 3.4.6) + rack (>= 1.6.2, < 3) + omniauth-facebook (6.0.0) + omniauth-oauth2 (~> 1.2) + omniauth-github (1.4.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-google-oauth2 (0.8.0) + jwt (>= 2.0) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.6) + omniauth-oauth2 (1.7.0) + oauth2 (~> 1.4) + omniauth (~> 1.9) + omniauth-openid (1.0.1) + omniauth (~> 1.0) + rack-openid (~> 1.3.1) orm_adapter (0.5.0) pg (1.2.3) pg (1.2.3-x64-mingw32) @@ -145,6 +176,9 @@ GEM puma (4.3.5) nio4r (~> 2.0) rack (2.2.3) + rack-openid (1.3.1) + rack (>= 1.1.0) + ruby-openid (>= 2.1.8) rack-pjax (1.1.0) nokogiri (~> 1.5) rack (>= 1.1) @@ -199,6 +233,7 @@ GEM responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) + ruby-openid (2.9.2) rubyzip (2.3.0) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -270,6 +305,10 @@ DEPENDENCIES devise (~> 4.7) jbuilder (~> 2.7) listen (~> 3.2) + omniauth-facebook + omniauth-github + omniauth-google-oauth2 + omniauth-openid pg (>= 0.18, < 2.0) puma (~> 4.1) rails (~> 6.0.3, >= 6.0.3.2) diff --git a/app/assets/stylesheets/pages.scss b/app/assets/stylesheets/pages.scss new file mode 100644 index 0000000..32ebd4f --- /dev/null +++ b/app/assets/stylesheets/pages.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the pages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..45f463e --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,4 @@ +class PagesController < ApplicationController + def home + end +end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb new file mode 100644 index 0000000..2c057fd --- /dev/null +++ b/app/helpers/pages_helper.rb @@ -0,0 +1,2 @@ +module PagesHelper +end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 9cd55d4..2c74500 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -7,7 +7,8 @@ require("@rails/ujs").start() require("turbolinks").start() require("@rails/activestorage").start() require("channels") - +global.toastr = require("toastr") +import "../stylesheets/application" // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) diff --git a/app/javascript/stylesheets/application.scss b/app/javascript/stylesheets/application.scss new file mode 100644 index 0000000..a9ca5af --- /dev/null +++ b/app/javascript/stylesheets/application.scss @@ -0,0 +1 @@ +@import 'toastr' diff --git a/app/models/admin.rb b/app/models/admin.rb index 7a7be2f..86be4db 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -2,5 +2,6 @@ class Admin < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :validatable + :recoverable, :rememberable, :validatable, :confirmable, + :lockable, :timeoutable, :trackable, :omniauthable end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5e47171..fe9a881 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,14 @@ + <% unless flash.empty? %> + + <% end %>

<%= notice %>

<%= alert %>

<%= yield %> diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb new file mode 100644 index 0000000..3453cf2 --- /dev/null +++ b/app/views/pages/home.html.erb @@ -0,0 +1,2 @@ +

Pages#home

+

Find me in app/views/pages/home.html.erb

diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e8..c94ed58 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -12,3 +12,9 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules') # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) + +# Workaround for Segfault +# https://github.com/sass/sassc-ruby/issues/197 +Rails.application.config.assets.configure do |env| + env.export_concurrent = false +end \ No newline at end of file diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ad4fb95..6c553b7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -143,7 +143,7 @@ Devise.setup do |config| # 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 + 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 @@ -151,7 +151,7 @@ Devise.setup do |config| # 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 + 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 @@ -164,7 +164,7 @@ Devise.setup do |config| # ==> Configuration for :rememberable # The time the user will be remembered without asking for credentials again. - # config.remember_for = 2.weeks + config.remember_for = 8.weeks # Invalidates all the remember me tokens when the user signs out. config.expire_all_remember_me_on_sign_out = true diff --git a/config/routes.rb b/config/routes.rb index b1b88bd..b80f170 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do + get 'pages/home' mount RailsAdmin::Engine => '/admin', as: 'rails_admin' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html devise_for :admins + root to: "pages#home" end diff --git a/db/migrate/20200817200957_devise_create_admins.rb b/db/migrate/20200817200957_devise_create_admins.rb index e0c0b1a..66b3d4e 100644 --- a/db/migrate/20200817200957_devise_create_admins.rb +++ b/db/migrate/20200817200957_devise_create_admins.rb @@ -15,22 +15,22 @@ class DeviseCreateAdmins < ActiveRecord::Migration[6.0] 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.inet :current_sign_in_ip - # t.inet :last_sign_in_ip + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.inet :current_sign_in_ip + t.inet :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 + 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.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 @@ -38,7 +38,7 @@ class DeviseCreateAdmins < ActiveRecord::Migration[6.0] add_index :admins, :email, unique: true add_index :admins, :reset_password_token, unique: true - # add_index :admins, :confirmation_token, unique: true - # add_index :admins, :unlock_token, unique: true + add_index :admins, :confirmation_token, unique: true + add_index :admins, :unlock_token, unique: true end end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..16f4b1e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,4 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +admin = Admin.create([{email: 'admin@example.org', password: 'password'}]) \ No newline at end of file diff --git a/package.json b/package.json index 67c2d78..caf194d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@rails/activestorage": "^6.0.0", "@rails/ujs": "^6.0.0", "@rails/webpacker": "4.3.0", + "toastr": "^2.1.4", "turbolinks": "^5.2.0" }, "version": "0.1.0", diff --git a/ss-calculator.iml b/ss-calculator.iml index af03825..cc08a72 100644 --- a/ss-calculator.iml +++ b/ss-calculator.iml @@ -1,9 +1,34 @@ + + + + + + + + + - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb new file mode 100644 index 0000000..56c712a --- /dev/null +++ b/test/controllers/pages_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class PagesControllerTest < ActionDispatch::IntegrationTest + test "should get home" do + get pages_home_url + assert_response :success + end + +end diff --git a/yarn.lock b/yarn.lock index a4ce269..a198465 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1788,9 +1788,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111: - version "1.0.30001114" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001114.tgz#2e88119afb332ead5eaa330e332e951b1c4bfea9" - integrity sha512-ml/zTsfNBM+T1+mjglWRPgVsu2L76GAaADKX5f4t0pbhttEp0WMawJsHDYlFkVZkoA+89uvBRrVrEE4oqenzXQ== + version "1.0.30001115" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001115.tgz#c04cd828883ba47f6f776312e0817bcc9040cfa4" + integrity sha512-NZrG0439ePYna44lJX8evHX2L7Z3/z3qjVLnHgbBb/duNEnGo348u+BQS5o4HTWcrb++100dHFrU36IesIrC1Q== case-sensitive-paths-webpack-plugin@^2.2.0: version "2.3.0" @@ -2635,9 +2635,9 @@ ee-first@1.1.1: integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= electron-to-chromium@^1.3.523: - version "1.3.533" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.533.tgz#d7e5ca4d57e9bc99af87efbe13e7be5dde729b0f" - integrity sha512-YqAL+NXOzjBnpY+dcOKDlZybJDCOzgsq4koW3fvyty/ldTmsb4QazZpOWmVvZ2m0t5jbBf7L0lIGU3BUipwG+A== + version "1.3.534" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.534.tgz#fc7af8518dd00a5b22a24aed3f116b5d097e2330" + integrity sha512-7x2S3yUrspNHQOoPk+Eo+iHViSiJiEGPI6BpmLy1eT2KRNGCkBt/NUYqjfXLd1DpDCQp7n3+LfA1RkbG+LqTZQ== elliptic@^6.5.3: version "6.5.3" @@ -3991,6 +3991,11 @@ jest-worker@^25.4.0: merge-stream "^2.0.0" supports-color "^7.0.0" +jquery@>=1.12.0: + version "3.5.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.5.1.tgz#d7b4d08e1bfdb86ad2f1a3d039ea17304717abb5" + integrity sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg== + js-base64@^2.1.8: version "2.6.4" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.6.4.tgz#f4e686c5de1ea1f867dbcad3d46d969428df98c4" @@ -7058,6 +7063,13 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" +toastr@^2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/toastr/-/toastr-2.1.4.tgz#8b43be64fb9d0c414871446f2db8e8ca4e95f181" + integrity sha1-i0O+ZPudDEFIcURvLbjoyk6V8YE= + dependencies: + jquery ">=1.12.0" + toidentifier@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"