asciinema.org/app/services/email_login_service.rb

22 lines
453 B
Ruby
Raw Normal View History

2014-10-12 18:36:31 +00:00
class EmailLoginService
def login(email)
user = User.for_email!(email)
expiring_token = ExpiringToken.create_for_user(user)
Notifications.delay_login_request(expiring_token.user_id, expiring_token.token)
true
rescue User::InvalidEmailError
false
end
def validate(token)
expiring_token = ExpiringToken.active_for_token(token)
if expiring_token
expiring_token.use!
expiring_token.user
end
end
end