diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 00000000..97fa8997 --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,9 @@ +class Users + class ConfirmationsController < Devise::ConfirmationsController + private + + def after_confirmation_path_for(*) + root_path + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 98891b7a..8974dc87 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,9 @@ # Table name: users # # id :integer not null, primary key +# confirmation_sent_at :datetime +# confirmation_token :string +# confirmed_at :datetime # current_sign_in_at :datetime # current_sign_in_ip :string # email :string default(""), not null @@ -16,11 +19,13 @@ # role :string # sign_in_count :integer default(0), not null # uid :string +# unconfirmed_email :string # created_at :datetime not null # updated_at :datetime not null # # Indexes # +# index_users_on_confirmation_token (confirmation_token) UNIQUE # index_users_on_email (email) UNIQUE # index_users_on_reset_password_token (reset_password_token) UNIQUE # @@ -28,9 +33,15 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :omniauthable, omniauth_providers: [:hpiopenid] + devise :database_authenticatable, + :registerable, + :recoverable, + :rememberable, + :trackable, + :validatable, + :omniauthable, + :confirmable, + omniauth_providers: [:hpiopenid] has_one :profile has_many :agreement_letters diff --git a/app/views/users/index.html.erb b/app/views/devise/index.html.erb similarity index 100% rename from app/views/users/index.html.erb rename to app/views/devise/index.html.erb diff --git a/app/views/users/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb similarity index 100% rename from app/views/users/sessions/new.html.erb rename to app/views/devise/sessions/new.html.erb diff --git a/config/environments/test.rb b/config/environments/test.rb index 30587ef6..c8fa89db 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -34,6 +34,8 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 20b01c26..f689ef71 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -127,7 +127,7 @@ # 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 = 7.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 @@ -220,7 +220,7 @@ # 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 = true + 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). diff --git a/config/routes.rb b/config/routes.rb index d986d8a7..1eee3d10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,7 +41,8 @@ end devise_for :users, :controllers => { :registrations => "users/registrations", - :omniauth_callbacks => "users/omniauth_callbacks" + :omniauth_callbacks => "users/omniauth_callbacks", + :confirmations => "users/confirmations" } resources :users, only: [:index] # index page for devise users patch 'users/:id/role' => 'users#update_role', as: :update_user_role diff --git a/db/migrate/20180602123530_add_confirmable_to_devise.rb b/db/migrate/20180602123530_add_confirmable_to_devise.rb new file mode 100644 index 00000000..ec0500e6 --- /dev/null +++ b/db/migrate/20180602123530_add_confirmable_to_devise.rb @@ -0,0 +1,15 @@ +class AddConfirmableToDevise < ActiveRecord::Migration[5.1] + def up + add_column :users, :confirmation_token, :string + add_column :users, :confirmed_at, :datetime + add_column :users, :confirmation_sent_at, :datetime + add_column :users, :unconfirmed_email, :string + add_index :users, :confirmation_token, unique: true + User.all.update_all confirmed_at: DateTime.now + end + + def down + remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at + remove_columns :users, :unconfirmed_email + end +end diff --git a/db/schema.rb b/db/schema.rb index d3959f9c..456902fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180511192952) do +ActiveRecord::Schema.define(version: 20180602123530) do create_table "agreement_letters", force: :cascade do |t| t.integer "user_id", null: false @@ -148,6 +148,11 @@ t.string "role" t.string "provider" t.string "uid" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake index edb0a0da..4eaa8503 100644 --- a/lib/tasks/auto_annotate_models.rake +++ b/lib/tasks/auto_annotate_models.rake @@ -14,7 +14,7 @@ if Rails.env.development? 'position_in_fixture' => 'before', 'position_in_factory' => 'before', 'position_in_serializer' => 'before', - 'show_foreign_keys' => 'true', + 'show_foreign_keys' => 'false', 'show_complete_foreign_keys' => 'false', 'show_indexes' => 'true', 'simple_indexes' => 'false', diff --git a/spec/factories/users.rb b/spec/factories/users.rb index c30f9d2d..a58be6dc 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -3,6 +3,9 @@ # Table name: users # # id :integer not null, primary key +# confirmation_sent_at :datetime +# confirmation_token :string +# confirmed_at :datetime # current_sign_in_at :datetime # current_sign_in_ip :string # email :string default(""), not null @@ -16,11 +19,13 @@ # role :string # sign_in_count :integer default(0), not null # uid :string +# unconfirmed_email :string # created_at :datetime not null # updated_at :datetime not null # # Indexes # +# index_users_on_confirmation_token (confirmation_token) UNIQUE # index_users_on_email (email) UNIQUE # index_users_on_reset_password_token (reset_password_token) UNIQUE # @@ -30,6 +35,7 @@ sequence(:email) { |n| "test@example#{n}.com" } password "test123" role :pupil + confirmed_at Time.now factory :user_with_profile do after(:build) do |user| build(:profile, user: user) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index aaea84f5..abdf61e6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3,6 +3,9 @@ # Table name: users # # id :integer not null, primary key +# confirmation_sent_at :datetime +# confirmation_token :string +# confirmed_at :datetime # current_sign_in_at :datetime # current_sign_in_ip :string # email :string default(""), not null @@ -16,11 +19,13 @@ # role :string # sign_in_count :integer default(0), not null # uid :string +# unconfirmed_email :string # created_at :datetime not null # updated_at :datetime not null # # Indexes # +# index_users_on_confirmation_token (confirmation_token) UNIQUE # index_users_on_email (email) UNIQUE # index_users_on_reset_password_token (reset_password_token) UNIQUE #