Skip to content

Mailers #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore application configuration
/config/application.yml
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/todos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'DevTrackerW18@gmail.com'
layout 'mailer'
end
9 changes: 9 additions & 0 deletions app/mailers/todo_mailer.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions app/views/user_mailer/todos_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>You created a new Todo, <%= @user.email %></h1>
<p>Have a great day!</p>
</body>
</html>
3 changes: 3 additions & 0 deletions app/views/user_mailer/todos_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
You created a new Todo, <%= @user.email %>
===============================================
Have a great day!
17 changes: 17 additions & 0 deletions app/views/user_mailer/welcome_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to https://dev-tracker19.herokuapp.com/, <%= @user.email %></h1>
<p>
You have successfully signed up to dev-tracker19.herokuapp.com,
your username is: <%= @user.email %>.<br>
</p>
<p>
To login to the site, just follow this link: https://dev-tracker19.herokuapp.com/login
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
5 changes: 5 additions & 0 deletions app/views/user_mailer/welcome_email.text.erb
Original file line number Diff line number Diff line change
@@ -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!
30 changes: 15 additions & 15 deletions client/src/components/Auth/RegisterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class RegisterForm extends React.Component {
<p className="match-errors-message">Password must match</p>
</div>
) : (
<div className="no-match-errors">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M400 480H48c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h352c26.51 0 48 21.49 48 48v352c0 26.51-21.49 48-48 48zm-204.686-98.059l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.248-16.379-6.249-22.628 0L184 302.745l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.25 16.379 6.25 22.628.001z" />
</svg>
<p className="no-match-errors-message">Password must match</p>
</div>
)}
<div className="no-match-errors">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M400 480H48c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h352c26.51 0 48 21.49 48 48v352c0 26.51-21.49 48-48 48zm-204.686-98.059l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.248-16.379-6.249-22.628 0L184 302.745l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.25 16.379 6.25 22.628.001z" />
</svg>
<p className="no-match-errors-message">Password must match</p>
</div>
)}
{length_errors ? (
<div className="match-errors">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
Expand All @@ -148,15 +148,15 @@ class RegisterForm extends React.Component {
</p>
</div>
) : (
<div className="no-match-errors">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M400 480H48c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h352c26.51 0 48 21.49 48 48v352c0 26.51-21.49 48-48 48zm-204.686-98.059l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.248-16.379-6.249-22.628 0L184 302.745l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.25 16.379 6.25 22.628.001z" />
</svg>
<p className="no-match-errors-message">
Password must be atleast 8 characters long.
<div className="no-match-errors">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M400 480H48c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h352c26.51 0 48 21.49 48 48v352c0 26.51-21.49 48-48 48zm-204.686-98.059l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.248-16.379-6.249-22.628 0L184 302.745l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.25 16.379 6.25 22.628.001z" />
</svg>
<p className="no-match-errors-message">
Password must be atleast 8 characters long.
</p>
</div>
)}
</div>
)}
</Task>
</TaskList>
<p>
Expand Down
10 changes: 5 additions & 5 deletions client/src/providers/AuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
9 changes: 6 additions & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"]
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview

end
7 changes: 7 additions & 0 deletions test/mailers/user_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UserMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end