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 1d3a60e..0b4d8ec 100644 --- a/Gemfile +++ b/Gemfile @@ -16,12 +16,14 @@ group :development, :test do gem 'pry' gem 'faker' gem 'dotenv-rails' + gem 'figaro' end 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..2dd420e 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) @@ -73,12 +75,18 @@ 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) 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 +116,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 +191,8 @@ DEPENDENCIES devise_token_auth dotenv-rails faker + figaro + letter_opener listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) pry diff --git a/app/controllers/api/todos_controller.rb b/app/controllers/api/todos_controller.rb index a3f8dbb..d31a539 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, @user).deliver_now render json: todo else render json: todo.errors, status: 422 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/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 new file mode 100644 index 0000000..854077a --- /dev/null +++ b/app/mailers/user_mailer.rb @@ -0,0 +1,9 @@ +class UserMailer < ApplicationMailer + default from: "DevTrackerW18@gmail.com" + + def welcome_email(user) + @user = 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..41aff8a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,4 +10,8 @@ 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(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 new file mode 100644 index 0000000..782a684 --- /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..278749c --- /dev/null +++ b/app/views/user_mailer/welcome_email.text.erb @@ -0,0 +1,5 @@ +Welcome to https://dev-tracker19.herokuapp.com/login, <%= @user.email %> +=============================================== +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/client/src/components/Auth/RegisterForm.js b/client/src/components/Auth/RegisterForm.js index aeb98e0..b956e70 100644 --- a/client/src/components/Auth/RegisterForm.js +++ b/client/src/components/Auth/RegisterForm.js @@ -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.

-
- )} +
+ )}

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..468b7d0 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,9 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + config.action_mailer.delivery_method = :letter_opener + + 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