Skip to content

Commit

Permalink
Add confirmation mail while sign up (ifmeorg#1958)
Browse files Browse the repository at this point in the history
* Add confirmation mail while sign up

* Add confirmed_at inside factories

* Skip email confirmation while using omniauth

* Skip email confirmation while using omniauth

* Skip email confirmation while using omniauth

Co-authored-by: revathyn <revathyn@qburst.com>
  • Loading branch information
Revathyne and Revathynaduvil authored Feb 18, 2021
1 parent 2bff3cd commit 3b96393
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def upload_avatar(omniauth_avatar)

user.third_party_avatar = omniauth_avatar
user.remote_avatar_url = omniauth_avatar
user.skip_confirmation!
user.save!
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class User < ApplicationRecord
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :invitable, :database_authenticatable, :registerable, :uid, :lockable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
omniauth_providers: %i[google_oauth2 facebook]
:confirmable, omniauth_providers: %i[google_oauth2 facebook]
# https://github.com/michaelbanfield/devise-pwned_password#disabling-in-test-environments
# TODO: reenable if we disable real network requests & stub them with Webmock
# https://github.com/bblimke/webmock
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20210212112419_add_confirmable_to_devise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AddConfirmableToDevise < ActiveRecord::Migration[6.0]
def self.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
end
def self.down
remove_index :users, :confirmation_token

remove_column :users, :unconfirmed_email
remove_column :users, :confirmation_sent_at
remove_column :users, :confirmed_at
remove_column :users, :confirmation_token
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: 2020_10_19_231628) do
ActiveRecord::Schema.define(version: 2021_02_12_112419) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -296,6 +296,11 @@
t.text "third_party_avatar"
t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at"
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 ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["invitations_count"], name: "index_users_on_invitations_count"
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@
sequence(:email) { |n| "some-email#{n}@ifme.org" }
sequence(:name) { |n| "Some Person#{n}" }
password { 'passworD%1' }
confirmed_at { Time.zone.now }
end

factory :user1, class: User do
name { 'Oprah Chang' }
sequence(:email) { |n| "oprah.chang#{n}@example.com" }
password { 'passworD%1' }
confirmed_at { Time.zone.now }
location { 'Toronto, ON, Canada' }
end

factory :user2, class: User do
name { 'Plum Blossom' }
email { 'plum.blossom@example.com' }
password { 'passworD%1' }
confirmed_at { Time.zone.now }
location { 'Toronto, ON, Canada' }

trait :with_allies do
Expand All @@ -81,13 +84,15 @@
name { 'Gentle Breezy' }
email { 'gentle.breezy@example.com' }
password { 'passworD%1' }
confirmed_at { Time.zone.now }
location { 'Toronto, ON, Canada' }
end

factory :user_oauth, class: User do
name { 'Orange Southland' }
email { 'orange.southland@example.com' }
password { 'passworD%1' }
confirmed_at { Time.zone.now }
location { 'Toronto, ON, Canada' }
token { 'has_a_token' }
access_expires_at { Time.zone.now + 600 }
Expand Down

0 comments on commit 3b96393

Please sign in to comment.