From 65fb59d78bb2a821f26bd4ee627a00395144d791 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 14 Sep 2018 14:47:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=8F=90=E7=A4=BA=E9=A1=B5?= =?UTF-8?q?=E5=92=8C=E6=9C=AA=E6=BF=80=E6=B4=BB=E8=B4=A6=E5=8F=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=20=E5=A2=9E=E5=8A=A0=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=A6=82=E5=86=B5=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 65 +++++++++++++++++++- app/helpers/account_helper.rb | 27 ++++++++ app/views/account/email_activation.html.erb | 47 ++++++-------- app/views/account/email_valid.html.erb | 48 ++++++--------- app/views/organizations/_unlogged_tip.js.erb | 2 +- config/routes.rb | 1 + public/stylesheets/css/public.css | 1 + 7 files changed, 133 insertions(+), 58 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 9e9bcc767..ce6255e16 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -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] diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 827557a40..6c06a8358 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -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 diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb index 5f64ddf06..41434afe7 100644 --- a/app/views/account/email_activation.html.erb +++ b/app/views/account/email_activation.html.erb @@ -3,18 +3,14 @@

您的账号尚未激活,请先进入您的注册邮箱(<%= @user.mail %>),激活您的账号。

<%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %> +
+ 邮件概况: +
@@ -45,28 +41,25 @@ } $(".email_verify_btn").replaceWith("

激活邮件已发送至您的注册邮箱("+mail+"),请及时登录邮箱进行验证。

"); + + $.ajax({ + url:'<%= account_get_email_info_path(:user_id => @user.try(:id), :subject => "用户注册帐号激活通知") %>', + type:'get', + success:function(data){ + if(data.result == "succuss"){ + $("#email_log_detail").html("邮件概况:"+data.message); + } else{ + $("#email_log_detail").html("邮件概况:无法查询邮件概况"); + } + $("#email_log_detail").parent().show(); + }, + error:function(){ + $("#email_log_detail").html("邮件概况:无法查询邮件概况"); + $("#email_log_detail").parent().show(); + } + }); } ); - } - function leave_email_activation_message(url,user) - { - if ($(".email_prompt_mes").val().length == 0){ - //弹框请他输入文字 - var htmlvalue = "
您的留言不能为空

确定
"; - 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 = "
" - pop_up_box(htmlvalue, 580, 30, 45); - $(".email_prompt_mes").val(""); - } - }); } function regex_mv_name() { diff --git a/app/views/account/email_valid.html.erb b/app/views/account/email_valid.html.erb index f0a91069a..8bb1020ae 100644 --- a/app/views/account/email_valid.html.erb +++ b/app/views/account/email_valid.html.erb @@ -5,32 +5,43 @@

注册成功! 请在24小时内点击邮件中的链接来激活您的账号。

-

请登录邮箱(<%= @user.mail %>)收取账号激活邮件。
点击邮件中的激活链接,方可使用该账号 +

请登录邮箱(<%= @user.mail %>)收取账号激活邮件。
点击邮件中的激活链接,方可使用该账号

<%= l(:label_check_email)%>     <%= link_to "".html_safe, { :controller => 'account', :action => 'resendmail', :user => @user}, :remote => true, :method => 'get' %>

+