Last active
February 6, 2019 18:06
-
-
Save kopylovvlad/119c8bbe4d90700b4d560b45a3ba2b95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ForgottenPasswordService | |
def initialize(user_email) | |
@user_email = user_email | |
@user = nil | |
end | |
def perform | |
find_user && generate_token && send_email | |
end | |
private | |
def find_user | |
@user = User.find_by(email: @user_email) | |
@user.present? | |
end | |
def generate_token | |
@user.update_attributes(token: TokenGenerator.generate) | |
end | |
def send_email | |
UserMailer.password_reset(@user.email, @user.token) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment