* Move emails from users table to email_addresses table. * Validate that addresses are formatted correctly and are unique across users. Existing invalid emails are grandfathered in. * Add is_verified flag (the address has been confirmed by the user). * Add is_deliverable flag (an undeliverable address is an address that bounces). * Normalize addresses to prevent registering multiple accounts with the same email address (using tricks like Gmail's plus addressing).
18 lines
394 B
Ruby
18 lines
394 B
Ruby
class UserEmailChange
|
|
attr_reader :user, :password, :new_email
|
|
|
|
def initialize(user, new_email, password)
|
|
@user = user
|
|
@new_email = new_email
|
|
@password = password
|
|
end
|
|
|
|
def process
|
|
if User.authenticate(user.name, password)
|
|
user.update(email_address_attributes: { address: new_email })
|
|
else
|
|
user.errors[:base] << "Password was incorrect"
|
|
end
|
|
end
|
|
end
|