From aee2bce91d5dfcb4eb6ef9754b4e0ee95ebc47ea Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Thu, 24 Jan 2019 20:39:21 -0700 Subject: [PATCH 1/7] set up rails active mailer in the backend --- Gemfile | 1 + Gemfile.lock | 8 ++++++ app/controllers/api/users_controller.rb | 19 +++++++------ app/mailers/application_mailer.rb | 2 +- app/mailers/user_mailer.rb | 9 +++++++ app/models/user.rb | 3 +++ app/views/user_mailer/welcome_email.html.erb | 17 ++++++++++++ app/views/user_mailer/welcome_email.text.erb | 5 ++++ client/src/providers/AuthProvider.js | 10 +++---- config/environments/development.rb | 28 +++++++++++++++++--- config/environments/production.rb | 12 +++++---- config/environments/test.rb | 5 ++-- test/mailers/previews/user_mailer_preview.rb | 4 +++ test/mailers/user_mailer_test.rb | 7 +++++ 14 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 app/mailers/user_mailer.rb create mode 100644 app/views/user_mailer/welcome_email.html.erb create mode 100644 app/views/user_mailer/welcome_email.text.erb create mode 100644 test/mailers/previews/user_mailer_preview.rb create mode 100644 test/mailers/user_mailer_test.rb diff --git a/Gemfile b/Gemfile index 1d3a60e..6a44d74 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ group :development do gem 'listen', '>= 3.0.5', '< 3.2' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'letter_opener' end diff --git a/Gemfile.lock b/Gemfile.lock index 46bd15b..d26664e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.6.0) + public_suffix (>= 2.0.2, < 4.0) arel (9.0.0) aws_cf_signer (0.1.3) bcrypt (3.1.12) @@ -79,6 +81,10 @@ GEM domain_name (~> 0.5) i18n (1.5.1) concurrent-ruby (~> 1.0) + launchy (2.4.3) + addressable (~> 2.3) + letter_opener (1.7.0) + launchy (~> 2.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -108,6 +114,7 @@ GEM pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) + public_suffix (3.0.3) puma (3.12.0) rack (2.0.6) rack-test (1.1.0) @@ -182,6 +189,7 @@ DEPENDENCIES devise_token_auth dotenv-rails faker + letter_opener listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) pry diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index 4a9f527..0e5e4ef 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -11,15 +11,15 @@ def show end def create - user = User.new(user_params) - if user.save + @user = User.new(user_params) + if @user.save render json: user else render json: user.errors, status: 422 end end - def update + def update user = User.find(params[:id]) user.email = params[:email] ? params[:email] : user.email user.first_name = params[:first_name] ? params[:first_name] : user.first_name @@ -30,27 +30,26 @@ def update user.college_degree = params[:college_degree] ? params[:college_degree] : user.college_degree user.employment_status = params[:employment_status] ? params[:employment_status] : user.employment_status user.sex = params[:sex] ? params[:sex] : user.sex - user.github = params[:github] ? params[:github] : user.github + user.github = params[:github] ? params[:github] : user.github user.linkedin = params[:linkedin] ? params[:linkedin] : user.linkedin user.resume = params[:resume] ? params[:resume] : user.resume file = params[:file] - + if file != "undefined" begin ext = File.extname(file.tempfile) cloud_image = Cloudinary::Uploader.upload(file, public_id: file.original_filename, secure: true) - user.image = cloud_image['secure_url'] + user.image = cloud_image["secure_url"] rescue => e - render json: { errors: e }, status: 422 + render json: {errors: e}, status: 422 end end - + if user.save render json: user else - render json: { errors: user.errors.full_messages }, status: 422 + render json: {errors: user.errors.full_messages}, status: 422 end - end def destroy diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..75e4e4d 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: 'DevTrackerW18@gmail.com' layout 'mailer' end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb new file mode 100644 index 0000000..71eae7a --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -0,0 +1,9 @@ +class UserMailer < ApplicationMailer + default from: "notifications@example.com" + + def welcome_email(user) + @user = params[:user] + @url = "https://dev-tracker19.herokuapp.com/login" + mail(to: @user.email, subject: "Welcome to DevTracker!") + end +end diff --git a/app/models/user.rb b/app/models/user.rb index f9efae7..8b15e65 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,4 +10,7 @@ class User < ActiveRecord::Base has_many :applications, dependent: :destroy has_many :companies, through: :applications has_many :todos, dependent: :destroy + after_create do + UserMailer.welcome_email(@user).deliver_now + end end diff --git a/app/views/user_mailer/welcome_email.html.erb b/app/views/user_mailer/welcome_email.html.erb new file mode 100644 index 0000000..8832fca --- /dev/null +++ b/app/views/user_mailer/welcome_email.html.erb @@ -0,0 +1,17 @@ + + + + + + +

Welcome to https://dev-tracker19.herokuapp.com/, <%= @user.email %>

+

+ You have successfully signed up to dev-tracker19.herokuapp.com, + your username is: <%= @user.email %>.
+

+

+ To login to the site, just follow this link: <%= @https://dev-tracker19.herokuapp.com/login %>. +

+

Thanks for joining and have a great day!

+ + \ No newline at end of file diff --git a/app/views/user_mailer/welcome_email.text.erb b/app/views/user_mailer/welcome_email.text.erb new file mode 100644 index 0000000..33a8f50 --- /dev/null +++ b/app/views/user_mailer/welcome_email.text.erb @@ -0,0 +1,5 @@ +Welcome to example.com, <%= @user.email %> +=============================================== +You have successfully signed up to example.com, +your username is: <%= @user.email %>. +Thanks for joining and have a great day! \ No newline at end of file diff --git a/client/src/providers/AuthProvider.js b/client/src/providers/AuthProvider.js index d152e3a..02865c9 100644 --- a/client/src/providers/AuthProvider.js +++ b/client/src/providers/AuthProvider.js @@ -25,15 +25,15 @@ class AuthProvider extends React.Component { axios .put( `/api/users/${id}?email=${user.email}&first_name=${ - user.first_name + user.first_name }&last_name=${user.last_name}&image=${user.image}&cohort=${ - user.cohort + user.cohort }&dob=${user.dob}&college_degree=${ - user.college_degree + user.college_degree }&employment_status=${user.employment_status}&sex=${ - user.sex + user.sex }&github=${user.github}&linkedin=${user.linkedin}&resume=${ - user.resume + user.resume }`, data ) diff --git a/config/environments/development.rb b/config/environments/development.rb index d52ec9e..c70c40d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,12 +14,12 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}", } else config.action_controller.perform_caching = false @@ -31,7 +31,7 @@ config.active_storage.service = :local # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_caching = false @@ -44,6 +44,28 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + config.action_mailer.delivery_method = :sendmail + # Defaults to: + # config.action_mailer.sendmail_settings = { + # location: '/usr/sbin/sendmail', + # arguments: '-i' + # } + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "https://dev-tracker19.herokuapp.com/login", + user_name: "DevTrackerW18@gmail.com", + password: "dtrackw18", + authentication: "plain", + enable_starttls_auto: true, + } + + config.active_job.queue_adapter = :inline # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 801bed4..902c5ab 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,6 +1,8 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + config.active_job.queue_adapter = :async + # Code is not reloaded between requests. config.cache_classes = true @@ -11,7 +13,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] @@ -20,7 +22,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -45,7 +47,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -75,9 +77,9 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/config/environments/test.rb b/config/environments/test.rb index 0a38fd3..8a91fd9 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -15,11 +15,11 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}", } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates. @@ -37,6 +37,7 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + config.active_job.queue_adapter = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/test/mailers/previews/user_mailer_preview.rb b/test/mailers/previews/user_mailer_preview.rb new file mode 100644 index 0000000..957e12b --- /dev/null +++ b/test/mailers/previews/user_mailer_preview.rb @@ -0,0 +1,4 @@ +# Preview all emails at http://localhost:3000/rails/mailers/user_mailer +class UserMailerPreview < ActionMailer::Preview + +end diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb new file mode 100644 index 0000000..67a1629 --- /dev/null +++ b/test/mailers/user_mailer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserMailerTest < ActionMailer::TestCase + # test "the truth" do + # assert true + # end +end From 5c29b1ecc17b95de68b7cdc20bb1db6bef72e14b Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Sat, 26 Jan 2019 19:28:39 -0700 Subject: [PATCH 2/7] continue work on user and todo mailer --- app/controllers/api/todos_controller.rb | 5 ++- app/mailers/todo_mailer.rb | 9 +++++ app/mailers/user_mailer.rb | 4 +- app/models/user.rb | 5 ++- app/views/user_mailer/todos_email.html.erb | 10 +++++ app/views/user_mailer/todos_email.text.erb | 3 ++ app/views/user_mailer/welcome_email.html.erb | 2 +- app/views/user_mailer/welcome_email.text.erb | 4 +- config/environments/development.rb | 41 +++++++++++--------- config/environments/production.rb | 18 +++++++++ 10 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 app/mailers/todo_mailer.rb create mode 100644 app/views/user_mailer/todos_email.html.erb create mode 100644 app/views/user_mailer/todos_email.text.erb diff --git a/app/controllers/api/todos_controller.rb b/app/controllers/api/todos_controller.rb index a3f8dbb..1e263cd 100644 --- a/app/controllers/api/todos_controller.rb +++ b/app/controllers/api/todos_controller.rb @@ -10,9 +10,10 @@ def show end def create - todo = current_user.todos.new(todo_params) + @todo = current_user.todos.new(todo_params) - if todo.save + if @todo.save + TodosMailer.todo_email(@todo).deliver_now render json: todo else render json: todo.errors, status: 422 diff --git a/app/mailers/todo_mailer.rb b/app/mailers/todo_mailer.rb new file mode 100644 index 0000000..b1313b3 --- /dev/null +++ b/app/mailers/todo_mailer.rb @@ -0,0 +1,9 @@ +class TodoMailer < ApplicationMailer + default from: "DevTrackerW18@gmail.com" + + def todo_email(user, todo) + @todo = todo + @url = "https://dev-tracker19.herokuapp.com/login" + mail(to: @user.email, subject: "Todo was added.") + end +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 71eae7a..854077a 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,8 +1,8 @@ class UserMailer < ApplicationMailer - default from: "notifications@example.com" + default from: "DevTrackerW18@gmail.com" def welcome_email(user) - @user = params[:user] + @user = user @url = "https://dev-tracker19.herokuapp.com/login" mail(to: @user.email, subject: "Welcome to DevTracker!") end diff --git a/app/models/user.rb b/app/models/user.rb index 8b15e65..a988d8e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,13 +4,14 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, :confirmable include DeviseTokenAuth::Concerns::User has_many :contacts, dependent: :destroy has_many :applications, dependent: :destroy has_many :companies, through: :applications has_many :todos, dependent: :destroy + after_create do - UserMailer.welcome_email(@user).deliver_now + UserMailer.welcome_email(self).deliver_now end end diff --git a/app/views/user_mailer/todos_email.html.erb b/app/views/user_mailer/todos_email.html.erb new file mode 100644 index 0000000..8ddb525 --- /dev/null +++ b/app/views/user_mailer/todos_email.html.erb @@ -0,0 +1,10 @@ + + + + + + +

You created a new Todo, <%= @user.email %>

+

Have a great day!

+ + \ No newline at end of file diff --git a/app/views/user_mailer/todos_email.text.erb b/app/views/user_mailer/todos_email.text.erb new file mode 100644 index 0000000..970b3a1 --- /dev/null +++ b/app/views/user_mailer/todos_email.text.erb @@ -0,0 +1,3 @@ +You created a new Todo, <%= @user.email %> +=============================================== +Have a great day! \ No newline at end of file diff --git a/app/views/user_mailer/welcome_email.html.erb b/app/views/user_mailer/welcome_email.html.erb index 8832fca..782a684 100644 --- a/app/views/user_mailer/welcome_email.html.erb +++ b/app/views/user_mailer/welcome_email.html.erb @@ -10,7 +10,7 @@ your username is: <%= @user.email %>.

- To login to the site, just follow this link: <%= @https://dev-tracker19.herokuapp.com/login %>. + To login to the site, just follow this link: https://dev-tracker19.herokuapp.com/login

Thanks for joining and have a great day!

diff --git a/app/views/user_mailer/welcome_email.text.erb b/app/views/user_mailer/welcome_email.text.erb index 33a8f50..278749c 100644 --- a/app/views/user_mailer/welcome_email.text.erb +++ b/app/views/user_mailer/welcome_email.text.erb @@ -1,5 +1,5 @@ -Welcome to example.com, <%= @user.email %> +Welcome to https://dev-tracker19.herokuapp.com/login, <%= @user.email %> =============================================== -You have successfully signed up to example.com, +You have successfully signed up to https://dev-tracker19.herokuapp.com/login, your username is: <%= @user.email %>. Thanks for joining and have a great day! \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index c70c40d..ac93a13 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,26 +44,29 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - config.action_mailer.delivery_method = :sendmail - # Defaults to: - # config.action_mailer.sendmail_settings = { - # location: '/usr/sbin/sendmail', - # arguments: '-i' + # gmail + + # config.action_mailer.delivery_method = :sendmail + # # Defaults to: config.action_mailer.sendmail_settings = { + # # location: "/usr/sbin/sendmail", + # # arguments: "-i", + # # } + # config.action_mailer.perform_deliveries = true + # config.action_mailer.raise_delivery_errors = true + # config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + # config.action_mailer.delivery_method = :smtp + # config.action_mailer.smtp_settings = { + # address: "smtp.gmail.com", + # port: 587, + # domain: "https://dev-tracker19.herokuapp.com/login", + # user_name: "DevTrackerW18", + # # user_name: "DevTrackerW18@gmail.com", + # password: "dtrackw18", + # authentication: "plain", + # enable_starttls_auto: true, # } - config.action_mailer.perform_deliveries = true - config.action_mailer.raise_delivery_errors = true - config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} - - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", - port: 587, - domain: "https://dev-tracker19.herokuapp.com/login", - user_name: "DevTrackerW18@gmail.com", - password: "dtrackw18", - authentication: "plain", - enable_starttls_auto: true, - } + + config.action_mailer.delivery_method = :letter_opener config.active_job.queue_adapter = :inline diff --git a/config/environments/production.rb b/config/environments/production.rb index 902c5ab..4cf3dbd 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -5,6 +5,24 @@ # Code is not reloaded between requests. config.cache_classes = true + config.action_mailer.delivery_method = :sendmail + # Defaults to: config.action_mailer.sendmail_settings = { + # location: "/usr/sbin/sendmail", + # arguments: "-i", + # } + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "https://dev-tracker19.herokuapp.com/login", + user_name: "DevTrackerW18", + password: "dtrackw18", + authentication: "plain", + enable_starttls_auto: true, + } # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers From 8f952660a3fab66f56756fa79cda79bb34b3150d Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Sat, 26 Jan 2019 19:43:05 -0700 Subject: [PATCH 3/7] bring back the gmail code in development.rb --- config/environments/development.rb | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index ac93a13..cbca2ba 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -46,25 +46,25 @@ # gmail - # config.action_mailer.delivery_method = :sendmail - # # Defaults to: config.action_mailer.sendmail_settings = { - # # location: "/usr/sbin/sendmail", - # # arguments: "-i", - # # } - # config.action_mailer.perform_deliveries = true - # config.action_mailer.raise_delivery_errors = true - # config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} - # config.action_mailer.delivery_method = :smtp - # config.action_mailer.smtp_settings = { - # address: "smtp.gmail.com", - # port: 587, - # domain: "https://dev-tracker19.herokuapp.com/login", - # user_name: "DevTrackerW18", - # # user_name: "DevTrackerW18@gmail.com", - # password: "dtrackw18", - # authentication: "plain", - # enable_starttls_auto: true, + config.action_mailer.delivery_method = :sendmail + # Defaults to: config.action_mailer.sendmail_settings = { + # location: "/usr/sbin/sendmail", + # arguments: "-i", # } + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "https://dev-tracker19.herokuapp.com/login", + user_name: "DevTrackerW18", + # user_name: "DevTrackerW18@gmail.com", + password: "dtrackw18", + authentication: "plain", + enable_starttls_auto: true, + } config.action_mailer.delivery_method = :letter_opener From 010077b8d7c490c506911fe5c9198c6c2e4c817b Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Sat, 26 Jan 2019 20:31:31 -0700 Subject: [PATCH 4/7] add figaro gem --- .gitignore | 3 +++ Gemfile | 1 + Gemfile.lock | 3 +++ config/environments/development.rb | 17 ++++++++--------- config/environments/production.rb | 16 ++++++++-------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 46d61a0..feeb44e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Ignore application configuration +/config/application.yml diff --git a/Gemfile b/Gemfile index 6a44d74..0b4d8ec 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ group :development, :test do gem 'pry' gem 'faker' gem 'dotenv-rails' + gem 'figaro' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index d26664e..2dd420e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,8 @@ GEM faker (1.9.1) i18n (>= 0.7) ffi (1.9.25) + figaro (1.1.1) + thor (~> 0.14) globalid (0.4.1) activesupport (>= 4.2.0) http-cookie (1.0.3) @@ -189,6 +191,7 @@ DEPENDENCIES devise_token_auth dotenv-rails faker + figaro letter_opener listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) diff --git a/config/environments/development.rb b/config/environments/development.rb index cbca2ba..4b94dec 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -53,17 +53,16 @@ # } config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true - config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + config.action_mailer.default_options = {from: "DevTrackerW18@gmail.com"} config.action_mailer.delivery_method = :smtp + # SMTP settings for gmail config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", - port: 587, - domain: "https://dev-tracker19.herokuapp.com/login", - user_name: "DevTrackerW18", - # user_name: "DevTrackerW18@gmail.com", - password: "dtrackw18", - authentication: "plain", - enable_starttls_auto: true, + :address => "smtp.gmail.com", + :port => 587, + :user_name => ENV["gmail_username"], + :password => ENV["gmail_password"], + :authentication => "plain", + :enable_starttls_auto => true, } config.action_mailer.delivery_method = :letter_opener diff --git a/config/environments/production.rb b/config/environments/production.rb index 4cf3dbd..0f7f22a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -12,16 +12,16 @@ # } config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true - config.action_mailer.default_options = {from: "DevTrackerW18@example.com"} + config.action_mailer.default_options = {from: "DevTrackerW18@gmail.com"} config.action_mailer.delivery_method = :smtp + # SMTP settings for gmail config.action_mailer.smtp_settings = { - address: "smtp.gmail.com", - port: 587, - domain: "https://dev-tracker19.herokuapp.com/login", - user_name: "DevTrackerW18", - password: "dtrackw18", - authentication: "plain", - enable_starttls_auto: true, + :address => "smtp.gmail.com", + :port => 587, + :user_name => ENV["gmail_username"], + :password => ENV["gmail_password"], + :authentication => "plain", + :enable_starttls_auto => true, } # Eager load code on boot. This eager loads most of Rails and From 8f4b657fbac15a92f73b0b929fa0e2b6b2b306c4 Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Mon, 28 Jan 2019 11:44:38 -0700 Subject: [PATCH 5/7] ensure letter_opener is included --- app/controllers/api/todos_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/todos_controller.rb b/app/controllers/api/todos_controller.rb index 1e263cd..d31a539 100644 --- a/app/controllers/api/todos_controller.rb +++ b/app/controllers/api/todos_controller.rb @@ -13,7 +13,7 @@ def create @todo = current_user.todos.new(todo_params) if @todo.save - TodosMailer.todo_email(@todo).deliver_now + TodosMailer.todo_email(@todo, @user).deliver_now render json: todo else render json: todo.errors, status: 422 From 367de98a2e52966a4dfc2f33d0c0b3489662c600 Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Mon, 28 Jan 2019 13:57:22 -0700 Subject: [PATCH 6/7] rails mailers functional with letter_opener on user account creation/sign-up --- app/controllers/api/users_controller.rb | 1 + app/models/user.rb | 3 +- client/src/components/Auth/RegisterForm.js | 32 +++++++++++----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index 0e5e4ef..5a6304f 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -11,6 +11,7 @@ def show end def create + binding.pry @user = User.new(user_params) if @user.save render json: user diff --git a/app/models/user.rb b/app/models/user.rb index a988d8e..bd0d5ea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, :confirmable + :recoverable, :rememberable, :trackable, :validatable include DeviseTokenAuth::Concerns::User has_many :contacts, dependent: :destroy has_many :applications, dependent: :destroy @@ -12,6 +12,7 @@ class User < ActiveRecord::Base has_many :todos, dependent: :destroy after_create do + binding.pry UserMailer.welcome_email(self).deliver_now end end diff --git a/client/src/components/Auth/RegisterForm.js b/client/src/components/Auth/RegisterForm.js index aeb98e0..7253bc1 100644 --- a/client/src/components/Auth/RegisterForm.js +++ b/client/src/components/Auth/RegisterForm.js @@ -25,7 +25,7 @@ class RegisterForm extends React.Component { handleError = error => { console.log(error.response) - let errors = error.response.data.errors.full_messages[0]; + let errors = error.response.data.errors; if (errors) { this.setState({ error: true, @@ -131,13 +131,13 @@ class RegisterForm extends React.Component {

Password must match

) : ( -
- - - -

Password must match

-
- )} +
+ + + +

Password must match

+
+ )} {length_errors ? (
@@ -148,15 +148,15 @@ class RegisterForm extends React.Component {

) : ( -
- - - -

- Password must be atleast 8 characters long. +

+ + + +

+ Password must be atleast 8 characters long.

-
- )} +
+ )}

From 9040944bb8c842ac4d6e224b463cfef674c7c4f6 Mon Sep 17 00:00:00 2001 From: Kevin Peery Date: Mon, 28 Jan 2019 15:30:45 -0700 Subject: [PATCH 7/7] remove code for mailer delivery through gmail --- app/controllers/api/users_controller.rb | 1 - app/models/user.rb | 1 - client/src/components/Auth/RegisterForm.js | 2 +- config/environments/development.rb | 21 --------------------- config/environments/production.rb | 18 ------------------ 5 files changed, 1 insertion(+), 42 deletions(-) diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index 5a6304f..0e5e4ef 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -11,7 +11,6 @@ def show end def create - binding.pry @user = User.new(user_params) if @user.save render json: user diff --git a/app/models/user.rb b/app/models/user.rb index bd0d5ea..41aff8a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,6 @@ class User < ActiveRecord::Base has_many :todos, dependent: :destroy after_create do - binding.pry UserMailer.welcome_email(self).deliver_now end end diff --git a/client/src/components/Auth/RegisterForm.js b/client/src/components/Auth/RegisterForm.js index 7253bc1..b956e70 100644 --- a/client/src/components/Auth/RegisterForm.js +++ b/client/src/components/Auth/RegisterForm.js @@ -25,7 +25,7 @@ class RegisterForm extends React.Component { handleError = error => { console.log(error.response) - let errors = error.response.data.errors; + let errors = error.response.data.errors.full_messages[0]; if (errors) { this.setState({ error: true, diff --git a/config/environments/development.rb b/config/environments/development.rb index 4b94dec..468b7d0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -44,27 +44,6 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # gmail - - config.action_mailer.delivery_method = :sendmail - # Defaults to: config.action_mailer.sendmail_settings = { - # location: "/usr/sbin/sendmail", - # arguments: "-i", - # } - config.action_mailer.perform_deliveries = true - config.action_mailer.raise_delivery_errors = true - config.action_mailer.default_options = {from: "DevTrackerW18@gmail.com"} - config.action_mailer.delivery_method = :smtp - # SMTP settings for gmail - config.action_mailer.smtp_settings = { - :address => "smtp.gmail.com", - :port => 587, - :user_name => ENV["gmail_username"], - :password => ENV["gmail_password"], - :authentication => "plain", - :enable_starttls_auto => true, - } - config.action_mailer.delivery_method = :letter_opener config.active_job.queue_adapter = :inline diff --git a/config/environments/production.rb b/config/environments/production.rb index 0f7f22a..902c5ab 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -5,24 +5,6 @@ # Code is not reloaded between requests. config.cache_classes = true - config.action_mailer.delivery_method = :sendmail - # Defaults to: config.action_mailer.sendmail_settings = { - # location: "/usr/sbin/sendmail", - # arguments: "-i", - # } - config.action_mailer.perform_deliveries = true - config.action_mailer.raise_delivery_errors = true - config.action_mailer.default_options = {from: "DevTrackerW18@gmail.com"} - config.action_mailer.delivery_method = :smtp - # SMTP settings for gmail - config.action_mailer.smtp_settings = { - :address => "smtp.gmail.com", - :port => 587, - :user_name => ENV["gmail_username"], - :password => ENV["gmail_password"], - :authentication => "plain", - :enable_starttls_auto => true, - } # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers