From f342c585c6b7404b43ba78bc00a6d68d14ae56a4 Mon Sep 17 00:00:00 2001 From: manson Date: Mon, 28 Apr 2014 10:23:24 +0800 Subject: [PATCH 1/8] Fix mobile page 500 error when there's no adbanner named "Home" --- app/views/mobile/index.mobile.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/mobile/index.mobile.erb b/app/views/mobile/index.mobile.erb index 57c3043..b6f4e7c 100644 --- a/app/views/mobile/index.mobile.erb +++ b/app/views/mobile/index.mobile.erb @@ -1,8 +1,11 @@ +<% unless @ad_banner.nil? %>
<% @ad_banner.ad_images.can_display.each do |image| %> <%= image_tag image.file.url, width: @ad_banner.width, height: @ad_banner.height %> <% end %>
+<% end %> +
<% @bulletins.each do |bulletin| %>
@@ -17,6 +20,8 @@
<% end %>
+ + <% unless @ad_banner.nil? %> +<% end %> From e5293acee5c6f674e22dc882e3041f141cf562d7 Mon Sep 17 00:00:00 2001 From: manson Date: Mon, 28 Apr 2014 10:49:41 +0800 Subject: [PATCH 2/8] Ignore compressed log files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 84ef7b1..64800a8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Gemfile.lock db/*.sqlite3 log/*.log +log/*.gz public/assets public/index.html public/panel/**/* From 7bb1b48c25afc2b3bcbde0b4e1b9589d30a6200c Mon Sep 17 00:00:00 2001 From: spen Date: Fri, 2 May 2014 13:54:49 +0800 Subject: [PATCH 3/8] fix reset password --- app/mailer/user_mailer.rb | 34 ++++++++++++++++++- .../confirmation_instructions.html.erb | 5 +++ .../reset_password_instructions.html.erb | 8 +++++ .../user_mailer/unlock_instructions.html.erb | 7 ++++ config/initializers/devise.rb | 2 +- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 app/views/user_mailer/confirmation_instructions.html.erb create mode 100644 app/views/user_mailer/reset_password_instructions.html.erb create mode 100644 app/views/user_mailer/unlock_instructions.html.erb diff --git a/app/mailer/user_mailer.rb b/app/mailer/user_mailer.rb index 8a5a6e6..eca096e 100644 --- a/app/mailer/user_mailer.rb +++ b/app/mailer/user_mailer.rb @@ -1,3 +1,35 @@ class UserMailer < Devise::Mailer - default :from => "noreply@rulingcom.com" + + # default :from => "noreply@rulingcom.com" + + @site = Site.first + + @smtp_settings = { + :address => @site['site_settings']['address'], + :port => @site['site_settings']['port'], + :domain => @site['site_settings']['domain'], + :authentication => @site['site_settings']['authentication'], + :enable_starttls_auto => @site['site_settings']['enable_starttls_auto'] + } + + if !@site['site_settings']['user_name'].blank? + @smtp_settings[:user_name] = @site['site_settings']['user_name'] + end + + if !@site['site_settings']['password'].blank? + @smtp_settings[:password] = @site['site_settings']['password'] + end + + if !@site['site_settings']['service_email'].blank? + @smtp_settings[:from] = @site['site_settings']['service_email'] + Devise.mailer_sender = @site['site_settings']['service_email'] + end + + if !@site['site_settings']['reply_email'].blank? + @smtp_settings[:reply_to] = @site['site_settings']['reply_email'] + end + + + ActionMailer::Base.smtp_settings = @smtp_settings + end \ No newline at end of file diff --git a/app/views/user_mailer/confirmation_instructions.html.erb b/app/views/user_mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..a6ea8ca --- /dev/null +++ b/app/views/user_mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @resource.email %>!

+ +

You can confirm your account through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

diff --git a/app/views/user_mailer/reset_password_instructions.html.erb b/app/views/user_mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..ae9e888 --- /dev/null +++ b/app/views/user_mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password, and you can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/user_mailer/unlock_instructions.html.erb b/app/views/user_mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..2263c21 --- /dev/null +++ b/app/views/user_mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive amount of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>

diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index cfc7857..6dae797 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -6,7 +6,7 @@ Devise.setup do |config| config.mailer_sender = "noreply@rulingcom.com" # Configure the class responsible to send e-mails. - config.mailer = "Devise::Mailer" + config.mailer = "UserMailer" # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and From 1bf4d5599252ef8074a80644eaf094d25f51c54c Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 28 May 2014 13:39:22 +0800 Subject: [PATCH 4/8] Fix resque-scheduler version, 3.0.0 is not compatible --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0a0fa3f..7dda595 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,7 @@ gem 'radius' gem 'rake' # gem 'remotipart' gem 'resque', :require => 'resque/server' # background jobs -gem 'resque-scheduler' # job scheduling +gem 'resque-scheduler', '2.5.5' # job scheduling gem 'resque-restriction' #gem 'rb-readline' # gem 'ruby-debug19' From 7022adc11f16ab8c47b801c3796e3c5a4999dda0 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Tue, 10 Jun 2014 15:26:34 +0800 Subject: [PATCH 5/8] Update site search chinese input issue, add pagination, user feed back and performance --- .../stylesheets/basic/orbit_bar.css.erb | 19 ++- app/controllers/site_search_controller.rb | 12 +- app/views/layouts/_search.erb | 112 +++++++++++++----- 3 files changed, 106 insertions(+), 37 deletions(-) diff --git a/app/assets/stylesheets/basic/orbit_bar.css.erb b/app/assets/stylesheets/basic/orbit_bar.css.erb index 082e63d..290f61f 100644 --- a/app/assets/stylesheets/basic/orbit_bar.css.erb +++ b/app/assets/stylesheets/basic/orbit_bar.css.erb @@ -169,11 +169,21 @@ } #search_footer{ - height: 10px; + min-height: 10px; padding: 5px 25px 5px 10px; + border-top: 1px solid #DDD; border-bottom: 1px solid #CCC; color: #666; - /*background: #DDD;*/ + background: #EEE; +} + +#search_footer .pagination{ + margin: 0; +} + +#search_footer .pagination ul li a{ + padding: 4px 10px; + color: #0053CF; } #search_results{ @@ -181,7 +191,10 @@ overflow-y: auto; overflow-x: hidden; } - +#search_results img{ + margin: 20px auto; + display: block; +} #search_results::-webkit-scrollbar { width: 8px; background: #CCC; diff --git a/app/controllers/site_search_controller.rb b/app/controllers/site_search_controller.rb index 307d21d..7d21359 100644 --- a/app/controllers/site_search_controller.rb +++ b/app/controllers/site_search_controller.rb @@ -8,6 +8,7 @@ class SiteSearchController < ApplicationController ] key_string = params[:keywords] + key_string = key_string.strip.nil? ? key_string : key_string.strip keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")}) @@ -45,7 +46,8 @@ class SiteSearchController < ApplicationController tmp[:content] = "" tmp[:matches] = 0 mod[:fields].each do |f| - value = eval("r.#{f}").gsub(/<\/?[^>]*>/, "").gsub(/ /i,"") rescue "" + value = ActionView::Base.full_sanitizer.sanitize(eval("r.#{f}")) rescue "" + value = value.nil? ? "" : value if f=="title" or f=="name" tmp[:title] = value @@ -62,11 +64,11 @@ class SiteSearchController < ApplicationController result.each do |res| res[:matches] = 0 - res[:matches] += res[:title].match(/(#{key_string})/i) ? 100 : 0 rescue 0 - res[:matches] += res[:content].match(/(#{key_string})/i) ? 100 : 0 rescue 0 + res[:matches] += res[:title].match(/(#{key_string})/i) ? 500 : 0 rescue 0 + res[:matches] += res[:content].match(/(#{key_string})/i) ? 300 : 0 rescue 0 keywords.each do |k| - res[:matches] += res[:title].scan(/(#{k})/i).size + res[:content].scan(/(#{k})/i).size + res[:matches] += (res[:title].scan(/(#{k})/i).size)*100 + res[:content].scan(/(#{k})/i).size res[:title].gsub!(/(#{k})/i, '\1') rescue "" res[:content].gsub!(/(#{k})/i, '\1') rescue "" end @@ -76,7 +78,7 @@ class SiteSearchController < ApplicationController next end - res[:content] = truncate(res[:content], length: 150) + res[:content] = truncate(res[:content], length: 120) end result = result.sort_by { |k| k[:matches] }.reverse rescue [] diff --git a/app/views/layouts/_search.erb b/app/views/layouts/_search.erb index d4c7ba9..c6381fc 100644 --- a/app/views/layouts/_search.erb +++ b/app/views/layouts/_search.erb @@ -3,18 +3,28 @@
-
- +
+
+ \ No newline at end of file From f3bb20ee45d88066967d2f9633d6ca1145a9339f Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 11 Jun 2014 16:00:28 +0800 Subject: [PATCH 6/8] Fix slow impressionist count --- app/models/page.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index 1b6ef08..f36f608 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -3,14 +3,14 @@ class Page < Item include Impressionist::Impressionable include ParserFrontEnd - is_impressionable :counter_cache => { :column_name => :view_count } + is_impressionable field :content, localize: true field :app_frontend_url # field :theme_id, :type => BSON::ObjectId, :default => nil field :category,type: Array, :default => [] field :tag, type: Array,:default => [] - field :view_count, :type => Integer, :default => 0 + # field :view_count, :type => Integer, :default => 0 field :page_title, localize: true field :frontend_style @@ -65,6 +65,10 @@ class Page < Item end end + def view_count + self.impression_count + end + protected def create_parts @@ -97,15 +101,15 @@ class Page < Item end def delete_empty_frontend_field - if self.frontend_field + if self.frontend_field self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) } - # self.frontend_field.each do | ff | - # if ff[0].blank? || ff[1].blank? + # self.frontend_field.each do | ff | + # if ff[0].blank? || ff[1].blank? # self.frontend_field.delete("") if self.frontend_field # self.frontend_field.delete(ff) - # end - # end - end + # end + # end + end end def generate_html From 97738b0e63d36770f66f12f9321dd550887a6138 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Tue, 1 Apr 2014 16:40:05 +0800 Subject: [PATCH 7/8] fgu --- app/controllers/sessions_controller.rb | 59 ++++++++ app/jobs/get_remote_announcement.rb | 7 + config/resque_schedule.yml | 6 + config/routes.rb | 2 +- lib/remote_announcement.rb | 181 +++++++++++++++++++++++++ 5 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/jobs/get_remote_announcement.rb create mode 100644 lib/remote_announcement.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..2397fef --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,59 @@ +# encoding: utf-8 + +class SessionsController < Devise::SessionsController + prepend_before_filter :require_no_authentication, :only => [ :new, :create ] + + require 'net/http' + require 'uri' + + def create + + @user_id = params[:user][:user_id] + + if @user_id == 'rulingcom' + + resource = User.first(conditions:{user_id: @user_id}) + + if !resource.blank? + + resource_name = resource.class.to_s.downcase + sign_in(resource_name, resource) + redirect_to after_sign_in_path_for(resource) + + else + + flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator." + redirect_to :root + + end + + else + + uri = URI('http://www.fgu.edu.tw/cgi-bin/check_intrant.pl') + response = Net::HTTP.post_form(uri, 'username' => @user_id, 'password' => params[:user][:password]) + @response = response.body + + if @response.include?("username=#{@user_id}") + + resource = User.first(conditions:{user_id: @user_id}) + + if !resource.blank? + resource_name = resource.class.to_s.downcase + sign_in(resource_name, resource) + redirect_to after_sign_in_path_for(resource) + else + flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator." + redirect_to :root + end + + else + flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator." + redirect_to :root + end + + end + + end + + +end \ No newline at end of file diff --git a/app/jobs/get_remote_announcement.rb b/app/jobs/get_remote_announcement.rb new file mode 100644 index 0000000..6c6f621 --- /dev/null +++ b/app/jobs/get_remote_announcement.rb @@ -0,0 +1,7 @@ +class GetRemoteAnnouncement + @queue = :high + + def self.perform() + %x(ruby "#{Rails.root}/lib/remote_announcement.rb") + end +end \ No newline at end of file diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index d6a7e83..3edd445 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -15,3 +15,9 @@ email_cron: class: EmailCron args: description: EmailCron + +get_remote_announcement: + cron: 0 * * * * * + class: GetRemoteAnnouncement + args: + description: GetRemoteAnnouncement \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b1c81d0..edb8f8c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ Orbit::Application.routes.draw do # get "robots.txt" => 'robots#index' - devise_for :users, :controllers => { :registrations => "registrations", :passwords => 'passwords', :confirmations => 'confirmations' } do + devise_for :users, :controllers => { :sessions => 'sessions', :registrations => "registrations", :passwords => 'passwords', :confirmations => 'confirmations' } do resources :passwords, :except => [:index, :show, :destroy] match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put end diff --git a/lib/remote_announcement.rb b/lib/remote_announcement.rb new file mode 100644 index 0000000..01356e7 --- /dev/null +++ b/lib/remote_announcement.rb @@ -0,0 +1,181 @@ +require 'mongo' +require 'open-uri' +require 'json' +require 'date' + +@db = Mongo::Connection.new("localhost", 27017).db("fgu_new") +@coll_bulletin = @db["bulletins"] +@bulletin_links = @db["bulletin_links"] +@coll_cat = @db["categories"] +@updated_bulletins = Array.new + + + + +bulletin_module_id = @db["module_apps"].find(key: "announcement").first + +coll_bulletin = @db["bulletins"] +@coll_buffer_cat = @db["buffer_categories"] +coll_cat = @db["categories"] +coll_bulletin_cat = @db["categories"].find(module_app_id: bulletin_module_id["_id"]) + +@categories = coll_bulletin_cat.find().to_a.inject({}) do |categories, category| +categories[category['key']] = category['_id'] +categories +end + + +# @categories = @coll_cat.find().to_a.inject({}) do |categories, category| +# categories[category['key']] = category['_id'] +# categories +# end + + +def save_bulletin_links bulletin_id, title, url, c_time + + title = "Link" if title == '' + + bulletin_link = { + title: {"zh_tw" => title, "en" => title }, + url: url, + bulletin_id: bulletin_id, + created_at: c_time, + updated_at: c_time + } + @bulletin_links.save(bulletin_link) + +end + +def get_remote_bulletins_json(url) + data = "" + open(url){|f| f.each_line {|line| data << line} } + + bulletins = JSON.parse data + + bulletins.each do |b| + + lang = b[1]=='zh-tw' ? "zh_tw".to_sym : "en".to_sym + + next if b[2]=="" + next if @categories["#{b[7]}"].nil? + + if b[5]=="" and b[4]!="" + b[5]=b[4] + b[4]="" + end + + bulletin = { _type: "Bulletin", + postdate: Time.parse(b[8]), + created_at: Time.parse(b[8]), + updated_at: Time.parse(b[8]), + is_checked: true, + is_pending: false, + is_rejected: false, + category_id: @categories["#{b[7]}"], + title: {lang => b[2]}, + subtitle: {lang => b[4]}, + text: {lang => b[5]}, + available_for_zh_tw: true, + available_for_en: true, + create_user_id: "", + public: true, + sn: b[0], + site: b[9], + site_id: b[10], + is_top: false, + is_hot: false, + is_hidden: false } + + this_bulletin = @coll_bulletin.find_one(:$and => [{ :sn => bulletin[:sn]},{ :site => bulletin[:site]}]) + @updated_bulletins.push({:sn => bulletin[:sn],:site => bulletin[:site] }) + # p bulletin + + unless this_bulletin + bs = @coll_bulletin.save(bulletin) + + buffer_cat = { _type: "BufferCategory", + category_id: @categories["#{b[7]}"], + categorizable_type: "Bulletin", + categorizable_id: bs } + @coll_buffer_cat.save(buffer_cat) + + + #files + (10..14).each do |i| + ta = i + 5 + save_bulletin_links( bulletin[:_id], b[ta], b[i], bulletin[:created_at] ) if b[i] != '' + end + + #url + save_bulletin_links( bulletin[:_id], '', b[20], bulletin[:created_at] ) if b[20] != '' + + # puts "Inserted "+lang.to_s+" "+bulletin[:title][lang] + # p bulletin + else + @coll_bulletin.update( + {"_id"=>this_bulletin["_id"]}, + { + :_type => "Bulletin", + :postdate => bulletin[:postdate], + :created_at => bulletin[:created_at], + :updated_at => bulletin[:updated_at], + :is_checked => this_bulletin["is_checked"], + :is_pending => this_bulletin["is_pending"], + :is_rejected => this_bulletin["is_rejected"], + :category_id => bulletin[:category_id], + :title => bulletin[:title], + :subtitle => bulletin[:subtitle], + :text => bulletin[:text], + :available_for_zh_tw => this_bulletin["available_for_zh_tw"], + :available_for_en => this_bulletin["available_for_en"], + :create_user_id => "", + :public => this_bulletin["public"], + :sn => bulletin[:sn], + :site => bulletin[:site], + :site_id => bulletin[:site_id], + :is_top => this_bulletin["is_top"], + :is_hot => this_bulletin["is_hot"], + :is_hidden => this_bulletin["is_hidden"] + }) + + + @coll_buffer_cat.remove(categorizable_id: BSON::ObjectId(this_bulletin["_id"].to_s) ) + + buffer_cat = { _type: "BufferCategory", + category_id: bulletin[:category_id], + categorizable_type: "Bulletin", + categorizable_id: this_bulletin["_id"] } + @coll_buffer_cat.save(buffer_cat) + + @bulletin_links.remove(bulletin_id: BSON::ObjectId(this_bulletin["_id"].to_s) ) + + #files + (10..14).each do |i| + ta = i + 5 + save_bulletin_links( this_bulletin["_id"], b[ta], b[i], this_bulletin["created_at"] ) if b[i] != '' + end + + #url + save_bulletin_links( this_bulletin["_id"], '', b[20], bulletin[:created_at] ) if b[20] != '' + + # puts "Updated "+lang.to_s+" "+bulletin[:title][lang] + # p this_bulletin["_id"] + end + end +end + +get_remote_bulletins_json("http://president.fgu.edu.tw/remote_annoucement/get_news2.php") +get_remote_bulletins_json("http://car.fgu.edu.tw/remote_annoucement/get_news2.php") + +# Delete bulletins that had been removed form remote sites +# Find all remote bulletins on server +local_bulletins = @coll_bulletin.find({ site: { :$exists => true } }) + +# Check if each remote bulletins on server exist in the updated bulletins +local_bulletins.each do |local_bulletin| + result = @updated_bulletins.select {|remote_bulletin| remote_bulletin[:sn] == local_bulletin["sn"] and remote_bulletin[:site] == local_bulletin["site"]} + if result.length == 0 + @coll_bulletin.remove(:$and => [{ :sn => local_bulletin["sn"]},{ :site => local_bulletin["site"]}]) + p "Delete: "+local_bulletin["site"]+"-"+local_bulletin["sn"] + end +end \ No newline at end of file From 17dcbe95f175a51d182ebfcb77beaf93cb690d96 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Tue, 8 Apr 2014 18:13:03 +0800 Subject: [PATCH 8/8] fix login --- app/controllers/sessions_controller.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2397fef..d4db64b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -10,16 +10,23 @@ class SessionsController < Devise::SessionsController @user_id = params[:user][:user_id] + @user_password = params[:user][:password] + if @user_id == 'rulingcom' resource = User.first(conditions:{user_id: @user_id}) - - if !resource.blank? + + if !resource.blank? and resource.valid_password?(@user_password) resource_name = resource.class.to_s.downcase sign_in(resource_name, resource) redirect_to after_sign_in_path_for(resource) + elsif !resource.valid_password?(@user_password) + + flash[:error] = "密碼錯誤
password Local fail" + redirect_to :root + else flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員
Sorry, you don't have the account or authority to login. Please contact the website administrator."