Adding user email feature

This commit is contained in:
Will Bradley 2013-10-06 04:09:56 -07:00
parent 04bab84293
commit 57e6ac1fc5
6 changed files with 72 additions and 12 deletions

View File

@ -50,7 +50,7 @@ class UsersController < ApplicationController
# Recent user activity
def activity
@user_logins = User.where(:last_sign_in_at => 1.month.ago..Date.today)
@user_logins = User.where(:last_sign_in_at => 1.month.ago..Time.now)
@new_users = User.where(:created_at => 3.months.ago..Date.today)
@cardless_users = User.includes('cards').where(['users.member_level >= ?','50']).where('cards.id IS NULL')
end
@ -70,6 +70,24 @@ class UsersController < ApplicationController
end
end
def compose_email
@user = User.find(params[:user_id])
authorize! :read, @user
end
def send_email
@user = User.find(params[:user_id])
authorize! :read, @user
@subject = params[:subject]
@body = params[:body]
if @user.send_email(current_user,@subject,@body)
redirect_to user_path(@user), :notice => "Email sent successfully."
else
flash[:alert] = "Error sending email."
render :compose_email
end
end
# GET /user_summary/1
def user_summary
respond_to do |format|

View File

@ -1,13 +1,20 @@
class UserMailer < ActionMailer::Base
default :from => "wiki@heatsynclabs.org"
default :from => "no-reply@heatsynclabs.org"
def new_user_email(user)
@user = user
@url = "http://members.heatsynclabs.org"
#@admins = User.where(:name => "Will Bradley")
#@admins.each do |admin|
mail(:to => 'member-notifications@heatsynclabs.org', :subject => "New HSL Member: "+user.name)
#end
mail(:to => 'member-notifications@heatsynclabs.org',
:subject => "New HSL Member: "+user.name)
end
def email(to_user,from_user,subject,body)
@url = "http://members.heatsynclabs.org"
@body = body
@from_user = from_user
mail(:to => to_user.email,
:subject => "HSL Message: "+subject)
end
end

View File

@ -121,8 +121,16 @@ class User < ActiveRecord::Base
end
end
def send_email(from_user,subject,body)
Rails.logger.info UserMailer.email(self,from_user,subject,body).deliver
end
private
def send_new_user_email
Rails.logger.info UserMailer.new_user_email(self).deliver
end
def member_status_calculation
# Begin output buffer
message = ""
@ -194,9 +202,4 @@ class User < ActiveRecord::Base
return {:message => message, :paid => paid, :flair => flair}
end
def send_new_user_email
Rails.logger.info UserMailer.new_user_email(self).deliver
end
end

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p><b>From:</b> <%= link_to @from_user.name, @from_user %></p>
<p>
<%= simple_format @body %>
</p>
<p>
<i>To reply, visit <%= link_to @url, @url %></i> .
</p>
</body>
</html>

View File

@ -0,0 +1,14 @@
<h3>Send Email to <%= @user.name %></h3>
<%= form_tag do %>
<div class="field">
<%= label_tag :subject %><br/>
<%= text_field_tag :subject, @subject, :size => 52 %>
</div>
<div class="field">
<%= label_tag :body %><br/>
<%= text_area_tag :body, @body, :cols => 40 %>
</div>
<div class="field">
<%= submit_tag "Send", :class => "btn" %>
</div>
<% end %>

View File

@ -35,7 +35,10 @@ Dooraccess::Application.routes.draw do
match 'users/merge' => 'users#merge_view', :via => :get # Merge view
match 'users/merge' => 'users#merge_action', :via => :post # Merge action
match 'users/inactive' => 'users#inactive' # Inactive users report
resources :users
resources :users do
get 'email' => 'users#compose_email'
post 'email' => 'users#send_email'
end
match 'users/create' => 'users#create', :via => :post # Use POST users/create instead of POST users to avoid devise conflict
match 'cards/upload_all' => 'cards#upload_all', :as => :upload_all