Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into user-messagin
  • Loading branch information
jannypie committed Apr 21, 2015
2 parents 2ddaff7 + 00ac36c commit c2af96b
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 12 deletions.
26 changes: 20 additions & 6 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,26 @@
//= require visualdata
//= require iconHelper

function sendEmail(address, username) {
console.log('sending an email to ' + address + ', from ' + username + '!')
$.ajax({
url: 'email',
data: {email: address, username: username},
type: 'POST'
}).done(function(data){
$('#send_email').attr('disabled', false)
$('#send_email').val('Submit')
$("#send-email-address").val("")
$('#send-email-message').html("Your email has been sent to " + address + "!")
}).fail(function(data){
$('#send_email').attr('disabled', false)
$('#send_email').val('Submit')
$("#send-email-address").val("")
$('#send-email-message').html("There was an error and your email was not able to be sent. Please try again shortly.")
})
}


//
window.sendEmail = sendEmail
function parseTwitterDate(tdate) {
var system_date = new Date(Date.parse(tdate));
var user_date = new Date();
Expand Down Expand Up @@ -53,9 +70,6 @@ var K = function () {
}
}();




function addSkillMeters() {
$(document).on('click','.add-skill', function(e){
e.preventDefault();
Expand All @@ -69,4 +83,4 @@ function addSkillMeters() {
sibling.val('');
});
}
addSkillMeters();
addSkillMeters();
14 changes: 13 additions & 1 deletion app/assets/javascripts/application/templates/users/edit.jst.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</section>
<section class="light-container col-xs-12 col-sm-8">
<h3>Edit Your Portfolio Information</h3>
<form id="user_form">
<form id="user-form">
<fieldset>
<label for="" class="col-xs-12 col-sm-3">Name</label>
<input class="col-xs-12 col-sm-6" type="text" name="name" value="<%= user_settings.name %>">
Expand Down Expand Up @@ -96,4 +96,16 @@
</fieldset>
</form>
</section>
<form id='mailer-form'>
<h4>Want to share your Devolio with someone?</h4>
<p>Enter any email address below and a link to your personal DEVOLIO will be automatically sent!</p>
<fieldset>
<label for="" class="col-xs-12 col-sm-3">Email Address</label>
<input class="col-xs-12 col-sm-6" type="text" name="email-address" id='send-email-address' value="">
</fieldset>
<fieldset>
<input type="submit" id="send_email" value="Send Link">
<p class="message" id='send-email-message'></p>
</fieldset>
</form>
</div>
19 changes: 16 additions & 3 deletions app/assets/javascripts/application/views/users/edit.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ class App.Views.Users.Edit extends App.View
template: JST['application/templates/users/edit']

events:
'submit form' : 'onFormSubmit'
'submit #user-form' : 'userFormSubmit'
'submit #mailer-form' : 'mailerFormSubmit'

render: ->
@$el.html(@template(@model.attributes))

onFormSubmit: ->
userFormSubmit: ->
$('#get_api').attr('disabled', true)
$('#get_api').val('Loading...')
form = @$el.find "form"
form = @$el.find "#user-form"
newAttrs = form.serializeJSON()
success = =>
console.log @model
Expand All @@ -23,3 +24,15 @@ class App.Views.Users.Edit extends App.View
$('.message').html("<span class='error'>There was an issue saving your updates</span>")
@model.save(newAttrs, success: success, error: error)
false

mailerFormSubmit: (e) ->
e.preventDefault()
$('#send_email').attr('disabled', true)
$('#send_email').val('Sending...')
form = @$el.find "#mailer_form"
username = $('body').attr('id')
console.log(username)
address = $('#send-email-address').val();
window.sendEmail(address, username)
error = ->
$(form + ' .message').html("<span class='error'>There was an issue and no email was sent.</span>")
12 changes: 12 additions & 0 deletions app/controllers/resumes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ def github

github_data.to_json
end

def email
puts '*' * 50
puts '*' * 50
puts 'SENDING EMAIL'
puts params
puts '*' * 50
puts '*' * 50
UserMailer.share_email(params).deliver_now

render nothing: true
end
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
10 changes: 10 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class UserMailer < ApplicationMailer
default from: 'no-reply@devol.io'

def share_email(params)
@user = User.find_by(username: params[:username])
@url = "https://devolio.herokuapp.com/#{@user.username}"
mail(to: params[:email], subject: "#{@user.name} would like to share their Devolio!")
end

end
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
13 changes: 13 additions & 0 deletions app/views/user_mailer/share_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
</head>
<body>
<h1>Hello!</h1>
<p><%= @user.name %> would like to share their Devolio with you!</p>
<p>Simple <a href='<%= @url %>'>follow this link</a> to check it out!</p>
<p>Sincerely,</p>
<p>The DEVOLIO team</p>
</body>
</html>
15 changes: 13 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# 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.default_url_options = { :host => 'localhost:3000' }

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: '587',
domain: 'gmail.com',
authentication: 'plain',
enable_starttls_auto: true,
user_name: 'devolio.app@gmail.com',
password: 'sealions'
}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand Down
13 changes: 13 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

config.action_mailer.default_url_options = { :host => 'https://devolio.herokuapp.com/' }

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
domain: 'heroku.com',
authentication: 'plain',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
enable_starttls_auto: true
}

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
resources :users, only: [:show, :edit, :update, :destroy]

post 'store_github', to: 'api#github'
post 'email', to: 'resumes#email'

root to: 'static#index'

Expand Down
4 changes: 4 additions & 0 deletions spec/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
5 changes: 5 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe UserMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit c2af96b

Please sign in to comment.