Skip to content

Instantly share code, notes, and snippets.

@davidmaogomezz
Last active September 9, 2020 22:02
Show Gist options
  • Save davidmaogomezz/7598725248dd490ed5c07a7bd79561a2 to your computer and use it in GitHub Desktop.
Save davidmaogomezz/7598725248dd490ed5c07a7bd79561a2 to your computer and use it in GitHub Desktop.
Send emails
emails = []
emails.each do |email|
@user = User.find_by_email(email)
@password = (0...8).map { [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten[rand([('a'..'z'), ('A'..'Z')].map(&:to_a).flatten.length)] }.join
@user.password = @password
@user.password_confirmation = @password
raw, hashed = Devise.token_generator.generate(User, :reset_password_token)
@user.reset_password_token = hashed
@user.reset_password_sent_at = Time.now.utc
@url = Utils::GetUrlEnv.call(@user)
@url_reset = "#{@url}#{Utils::PathResetPassword.call(@user)}?reset_password_token=#{raw}&email=#{@user.email}"
@url = "#{@url}#{Utils::PathSignIn.call(@user)}"
if @user.present?
UserMailer.welcome_email(@user, @url, @url_reset, @password).deliver_now
else
puts "No existe user con email #{email}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment