<邮件加密自动登录功能,邮件附件下载功能>

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2015-01-15 18:48:19 +08:00
parent 2bba0ddd70
commit 5191411508
12 changed files with 97 additions and 42 deletions

View File

@ -156,7 +156,16 @@ class ApplicationController < ActionController::Base
user
end
end
def try_to_autologin1
# auto-login feature starts a new session
user = User.try_to_autologin(params[:token])
if user
start_user_session(user)
end
user
end
# Sets the logged in user
def logged_user=(user)
reset_session
@ -248,10 +257,11 @@ class ApplicationController < ActionController::Base
end
end
end
def authorize1(ctrl = params[:controller], action = params[:action],login = params[:user_name],password = params[:password], global = false)
def authorize1(ctrl = params[:controller], action = params[:action],token = params[:token], global = false)
if(!User.current.logged? && !login.nil?)
password_authentication
if(!User.current.logged? && !token.nil?)
User.current =try_to_autologin1
end
allowed = authorize_allowed(params[:controller], params[:action],global)
@ -307,9 +317,9 @@ class ApplicationController < ActionController::Base
end
end
def authorize_attachment_download1(ctrl = params[:controller], action = params[:action],login = params[:user_name],password = params[:password], global = false)
if(!User.current.logged? && !login.nil?)
password_authentication
def authorize_attachment_download1(ctrl = params[:controller], action = params[:action],token = params[:token], global = false)
if(!User.current.logged? && !token.nil?)
User.current = try_to_autologin1
end
case @attachment.container_type
when "Memo"
@ -850,6 +860,7 @@ class ApplicationController < ActionController::Base
end
def successful_authentication(user, last_login_on)
logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}"
# Valid user

View File

@ -140,10 +140,12 @@ module ApplicationHelper
# * :text - Link text (default to attachment filename)
# * :download - Force download (default: false)
def link_to_attachment(attachment, options={})
token = options[:token] if options[:token]
text = options.delete(:text) || attachment.filename
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path)
url = send(route_method, attachment, attachment.filename, options)
url << "?token=#{token}" unless token.nil?
link_to text, url, html_options
end

View File

@ -224,6 +224,7 @@ module IssuesHelper
# as an array of strings
def details_to_strings(details, no_html=false, options={})
options[:only_path] = (options[:only_path] == false ? false : true)
options[:token] = options[:token] if options[:token]
strings = []
values_by_field = {}
details.each do |detail|
@ -312,7 +313,11 @@ module IssuesHelper
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
if options[:token].nil?
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
else
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path], :token => options[:token])
end
if options[:only_path] != false && atta.is_text?
value += link_to(
image_tag('magnifier.png'),

View File

@ -18,8 +18,12 @@
class IssueObserver < ActiveRecord::Observer
def after_create(issue)
thread1=Thread.new do
Mailer.issue_add(issue).deliver if Setting.notified_events.include?('issue_added')
end
Thread.start do
recipients = issue.recipients
recipients.each do |rec|
Mailer.issue_add(issue,rec).deliver if Setting.notified_events.include?('issue_added')
end
end
end
end

View File

@ -20,7 +20,11 @@ class IssueOverdue < ActiveRecord::Base
#发邮件
#puts "11" + issue.id.to_s
#Mailer.issue_expire(issue).deliver
Mailer.issue_add(issue).deliver
recipients = issue.recipients
recipients.each do |rec|
Mailer.issue_edit(issue,rec).deliver
end
break
end
end

View File

@ -23,8 +23,12 @@ class JournalObserver < ActiveRecord::Observer
(Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
(Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
)
Thread.new do
Mailer.issue_edit(journal).deliver
Thread.start do
recipients = journal.recipients
recipients.each do |rec|
Mailer.issue_edit(journal,rec).deliver
end
end
end
end

View File

@ -95,38 +95,45 @@ class Mailer < ActionMailer::Base
# Example:
# issue_add(issue) => Mail::Message object
# Mailer.issue_add(issue).deliver => sends an email to issue recipients
def issue_add(issue)
def issue_add(issue, recipients)
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue_id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
message_id issue
@author = issue.author
@issue = issue
recipients = issue.recipients
if recipients.include? "547533434@qq.com"
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :user_name => 'alan', :password => 'alanlong')
else
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
end
token = Token.new(:user => User.find_by_mail(recipients), :action => 'autologin')
token.save
@token = token
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :token => @token.value)
cc = issue.watcher_recipients - issue.recipients
subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
mail(:to => recipients,
:cc => cc,
:subject => subject)
end
# issue.attachments.each do |attach|
# attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}")
# end
cc = issue.watcher_recipients - recipients
# cc = issue.watcher_recipients - recipients
#mail.attachments['test'] = File.read("#{RAILS.root}/files/2015/01/150114094010_libegl.dll")
mail :to => recipients,
:cc => cc,
:subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
end
# Builds a Mail::Message object used to email recipients of the edited issue.
#
# Example:
# issue_edit(journal) => Mail::Message object
# Mailer.issue_edit(journal).deliver => sends an email to issue recipients
def issue_edit(journal)
def issue_edit(journal,recipients)
issue = journal.journalized.reload
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
@ -136,24 +143,34 @@ class Mailer < ActionMailer::Base
message_id journal
references issue
@author = journal.user
recipients = journal.recipients
if recipients.include? "547533434@qq.com"
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}", :user_name => 'alan', :password => 'alanlong')
else
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}")
end
token = Token.new(:user => User.find_by_mail(recipients), :action => 'autologin')
token.save
@token = token
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}", :token => @token.value)
# Watchers in cc
cc = journal.watcher_recipients - recipients
cc = journal.watcher_recipients - journal.recipients
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
s << issue.subject
@issue = issue
@journal = journal
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
mail :to => recipients,
:cc => cc,
:subject => s
mail(:to => recipients,
:cc => cc,
:subject => s)
end
def self.deliver_mailer(to,cc, subject)
mail :to => to,
:cc => cc,
:subject => subject
end
# 用户申请加入项目邮件通知

View File

@ -380,7 +380,7 @@ class User < Principal
raise text
end
# Returns the user who matches the given autologin +key+ or nil
def self.try_to_autologin(key)
user = Token.find_active_user('autologin', key, Setting.autologin.to_i)
if user
@ -466,7 +466,11 @@ class User < Principal
User.hash_password("#{salt}#{User.hash_password clear_password}") == hashed_password
end
end
def check_password1?(clear_password)
clear_password == hashed_password
end
# Generates a random salt and computes hashed_password for +clear_password+
# The hashed password is stored in the following form: SHA1(salt + SHA1(password))
def salt_password(clear_password)

View File

@ -5,10 +5,11 @@
<% unless @issue.attachments.nil? %>
<% @issue.attachments.each do |attach| %>
<li> <%= link_to_attachment(attach, :download => true, :only_path => false) %></li>
<li> <%= l(:label_attachment) %><%= link_to_attachment(attach, :download => true, :token => @token.value, :only_path => false) %><%= l(:label_added) %></li>
<% end %>
<% end %>
</ul>
<hr />
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>

View File

@ -1,8 +1,11 @@
<%= l(:text_issue_added, :id => "##{@issue.project_index}", :author => @issue.author) %>
<% @issue.attachments.each do |attach| %>
<%= link_to_attachment(attach, :download => true, :only_path => false) %>
<%= l(:label_attachment) %>
<%= link_to_attachment(attach, :download => true, :token => @token.value, :only_path => false) %> <%= l(:label_added) %>
<% end %>
----------------------------------------
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %>

View File

@ -1,7 +1,7 @@
<%= l(:text_issue_updated, :id => "##{@issue.project_index}", :author => h(@journal.user)) %>
<ul>
<% details_to_strings(@journal.details, false, :only_path => false).each do |string| %>
<% details_to_strings(@journal.details, false, :only_path => false, :token => @token.value).each do |string| %>
<li><%= string %></li>
<% end %>
</ul>

View File

@ -1,6 +1,6 @@
<%= l(:text_issue_updated, :id => "##{@issue.project_index}", :author => @journal.user) %>
<% details_to_strings(@journal.details, true).each do |string| -%>
<% details_to_strings(@journal.details, true, :token => @token.value).each do |string| -%>
<%= string %>
<% end -%>