Add validation_email_content and validate enable setting.
This commit is contained in:
parent
3f51e89566
commit
b10a11075b
|
@ -202,6 +202,7 @@ class AsksController < ApplicationController
|
|||
ask_setting = AskSetting.first
|
||||
ask_setting = AskSetting.create() if ask_setting.nil?
|
||||
end
|
||||
@ask_setting = ask_setting
|
||||
check_fields = ask_setting.default_setting.select{|k,v| v}.keys & ask_setting.default_setting_required.select{|k,v| v}.keys - AskSetting::No_required
|
||||
flag = true
|
||||
check_fields.each do |f|
|
||||
|
@ -265,8 +266,18 @@ class AsksController < ApplicationController
|
|||
if (email_regex ? ::Regexp.new(email_regex).match(temp_params["mail"].to_s) : true) && flag
|
||||
@disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting, true, nil, true)
|
||||
@usage_rule = ask_setting.usage_rule
|
||||
if temp_params['mail'].blank?
|
||||
temp_params = temp_params.merge({
|
||||
situation: AskTicketStatus::DefaultKeys[1]
|
||||
})
|
||||
end
|
||||
@ask_question.update_attributes(temp_params)
|
||||
build_email(@ask_question)
|
||||
if ask_setting.validate_enable && AskSafeEmail.where(:email=> @ask_question.mail).count == 0
|
||||
build_verification_email(@ask_question)
|
||||
else
|
||||
@ask_question.update(:situation => AskTicketStatus::DefaultKeys[1])
|
||||
build_email(@ask_question)
|
||||
end
|
||||
redirect_to "#{params[:referer_url]}?method=thank"
|
||||
else
|
||||
redirect_to "#{params[:referer_url]}?method=sorry"
|
||||
|
@ -284,6 +295,61 @@ class AsksController < ApplicationController
|
|||
{}
|
||||
end
|
||||
|
||||
def render_404
|
||||
render :file => "#{Rails.root}/app/views/errors/404", :layout => false, :status => :not_found, :formats => [:html]
|
||||
end
|
||||
|
||||
def verify_email
|
||||
@ask_question = AskQuestion.where(:id=>params[:id]).first
|
||||
if @ask_question.nil?
|
||||
render_404 and return
|
||||
elsif @ask_question.situation != AskTicketStatus::DefaultKeys[0]
|
||||
@already_verify = true
|
||||
else
|
||||
@already_verify = false
|
||||
@ask_question.update(:situation => AskTicketStatus::DefaultKeys[1])
|
||||
AskSafeEmail.create(:email=> @ask_question.mail)
|
||||
build_email(@ask_question)
|
||||
end
|
||||
end
|
||||
|
||||
def build_verification_email(email_er)
|
||||
email = Email.new
|
||||
email.save
|
||||
email_er.email_id = email.id
|
||||
email_er.save
|
||||
|
||||
group_mail = email_er.mail
|
||||
manager_emails = email_er.reviewer_emails
|
||||
mail_sentdate = DateTime.now
|
||||
|
||||
site = current_site rescue Site.first
|
||||
mail_from = site.title_translations[site.default_locale]
|
||||
host_url = Site.first.root_url rescue "http://"
|
||||
if host_url == "http://"
|
||||
host_url = request.protocol + request.host_with_port
|
||||
end
|
||||
verify_url = "#{host_url}/#{I18n.locale}/xhr/asks/verify_email/#{email_er.id}"
|
||||
verify_link = "<a title=\"#{t('ask.verify_link')}\" href=\"#{verify_url}\" target=\"_blank\">#{verify_url}</a>"
|
||||
mail_subject = mail_from+": #{t('ask.email_verification_notification')}"
|
||||
email_er.email.update_attributes(
|
||||
:mail_lang=> site.default_locale,
|
||||
:create_user=>(current_user rescue nil),
|
||||
:mail_sentdate=>mail_sentdate,
|
||||
:module_app=>@module_app,
|
||||
:mail_to=>group_mail,
|
||||
:mail_subject=>mail_subject,
|
||||
:template=>'asks/email_verification',
|
||||
:template_data=>{
|
||||
"validation_email_content" => @ask_setting.validation_email_content,
|
||||
"verify_link" => verify_link,
|
||||
"site_host" => host_url,
|
||||
},
|
||||
:mail_reply_to => (manager_emails.empty? ? nil : manager_emails)
|
||||
)
|
||||
# email_er.email.deliver
|
||||
end
|
||||
|
||||
def build_email(email_er)
|
||||
email = Email.new
|
||||
email.save
|
||||
|
|
|
@ -142,6 +142,12 @@ class AskCategorySetting
|
|||
tmp = nil if !(self.email_regex_enable) || ((self.default_setting[:mail] == false) rescue false)
|
||||
tmp
|
||||
end
|
||||
|
||||
field :email_regex_enable, type: Boolean, default: false
|
||||
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
|
||||
field :validate_enable, type: Boolean, default: false
|
||||
field :validation_email_content, type: String, localize: true
|
||||
|
||||
field :tmp_sort_number, type: Hash, default: {} # For Frontend
|
||||
field :sort_number, type: Hash, default: {}
|
||||
field :default_sort_number, type: Hash, default: {}
|
||||
|
@ -154,8 +160,7 @@ class AskCategorySetting
|
|||
field :usage_rule, type: String, default: ''
|
||||
field :category_id, type: String
|
||||
field :title_layout, type: Integer, default: 0
|
||||
field :email_regex_enable, type: Boolean, default: false
|
||||
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
|
||||
|
||||
field :need_check_customs, type: Array, default: [] #From AskSetting
|
||||
field :reject_customs, type: Array, default: [] #From AskSetting
|
||||
field :agree_customs, type: Array, default: [] #From AskSetting
|
||||
|
|
|
@ -20,12 +20,13 @@ class AskQuestion
|
|||
|
||||
field :reply, type: String
|
||||
field :comment, type: String
|
||||
field :situation, type: String, default: "is_waiting" #預設待處理
|
||||
field :send_email, type: Boolean, default: false
|
||||
field :situation, type: String, default: "is_email_not_confirmed" # 預設email未驗證
|
||||
field :email_id
|
||||
field :custom_values, type: Hash,default: {}
|
||||
field :agree_show,type: Boolean,default: false
|
||||
field :agree_usage,type: Boolean,default: false
|
||||
field :verify_email_id
|
||||
field :custom_values, type: Hash, default: {}
|
||||
field :agree_show, type: Boolean, default: false
|
||||
field :agree_usage, type: Boolean, default: false
|
||||
|
||||
field :review_time, type: DateTime
|
||||
belongs_to :reviewer , :class_name=>"MemberProfile", :foreign_key => :reviewer_id
|
||||
|
@ -36,7 +37,11 @@ class AskQuestion
|
|||
self.serial_number = last_serial_number
|
||||
end
|
||||
def email
|
||||
mail = Email.find(self.email_id) rescue nil
|
||||
mail = Email.where(:id=>self.email_id).first
|
||||
end
|
||||
|
||||
def verify_email
|
||||
verify_email = Email.where(:id=>self.verify_email_id).first
|
||||
end
|
||||
def reviewer_emails
|
||||
email_address = AskAdmin.or(:category_ids.in => [self.category_id, [], nil]).pluck(:email).select{|s| s.present?}.uniq rescue []
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AskSafeEmail
|
||||
include Mongoid::Document
|
||||
field :email, type: String
|
||||
index({email: 1}, { unique: false, background: true })
|
||||
end
|
|
@ -93,6 +93,9 @@ class AskSetting
|
|||
end
|
||||
field :email_regex_enable, type: Boolean, default: false
|
||||
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
|
||||
field :validate_enable, type: Boolean, default: false
|
||||
field :validation_email_content, type: String, localize: true
|
||||
|
||||
field :tmp_sort_number, type: Hash, default: {}
|
||||
field :sort_number, type: Hash, default: {}
|
||||
field :default_setting, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: true,appointment: true,recaptcha: true,agree_show: true,agree_usage: true}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class AskTicketStatus
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
DefaultKeys = ["is_waiting", "is_processed", "is_referral", "is_published"]
|
||||
DefaultKeys = ["is_email_not_confirmed" , "is_waiting", "is_processed", "is_referral", "is_published"]
|
||||
field :title, type: String, localize: true
|
||||
field :is_default, type: Boolean, default: false # if true => cannot delete
|
||||
field :key, type: String
|
||||
|
|
|
@ -174,6 +174,25 @@
|
|||
<%= f.text_field :email_regex, {:id=>"ask_email_regex", :style => "width: 30em;"}.merge(f.object.email_regex_enable ? {} : {:disabled=>"disabled"}) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<label for="ask_email_regex"><%= t("ask.validation_email_content") %>:</label>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label id="<%= "#{f.object_name}_validate_enable" %>"><%= f.check_box :validate_enable %><%= t('ask.enable') %></label>
|
||||
<div style="clear: both;"></div>
|
||||
<%= multiple_lang_tag_for_ask(
|
||||
nil,
|
||||
'text_area',
|
||||
'validation_email_content_translations',
|
||||
f.object.validation_email_content_translations,
|
||||
{
|
||||
class: 'ckeditor'
|
||||
}) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("#email_regex_enable").click(function(){
|
||||
if($(this).prop("checked")){
|
||||
|
@ -196,6 +215,22 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="control-label">
|
||||
<label for="ask_email_regex"><%= t("ask.validation_email_content") %>:</label>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label id="<%= "#{f.object_name}_validate_enable" %>"><%= f.check_box :validate_enable %><%= t('ask.enable') %></label>
|
||||
<%= multiple_lang_tag_for_ask(
|
||||
nil,
|
||||
'text_area',
|
||||
'validation_email_content_translations',
|
||||
f.object.validation_email_content_translations,
|
||||
{
|
||||
class: 'ckeditor'
|
||||
}) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<table class="table layoutfix_table">
|
||||
<thead>
|
||||
|
|
|
@ -31,6 +31,16 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= t("ask.validation_email_content") %>:</td>
|
||||
<td>
|
||||
<%= check_box_tag :validate_enable, @default_ask_setting.validate_enable , nil, {:id=>"",:disabled=>'disabled'} %><%= t("ask.enable") %>
|
||||
<div style="clear: both;"></div>
|
||||
<div class="show_field">
|
||||
<%= @default_ask_setting.validation_email_content %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('ask.field') %>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<%= @data['validation_email_content'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
|
||||
</p>
|
||||
<br />
|
||||
<%= @data['verify_link'].html_safe %>
|
||||
<br />
|
||||
<p><%= t('ask.email_automation_hint') %></p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
<style>
|
||||
.error_msg {
|
||||
color: red;
|
||||
}
|
||||
.success_msg {
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<% if @already_verify %>
|
||||
<div class="error_msg"><%= t('ask.this_link_has_expired') %></div>
|
||||
<% else %>
|
||||
<div class="success_msg"><%= t('ask.verify_success') %></div>
|
||||
<% end %>
|
|
@ -47,6 +47,10 @@ en:
|
|||
please_check_email_format: "Please check email format!"
|
||||
enable: Enable
|
||||
email_regex: Email validation regex
|
||||
verify_link: Verify link
|
||||
validation_email_content: Validation Email Content
|
||||
email_verification_notification: Email verification notification
|
||||
email_automation_hint: "This is an automatic email sent by the system, please do not reply directly."
|
||||
please_save: Please click "Save Order" button when you done.
|
||||
save_order: Save Order
|
||||
order_fields: Order Fields
|
||||
|
@ -88,6 +92,7 @@ en:
|
|||
upload_image: Upload Image
|
||||
no_index_page: There are no page for ask module created at site struture.
|
||||
thank_text: We will reply as soon as posible,thank you.
|
||||
is_email_not_confirmed: Email Not Confirmed
|
||||
is_waiting: Pending
|
||||
is_processed: Processed
|
||||
is_referral: Rreferral
|
||||
|
@ -122,6 +127,8 @@ en:
|
|||
acknowledgements: Thank You
|
||||
admins: Administrator
|
||||
new_question: New question
|
||||
verify_success: "Verify Successfully!"
|
||||
this_link_has_expired: "This Link has been clicked and expired!"
|
||||
|
||||
mongoid:
|
||||
attributes:
|
||||
|
|
|
@ -51,6 +51,10 @@ zh_tw:
|
|||
please_check_email_format: "請檢察email是否正確!"
|
||||
enable: 啟用
|
||||
email_regex: Email驗證regex
|
||||
verify_link: 驗證連結
|
||||
validation_email_content: 驗證信內容
|
||||
email_verification_notification: 電子郵件驗證通知
|
||||
email_automation_hint: "此為系統自動發信,請勿直接回覆"
|
||||
please_save: 調整完後, 請點選"儲存順序"
|
||||
save_order: 儲存順序
|
||||
order_fields: 排序欄位
|
||||
|
@ -91,6 +95,7 @@ zh_tw:
|
|||
upload_image: 上傳圖片
|
||||
no_index_page: 前台頁面尚未被建立,請前往網站架構設定,謝謝。
|
||||
thank_text: 我們已經收到您的預約,期待您的蒞臨,謝謝
|
||||
is_email_not_confirmed: Email未驗證
|
||||
is_waiting: 待處理
|
||||
is_processed: 已處理
|
||||
is_referral: 轉介其他單位
|
||||
|
@ -132,6 +137,8 @@ zh_tw:
|
|||
acknowledgements: 感謝詞
|
||||
admins: 管理者
|
||||
new_question: 新的發問
|
||||
verify_success: "驗證成功"
|
||||
this_link_has_expired: "此連結已經點選並已失效!"
|
||||
|
||||
mongoid:
|
||||
attributes:
|
||||
|
|
|
@ -5,7 +5,7 @@ Rails.application.routes.draw do
|
|||
AskPrintSetting.create() if AskPrintSetting.count == 0
|
||||
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
|
||||
update_flag = s.respond_to?(:tmp_flags)
|
||||
need_update = !update_flag || !(s.tmp_flags.include?('askf1'))
|
||||
need_update = !update_flag || !(s.tmp_flags.include?('askf4'))
|
||||
need_update2 = !update_flag || !(s.tmp_flags.include?('askf3'))
|
||||
if need_update
|
||||
ask_setting = AskSetting.first
|
||||
|
@ -31,7 +31,7 @@ Rails.application.routes.draw do
|
|||
ask_setting.save
|
||||
end
|
||||
default_keys = AskTicketStatus::DefaultKeys
|
||||
if AskTicketStatus.count < default_keys.count
|
||||
if AskTicketStatus.where(:key.in => default_keys).count < default_keys.count
|
||||
default_keys.each do |k|
|
||||
ticket_status = AskTicketStatus.where(:is_default=>true,:key=>k).first
|
||||
if ticket_status.nil?
|
||||
|
@ -45,7 +45,7 @@ Rails.application.routes.draw do
|
|||
a.save
|
||||
end
|
||||
if update_flag
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'askf1'})
|
||||
Site.update_all("$push"=>{"tmp_flags"=>'askf4'})
|
||||
end
|
||||
elsif need_update2
|
||||
([AskSetting.first] + AskCategorySetting.all.to_a).each do |a|
|
||||
|
@ -96,6 +96,7 @@ Rails.application.routes.draw do
|
|||
resources :ask_admins
|
||||
end
|
||||
resources :asks #fronted
|
||||
get "/xhr/asks/verify_email/:id" => "asks#verify_email"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue