diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 57e6cad..16bd459 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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| diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 725d6a5..4370377 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 2604e15..5d0df20 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/user_mailer/email.html.erb b/app/views/user_mailer/email.html.erb new file mode 100644 index 0000000..510a82c --- /dev/null +++ b/app/views/user_mailer/email.html.erb @@ -0,0 +1,15 @@ + + +
+ + + +From: <%= link_to @from_user.name, @from_user %>
++ <%= simple_format @body %> +
++ To reply, visit <%= link_to @url, @url %> . +
+ + diff --git a/app/views/users/compose_email.html.erb b/app/views/users/compose_email.html.erb new file mode 100644 index 0000000..3beb74e --- /dev/null +++ b/app/views/users/compose_email.html.erb @@ -0,0 +1,14 @@ +