Commit 50e73145 authored by Benjamin Neff's avatar Benjamin Neff Committed by Dennis Schubert

Cleanup invalid unconfirmed emails

Also remove confirm_email_token when unconfirmed_email is removed.

Fixes #7048

closes #7051
parent 4d51c024
......@@ -466,7 +466,7 @@ class User < ActiveRecord::Base
# Whenever email is set, clear all unconfirmed emails which match
def remove_invalid_unconfirmed_emails
User.where(unconfirmed_email: email).update_all(unconfirmed_email: nil) if email_changed?
User.where(unconfirmed_email: email).update_all(unconfirmed_email: nil, confirm_email_token: nil) if email_changed?
end
# Generate public/private keys for User and associated Person
......
class RemoveInvalidUnconfirmedEmails < ActiveRecord::Migration
class User < ActiveRecord::Base
end
def up
User.joins("INNER JOIN users as valid_user ON users.unconfirmed_email = valid_user.email")
.where("users.id != valid_user.id").update_all(unconfirmed_email: nil, confirm_email_token: nil)
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160901072443) do
ActiveRecord::Schema.define(version: 20160902180630) do
create_table "account_deletions", force: :cascade do |t|
t.string "diaspora_handle", limit: 255
......
......@@ -306,11 +306,12 @@ describe User, :type => :model do
expect(alice).not_to be_valid
end
it "resets a matching unconfirmed_email on save" do
eve.update_attribute :unconfirmed_email, "new@example.com"
alice.update_attribute :email, "new@example.com"
it "resets a matching unconfirmed_email and confirm_email_token on save" do
eve.update_attributes(unconfirmed_email: "new@example.com", confirm_email_token: SecureRandom.hex(15))
alice.update_attribute(:email, "new@example.com")
eve.reload
expect(eve.unconfirmed_email).to eql(nil)
expect(eve.confirm_email_token).to eql(nil)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment