diff --git a/.env.example b/.env.example index 67cc0c9..89fb089 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,6 @@ DATABASE_USER=postgres DATABASE_PASSWORD=postgres DATABASE_HOST=localhost DATABASE_PORT=5432 + +GMAIL_SMTP_USER_NAME= +GMAIL_SMTP_APP_PASSWORD= \ No newline at end of file diff --git a/app/controllers/rents_controller.rb b/app/controllers/rents_controller.rb index bd57a49..77b9c5d 100644 --- a/app/controllers/rents_controller.rb +++ b/app/controllers/rents_controller.rb @@ -31,6 +31,7 @@ def create respond_to do |format| if @rent.save + RentMailer.with(rent: @rent).create_email.deliver_later format.html { redirect_to users_rents_url, notice: "Sikeres kölcsönzés." } format.json { render :show, status: :created, location: @rent } else diff --git a/app/mailers/previews/rent_mailer_preview.rb b/app/mailers/previews/rent_mailer_preview.rb new file mode 100644 index 0000000..6db03b7 --- /dev/null +++ b/app/mailers/previews/rent_mailer_preview.rb @@ -0,0 +1,6 @@ +class RentMailerPreview < ActionMailer::Preview + def create_email + @rent = params[:rent] + mail(to: User.first.mail, subject: 'Schörpong mail') + end +end diff --git a/app/mailers/rent_mailer.rb b/app/mailers/rent_mailer.rb new file mode 100644 index 0000000..4bba505 --- /dev/null +++ b/app/mailers/rent_mailer.rb @@ -0,0 +1,6 @@ +class RentMailer < ApplicationMailer + def create_email + @rent = params[:rent] + mail(to:'sepsi.laszlo99@gmail.com', subject: 'Schörpong mail') + end +end diff --git a/app/views/rent_mailer/create_email.html.erb b/app/views/rent_mailer/create_email.html.erb new file mode 100644 index 0000000..0462bdf --- /dev/null +++ b/app/views/rent_mailer/create_email.html.erb @@ -0,0 +1,44 @@ + + + + + + + +
+
+
+
+

Új feldolgozatlan eszközigénylés

+
+
+
+
+

Eszköz: <%= @rent.item.name %>

+
+
+
+
+

Kölcsönzés kezdete:

+
+
+

Kölcsönzés vége:

+
+
+
+
+

<%= @rent.begin.strftime("%Y-%m-%d %H:%M") %>

+
+
+

<%= @rent.end.strftime("%Y-%m-%d %H:%M") %>

+
+
+
+
+ <%= link_to "Részletek", rents_url, class:"ui red huge button" %> +
+
+
+
+ + diff --git a/config/application.rb b/config/application.rb index 5652589..4918248 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,6 +11,18 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 config.i18n.default_locale = :hu + routes.default_url_options[:host] = 'localhost:3001' + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: 'smtp.gmail.com', + port: 587, + domain: 'example.com', + user_name: ENV['GMAIL_SMTP_USER_NAME'], + password: ENV['GMAIL_SMTP_APP_PASSWORD'], + authentication: 'plain', + enable_starttls_auto: true, + open_timeout: 5, + read_timeout: 5 } # Configuration for the application, engines, and railties goes here. # diff --git a/config/environments/production.rb b/config/environments/production.rb index 5a067d5..a6ebb37 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -2,6 +2,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + routes.default_url_options[:host] = 'https://schorpong.sch.bme.hu/' # Code is not reloaded between requests. config.cache_classes = true diff --git a/test/mailers/previews/rent_mailer_preview.rb b/test/mailers/previews/rent_mailer_preview.rb new file mode 100644 index 0000000..0a71f39 --- /dev/null +++ b/test/mailers/previews/rent_mailer_preview.rb @@ -0,0 +1,7 @@ +# Preview all emails at http://localhost:3000/rails/mailers/rent_mailer +class RentMailerPreview < ActionMailer::Preview + def create_email + @rent = Rent.last + RentMailer.with(rent: @rent).create_email + end +end diff --git a/test/mailers/rent_mailer_test.rb b/test/mailers/rent_mailer_test.rb new file mode 100644 index 0000000..2077617 --- /dev/null +++ b/test/mailers/rent_mailer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RentMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end