Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add email verification with devise, fixes #639 #708

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/controllers/users/confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Users
class ConfirmationsController < Devise::ConfirmationsController
private

def after_confirmation_path_for(*)
root_path
end
end
end
17 changes: 14 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,21 +19,29 @@
# 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
#

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
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20180602123530_add_confirmable_to_devise.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corinnaj could you revert these changes by switching to sqlite and running migrations? This should rewrite this file.


create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down