diff --git a/Gemfile b/Gemfile
index 310cac9..e2d039a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -95,3 +95,4 @@ gem 'will_paginate', '~> 4.0', '>= 4.0.1'
gem 'carrierwave', '~> 3.0', '>= 3.0.7'
gem 'annotate', '~> 3.2'
+gem 'MailchimpTransactional', '~> 1.0', '>= 1.0.59'
diff --git a/Gemfile.lock b/Gemfile.lock
index 0c79200..35c2fde 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
+ MailchimpTransactional (1.0.59)
+ excon (>= 0.76.0, < 1)
+ json (~> 2.1, >= 2.1.0)
actioncable (7.0.4)
actionpack (= 7.0.4)
activesupport (= 7.0.4)
@@ -127,6 +130,7 @@ GEM
dotenv (= 2.8.1)
railties (>= 3.2)
erubi (1.12.0)
+ excon (0.112.0)
factory_bot (6.2.1)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
@@ -317,6 +321,7 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
+ MailchimpTransactional (~> 1.0, >= 1.0.59)
annotate (~> 3.2)
better_errors (~> 2.10, >= 2.10.1)
binding_of_caller (~> 1.0, >= 1.0.1)
diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb
new file mode 100644
index 0000000..0b04bde
--- /dev/null
+++ b/app/mailers/admin_mailer.rb
@@ -0,0 +1,34 @@
+class AdminMailer < ApplicationMailer
+ default from: 'no-reply@topgeardirect.com'
+
+ def new_user(user)
+ @user = user
+ mail(to: @user.email, subject: "New User: #{user.email}")
+ end
+
+ def mandrill_client
+ @mandrill_client ||= MailchimpTransactional::Client.new Rails.application.credentials.dig(:smtp, :api_key)
+ end
+
+ def new_comment(comment)
+ template_name = 'new-comment'
+ template_content = []
+ message = {
+ to: [{ email: 'omar@topgeardirect.com' }],
+ subject: "New Comment Added: #{comment.text}",
+ merge_vars: [
+ {
+ rcpt: 'omar@topgeardirect.com',
+ vars: [
+ {
+ name: 'COMMENT_NAME',
+ content: comment.text
+ }
+ ]
+ }
+ ]
+ }
+
+ mandrill_client.messages.send_template template_name, template_content, message
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1eb506b..2f73a5c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -32,6 +32,8 @@ class User < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i[slugged history finders]
+ after_create :send_welcome_email
+
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :posts, foreign_key: :author_id
@@ -48,4 +50,8 @@ def recent_three_posts
def is?(requested_role)
role == requested_role.to_s
end
+
+ def send_welcome_email
+ AdminMailer.new_user(self).deliver
+ end
end
diff --git a/app/views/admin_mailer/new_user.html.erb b/app/views/admin_mailer/new_user.html.erb
new file mode 100644
index 0000000..71e9ba9
--- /dev/null
+++ b/app/views/admin_mailer/new_user.html.erb
@@ -0,0 +1,6 @@
+
Welcome, <%= @user.email %>!
+Dear <%= @user.name %>,
+We are excited to have you join our community. Thank you for signing up!
+If you have any questions, feel free to reach out to us at support@topgeardirect.com.
+Best regards,
+The Team
\ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index fb48fca..2456aa0 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -11,6 +11,7 @@
+ <%= render "shared/navbar" %>
<%= notice %>
<%= alert %>
<%= yield %>
diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb
new file mode 100644
index 0000000..dfdb85e
--- /dev/null
+++ b/app/views/shared/_navbar.html.erb
@@ -0,0 +1,3 @@
+<% if user_signed_in? %>
+ <%= link_to 'Sign out', destroy_user_session_path, data: { turbo_method: :delete } %>
+<% end %>
\ No newline at end of file
diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc
index ff15a81..3cba966 100644
--- a/config/credentials.yml.enc
+++ b/config/credentials.yml.enc
@@ -1 +1 @@
-B5s7+BYCscIXqQowL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RpNQifIA==--zmXR3nXkpekjs4eT--AmeABzUYkvSaNJDHpg69Vw==
\ No newline at end of file
diff --git a/config/environments/development.rb b/config/environments/development.rb
index deeb82c..1d8e5df 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -37,15 +37,27 @@
config.active_storage.service = :local
# Set up mailer for development.
- config.action_mailer.delivery_method = :letter_opener
+ config.action_mailer.delivery_method = :smtp
+
+ config.action_mailer.smtp_settings = {
+ address: Rails.application.credentials.dig(:smtp, :address),
+ port: Rails.application.credentials.dig(:smtp, :port),
+ domain: Rails.application.credentials.dig(:smtp, :domain),
+ user_name: Rails.application.credentials.dig(:smtp, :username),
+ password: Rails.application.credentials.dig(:smtp, :api_key),
+ authentication: "login",
+ enable_starttls_auto: true
+ }
+
+ config.action_mailer.default charset: "utf-8"
# Don't care if the mailer can't send.
- config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Set up default URL options for the Devise mailer in each environment.
- config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 598468e..303b3c2 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -24,7 +24,8 @@
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
- config.mailer_sender = 'contact@ovatec.com'
+ config.mailer_sender = 'Omar at Owatec '
+ config.parent_mailer = 'ActionMailer::Base'
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
@@ -263,7 +264,7 @@
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
- # config.navigational_formats = ['*/*', :html]
+ config.navigational_formats = ['*/*', :html, :turbo_stream]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
diff --git a/config/routes.rb b/config/routes.rb
index 614b616..ed28d3e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -10,6 +10,6 @@
resources :likes, only: [:create]
end
end
-
+
root "users#index"
end
diff --git a/spec/mailers/admin_mailer_spec.rb b/spec/mailers/admin_mailer_spec.rb
new file mode 100644
index 0000000..b28ea3c
--- /dev/null
+++ b/spec/mailers/admin_mailer_spec.rb
@@ -0,0 +1,5 @@
+require "rails_helper"
+
+RSpec.describe AdminMailer, type: :mailer do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/mailers/previews/admin_mailer_preview.rb b/spec/mailers/previews/admin_mailer_preview.rb
new file mode 100644
index 0000000..73ea1b7
--- /dev/null
+++ b/spec/mailers/previews/admin_mailer_preview.rb
@@ -0,0 +1,4 @@
+# Preview all emails at http://localhost:3000/rails/mailers/admin_mailer
+class AdminMailerPreview < ActionMailer::Preview
+
+end