Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop

This commit is contained in:
huang 2018-09-30 17:32:08 +08:00
commit 26cc87ba84
9 changed files with 160 additions and 63 deletions

View File

@ -17,12 +17,15 @@
class AccountController < ApplicationController
helper :custom_fields
include AccountHelper
include CustomFieldsHelper
require 'net/https'
require 'uri'
# prevents login action to be filtered by check_if_login_required application scope filter
skip_before_filter :check_if_login_required
skip_before_filter :verify_authenticity_token, :only =>[:codepedia_login]
# Login request and validation
#
def login
if params[:type] == "activated"
@message = l(:notice_account_activated)
@ -264,6 +267,66 @@ class AccountController < ApplicationController
render :json => req
end
def get_email_info
user = User.find(params[:user_id])
if user.present? && user.mail.present?
begin
email_path = Redmine::Configuration['email_path']
email_secret = Redmine::Configuration['email_secret']
email_Corp_ID = Redmine::Configuration['email_Corp_ID']
uri = "#{email_path}/gettoken?corpid=#{email_Corp_ID}&corpsecret=#{email_secret}"
uri = URI.parse(uri)
Rails.logger.info("get_access_token_uri: #{uri}")
http = Net::HTTP.new(uri.host, uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
Rails.logger.info("get_access_token_uri_path: #{uri.request_uri}")
request = Net::HTTP::Get.new(uri.request_uri)
res = http.request(request)
res = JSON.parse(res.body)
Rails.logger.info("get_access_token: #{res}")
if res['access_token'].present?
Rails.logger.info("access_token: #{res['access_token']}")
uri_params = {:begin_date => "#{Time.now.strftime('%Y-%m-%d')}", :end_date => "#{Time.now.strftime('%Y-%m-%d')}",
:mailtype => 1, :userid => "notification@trustie.org", :subject => params[:subject]}
uri_params = uri_params.to_json
Rails.logger.info("get_uri_params: #{uri_params}")
log_uri = "#{email_path}/log/mail?access_token=#{res['access_token']}"
log_uri = URI.parse(log_uri)
Rails.logger.info("get_log_uri: #{log_uri}")
http = Net::HTTP.new(log_uri.host, log_uri.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
request = Net::HTTP::Post.new(log_uri.request_uri, initheader = {'Content-Type' =>'application/json'})
request['foo'] = 'bar'
request.body = "#{uri_params}"
Rails.logger.info("request: #{request.body}")
response = http.start { |http| http.request(request) }
res = JSON.parse(response.body)
Rails.logger.info("get_log: #{res}")
if res['errcode'] == 0
status = -1
res['list'].each do |list|
if list['receiver'] == user.mail
status = list['status']
end
end
render :json => {:result => "succuss", :message => email_status(status)}
end
else
render :json => {:result => "fail"}
end
rescue => e
Rails.logger.error("failed to get email info! #{e}")
end
end
end
def email_valid
begin
@mail_type = params[:mail].split("@")[1]

View File

@ -19,6 +19,33 @@
module AccountHelper
def email_status status
message = ""
case status
when -1
message = " 未查询到相关数据"
when 0
message = "其他状态"
when 1
message = "发信中"
when 2
message = "被退信"
when 3
message = "发信成功"
when 4
message = "发信失败"
when 11
message = "收信被拦截"
when 12
message = "收信,邮件进入垃圾箱"
when 13
message = "收信成功,邮件在收件箱"
when 14
message = "收信成功,邮件在个人文件夹"
end
message
end
def email_activation_register(user, &block)
token = Token.new(:user => user, :action => "register")
if user.save and token.save

View File

@ -67,7 +67,11 @@
$("#user_email_show").html(data.email);
// 更改邮箱地址后,直接给用户发送邮件
$.ajax({
url: "<%= resendmail_path(:user => @user) %>"
url: "<%= resendmail_path(:user => @user) %>",
type: 'get',
success:function(data){
task = setInterval(get_email_info(<%= @user.try(:id) %>, "用户注册帐号激活通知"), 1000);
}
});
hideModal();
return;

View File

@ -3,18 +3,14 @@
<p class="email_verify_prompt"><span class="icons_email_prompt"></span>您的账号尚未激活,请先进入您的注册邮箱(<span class="c_red" id="user_email_show"><%= @user.mail %></span>),激活您的账号。</p>
<button class="email_verify_btn mt30 ml30" onclick = "resendMail('<%= resendmail_path(@user) %>','<%= @user.id %>');">重新发送激活邮件</button>
<%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %>
<div class="mt10 ml30 mb10 email_info_box none">
<span class="f14" id="email_log_detail">邮件概况:</span>
</div>
<ul class="email_prompt_txt ml30 mt30" style="width:580px;margin-bottom: 20px">
<p class="email_prompt_p">如果您尚未收到激活邮件,请按照以下步骤操作:</p>
<li>检查邮箱的“订阅邮件”、“垃圾邮件”,可能会发现激活邮件。 </li>
<li>如果激活邮件已无效,请点击重新发送激活邮件按钮。</li>
<li>如果重发注册验证邮箱邮件仍然没有收到,请<a href="javascript:void(0);" class="link-blue" id="change_email">更换邮箱地址</a>,重新发送激活邮件</li>
<li>如果您始终无法收到激活邮件,请直接给我们<a href="javascript:void(0);" class="link-blue" id="leave_message">留言</a></li>
<div class="mt10 undis" id="message_box">
<textarea style="resize: none;width: 570px;" class="email_prompt_mes" placeholder="<%= l(:label_email_feedback_tips) %>"></textarea>
<div class="c1"></div>
<button class="email_sub_btn fr" onclick="leave_email_activation_message('<%= leave_email_activation_message_path(1)%>','<%= @user.id %>');">确定</button>
<div class="cl"></div>
</div>
</ul>
</div>
</div>
@ -45,28 +41,10 @@
}
$(".email_verify_btn").replaceWith("<p class='email_verify_p mt30 ml30'>激活邮件已发送至您的注册邮箱("+mail+"),请及时登录邮箱进行验证。</p>");
get_email_info(<%= @user.try(:id) %>, "用户注册帐号激活通知");
}
);
}
function leave_email_activation_message(url,user)
{
if ($(".email_prompt_mes").val().length == 0){
//弹框请他输入文字
var htmlvalue = "</br><div style='width:550px;text-align:center'>您的留言不能为空</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
pop_up_box(htmlvalue,580,30,50);
return;
}
$.ajax({
url: url,
data: {user: user, text: $(".email_prompt_mes").val() },
type: "POST",
success: function (data) {
var htmlvalue = "<div class='email_tancon'><h2 class='email_tan_title'>您的留言已发送</h2><p class='email_tan_p'>我们将尽快处理好并通知您。感谢您的反馈!</p></div>"
pop_up_box(htmlvalue, 580, 30, 45);
$(".email_prompt_mes").val("");
}
});
}
function regex_mv_name()
{

View File

@ -5,32 +5,30 @@
<div class="email_verify" style="width: 580px;">
<p class="fb f18" style="color:green;"><i class="icon-ok mr5 f18"></i>注册成功!
<span style=" color:#3b94d6; font-size:12px; font-weight:normal;">请在24小时内点击邮件中的链接来激活您的账号。</span></p>
<p class="f14 mt30 mb5">请登录邮箱(<span class="c_red" id="user_email_show"><%= @user.mail %></span>)收取账号激活邮件。<br/>点击邮件中的激活链接,方可使用该账号
<p class="f14 mt30 mb5">请登录邮箱(<span class="c_red" id="user_email_show"><%= @user.mail %></span>)收取账号激活邮件。<br/>点击邮件中的激活链接,方可使用该账号
</p>
<p>
<a href="http://mail.<%= email %>" class="btn btn-blue" target="_blank"><%= l(:label_check_email)%></a>
&nbsp; &nbsp; <%= link_to "<input class='btn btn-blue' type='button' id='btn' value='重新发送激活邮件' onclick='settime(this)' />".html_safe, { :controller => 'account', :action => 'resendmail', :user => @user}, :remote => true, :method => 'get' %>
<a href="javascript:void(0);" onclick="resendMail('<%= resendmail_path(@user) %>','<%= @user.id %>');"><input class='btn btn-blue' type='button' id='btn' value='重新发送激活邮件'/></a>
</p>
<div class="mt10 mb10 email_info_box">
<span class="f14" id="email_log_detail">邮件概况:</span>
</div>
<ul class="email_prompt_txt mt30" style="width: 580px;">
<p class="email_prompt_p">如果您一直收不到激活邮件,请按照以下步骤操作:</p>
<li>请确认是否填写了正确的邮箱地址 </li>
<li>请注意查看邮箱中的“订阅邮件”、“垃圾邮件”可能Trustie的邮件被误杀了</li>
<li>请点击重新发送激活邮件按钮</li>
<li>如果重发注册验证邮箱邮件仍然没有收到,请<a href="javascript:void(0);" class="link-blue" id="change_email">更换邮箱地址</a>,重新发送激活邮件</li>
<li>如果您始终无法收到激活邮件,请直接给我们<a href="javascript:void(0);" class="link-blue" id="leave_message">留言</a></li>
<div class="mt10 undis" id="message_box">
<textarea style="resize: none;width: 570px;" class="email_prompt_mes" placeholder="<%= l(:label_email_feedback_tips) %>"></textarea>
<div class="c1"></div>
<button class="email_sub_btn fr" onclick="leave_email_activation_message('<%= leave_email_activation_message_path(1)%>','<%= @user.id %>');">确定</button>
<div class="cl"></div>
</div>
</ul>
</div>
</div>
<script>
$(document).ready(function(){
get_email_info(<%= @user.try(:id) %>, "用户注册帐号激活通知");
$("#change_email").click(function(){
$.ajax({
url: "<%= change_user_email_user_path(@user) %>"
@ -41,27 +39,26 @@
})
});
function leave_email_activation_message(url,user)
function resendMail(url,id)
{
if ($(".email_prompt_mes").val().length == 0){
//弹框请他输入文字
var htmlvalue = "</br><div style='width:550px;text-align:center'>您的留言不能为空</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
pop_up_box(htmlvalue,580,30,50);
return;
}
$.get(
url,
{user: id },
function (data) {
//邮箱@之前用a**b格式显示
var mail = data.email;
var pos = mail.indexOf("@");
var restr = mail.substring(1,pos-1);
if( mail.split("@")[0].length > 2 ){
mail = mail.replace(restr,"***");
}
$.ajax({
url: url,
data: {user: user, text: $(".email_prompt_mes").val() },
type: "POST",
success: function (data) {
var htmlvalue = "<div class='email_tancon'><h2 class='email_tan_title'>您的留言已发送</h2><p class='email_tan_p'>我们将尽快处理好并通知您。感谢您的反馈!</p></div>"
pop_up_box(htmlvalue, 580, 30, 50);
$(".email_prompt_mes").val("");
settime(document.getElementById("btn"));
get_email_info(<%= @user.try(:id) %>, "用户注册帐号激活通知");
}
});
);
}
function regex_mv_name()
{
var name = $.trim($("#subject").val());
@ -121,13 +118,6 @@
myTips("反馈成功","success");
});
$("#scrollsidebar").fix({
float: 'right', //default.left or right
minStatue: cookieget('minStatue'),
skin: 'green', //default.gray or blue
durationTime: 600
});
$("#subject").keydown(function(){
alert("2222");
var curLength=$("#subject").val().length;

View File

@ -1,4 +1,4 @@
//获取登录页面地址
var signinPath = '<%= signin_url_without_domain %>';
var htmlvalue = "</br><div style='width:550px;text-align:center'>您还没有登录,请登录后再执行此操作,谢谢!</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href="+signinPath+" class='Blue-btn fl' target='_Blank' onclick=' hideModal()' >登录</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>关闭</a></div>";
var htmlvalue = "</br><div style='width:550px;text-align:center'>您还没有登录,请登录后再执行此操作,谢谢!</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='"+signinPath+"' class='Blue-btn fl' target='_Blank' onclick='hideModal()' >登录</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>关闭</a></div>";
pop_up_box(htmlvalue,580,30,50);

View File

@ -544,6 +544,7 @@ RedmineApp::Application.routes.draw do
match 'account/activate', :via => :get
match 'account/valid_ajax', :via => :get
match 'account/change_email', :via => :get
match 'account/get_email_info', :to => 'account#get_email_info', :via => :get
match 'account/email_valid', :to => 'account#email_valid', :via => :get
match 'account/resendmail', :to => 'account#resendmail', :via=> :get, :as => 'resendmail'
match 'account/codepedia_login', :to => 'account#codepedia_login', :via => [:get, :post]

View File

@ -2347,4 +2347,37 @@ function toggle_student_score(id){
} else{
$("#toggle_score_" + id).html("展开评阅详情");
}
}
function get_email_info(id, subject) {
task = setInterval(search_email_status, 2000);
var count = 0;
function search_email_status() {
count = count + 1;
if(count > 3){
clearInterval(task);
} else {
$.ajax({
url: '/account/get_email_info?user_id=' + id + '&subject=' + subject,
type: 'get',
success: function (data) {
$("#email_log_detail").parent().show();
if (data.result == "succuss") {
$("#email_log_detail").html("邮件概况:" + data.message);
if (data.message != "未查询到相关数据" && data.message != "发信中") {
clearInterval(task);
}
} else {
$("#email_log_detail").html("邮件概况:无法查询邮件概况");
clearInterval(task);
}
},
error: function () {
$("#email_log_detail").html("邮件概况:无法查询邮件概况");
$("#email_log_detail").parent().show();
clearInterval(task);
}
});
}
}
}

View File

@ -840,6 +840,7 @@ a.winbox_btn_close{ color: #3b94d6; font-size: 18px; font-weight: bold;}
.email_tan_title{font-size:18px; color:#3a95d7; font-weight:normal; margin-bottom:5px;}
.email_tan_p{ font-size:14px; color:#4c4c4c;}
.email_verify_p{ font-size:14px; color:#3a95d7;}
.email_info_box{ background: #f5f5f5; padding: 5px; height: 60px;}
/* 作业二级回复 */
.clearit { clear:both; height:0; font-size:0; overflow:hidden; }
.comment_item{ width:720px; background-color:#f1f1f1; color:#888;}