From 86af2330425b927cac93a2d31e78450b6a2c5194 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 5 May 2015 11:45:58 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E4=BF=AE=E6=AD=A3autologin=E5=A4=9A?= =?UTF-8?q?=E7=BB=88=E7=AB=AF=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 5 +---- app/controllers/application_controller.rb | 18 +++++++++--------- app/controllers/my_controller.rb | 4 +++- app/models/token.rb | 17 +++++++++++++++-- config/environments/development.rb | 2 +- config/initializers/session_store.rb | 2 +- db/schema.rb | 10 ---------- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 22db3d5b4..981e0cb3c 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -31,9 +31,6 @@ class AccountController < ApplicationController else authenticate_user end - rescue AuthSourceException => e - logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" - render_error :message => e.message end # Log out current user and redirect to welcome page @@ -329,7 +326,7 @@ class AccountController < ApplicationController end def set_autologin_cookie(user) - token = Token.create(:user => user, :action => 'autologin') + token = Token.get_or_create_permanent_login_token(user) cookie_options = { :value => token.value, :expires => 7.days.from_now, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 741af2aee..0dc86fb01 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -156,16 +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 - + user = User.try_to_autologin(params[:token]) + if user + logout_user if User.current.id != user.id + start_user_session(user) + end + user end + # Sets the logged in user def logged_user=(user) reset_session @@ -200,7 +200,7 @@ class ApplicationController < ActionController::Base def logout_user if User.current.logged? cookies.delete(autologin_cookie_name) - Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) + # Token.delete_all(["user_id = ? AND action = ?", User.current.id, 'autologin']) self.logged_user = nil end end diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index d42a750a1..8c76da1a9 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -200,7 +200,9 @@ class MyController < ApplicationController @user = us.change_password params.merge(:current_user_id => @user.id) if @user.errors.full_messages.count <= 0 flash.now[:notice] = l(:notice_account_password_updated) - redirect_to my_account_url + # 修改完密码,让其重新登录,并更新Token + Token.delete_user_all_tokens(@user) + redirect_to logout_url end end rescue Exception => e diff --git a/app/models/token.rb b/app/models/token.rb index c89ff30bc..d9fc75d76 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,3 +1,4 @@ +#coding=utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -14,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - +# class Token < ActiveRecord::Base belongs_to :user validates_uniqueness_of :value @@ -27,6 +28,14 @@ class Token < ActiveRecord::Base self.value = Token.generate_token_value end + def self.get_or_create_permanent_login_token(user) + token = Token.get_token_from_user(user, 'autologin') + unless token + token = Token.create(:user => user, :action => 'autologin') + end + token + end + def self.get_token_from_user(user, action) token = Token.where(:action => action, :user_id => user).first unless token @@ -42,7 +51,7 @@ class Token < ActiveRecord::Base # Delete all expired tokens def self.destroy_expired - Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time] + Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api', 'autologin'], Time.now - @@validity_time] end # Returns the active user who owns the key for the given action @@ -80,6 +89,10 @@ class Token < ActiveRecord::Base Redmine::Utils.random_hex(20) end + def self.delete_user_all_tokens(user) + Token.delete_all(user_id: user.id) + end + private # Removes obsolete tokens (same user and action) diff --git a/config/environments/development.rb b/config/environments/development.rb index 5c2427320..1b653d929 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,7 +11,7 @@ RedmineApp::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false - config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" + # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 3d06070a2..1d3a65f8b 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1 +1 @@ -Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes, :key => '_trustie_session', :domain => :all +Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 90.minutes, :key => '_trustie_session', :domain => :all diff --git a/db/schema.rb b/db/schema.rb index 006b26e91..dcbe017fb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -654,16 +654,6 @@ ActiveRecord::Schema.define(:version => 20150428021035) do add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" - create_table "journal_details_copy", :force => true do |t| - t.integer "journal_id", :default => 0, :null => false - t.string "property", :limit => 30, :default => "", :null => false - t.string "prop_key", :limit => 30, :default => "", :null => false - t.text "old_value" - t.text "value" - end - - add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id" - create_table "journal_replies", :id => false, :force => true do |t| t.integer "journal_id" t.integer "user_id" From 05428213a269bce7932e8bf648bfc1044e8da249 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 May 2015 11:04:57 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E8=AE=A9session=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=95=BF=E6=97=B6=E9=97=B4=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=97=B6session=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 4 ++++ config/routes.rb | 2 ++ public/javascripts/application.js | 11 +++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 981e0cb3c..3089386bf 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -44,6 +44,10 @@ class AccountController < ApplicationController # display the logout form end + def heartbeat + render :json => session[:user_id] + end + # Lets user choose a new password def lost_password (redirect_to(home_url); return) unless Setting.lost_password? diff --git a/config/routes.rb b/config/routes.rb index d3b8a1b37..ae87c6a65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -227,6 +227,8 @@ RedmineApp::Application.routes.draw do match '/projects/search', :via => [:get, :post] match '/users/search', :via => [:get, :post] #end + + match 'account/heartbeat', to: 'account#heartbeat', :via => :get match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post] match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post] match 'account/register', :via => [:get, :post], :as => 'register' diff --git a/public/javascripts/application.js b/public/javascripts/application.js index f61738935..b2bd70d8d 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -571,10 +571,16 @@ function warnLeavingUnsaved(message) { }; } +function setupHeartBeat(){ + var time = 60*1000*30; // 30 mins + setInterval(function(){$.getJSON('/account/heartbeat');},time); +} + function setupAjaxIndicator() { - $('#ajax-indicator').bind('ajaxSend', function(event, xhr, settings) { - + if(settings && settings.url && settings.url.endsWith('account/heartbeat')){ + return; + } if ($('.ajax-loading').length === 0 && settings.contentType != 'application/octet-stream') { $('#ajax-indicator').show(); } @@ -622,6 +628,7 @@ function transpotUrl (scope) { } $(document).ready(setupAjaxIndicator); +$(document).ready(setupHeartBeat); $(document).ready(hideOnLoad); $(document).ready(addFormObserversForDoubleSubmit); From 297cb9182ee7c762aac8998f63a35a8111c78407 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 May 2015 11:08:33 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E9=87=87=E7=94=A8filecache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/environments/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 1b653d929..5c2427320 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -11,7 +11,7 @@ RedmineApp::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false - # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" + config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true From 9ba55296f59f37d2f07389e130484cc9cd283826 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 May 2015 15:17:42 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=90=8E=E8=B7=B3=E5=88=B0=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/my_controller.rb | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 8c76da1a9..d4f98749a 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -202,31 +202,18 @@ class MyController < ApplicationController flash.now[:notice] = l(:notice_account_password_updated) # 修改完密码,让其重新登录,并更新Token Token.delete_user_all_tokens(@user) - redirect_to logout_url + logout_user + redirect_to signin_url(back_url: my_account_path) + else + flash.now[:error] = l(:notice_account_wrong_password) end end rescue Exception => e if e.message == 'wrong password' flash.now[:error] = l(:notice_account_wrong_password) + else + flash.now[:error] = e.message end - # @user = User.current - # unless @user.change_password_allowed? - # flash.now[:error] = l(:notice_can_t_change_password) - # redirect_to my_account_url - # return - # end - # if request.post? - # if @user.check_password?(params[:password]) - # @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] - # - # if @user.save - # flash.now[:notice] = l(:notice_account_password_updated) - # redirect_to my_account_url - # end - # else - # flash.now[:error] = l(:notice_account_wrong_password) - # end - # end end # Create a new feeds key From 3f88a67eef7a9cb3772b58bc169d22ddaaf42b17 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 May 2015 23:32:34 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9B=B4=E6=8E=A5=E7=B2=98=E8=B4=B4QQ=E6=88=AA?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/rails_kindeditor/helper.rb | 4 +- .../assets/kindeditor/plugins/paste/paste.js | 37 +++ public/javascripts/paste.js | 292 ++++++++++++++++++ 3 files changed, 331 insertions(+), 2 deletions(-) create mode 100644 public/assets/kindeditor/plugins/paste/paste.js create mode 100644 public/javascripts/paste.js diff --git a/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb b/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb index 33d44a2ec..56b4c7adf 100644 --- a/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb +++ b/lib/rails_kindeditor/lib/rails_kindeditor/helper.rb @@ -55,7 +55,7 @@ module RailsKindeditor }" else "KindEditor.ready(function(K){ - #{editor_id}K.create('##{dom_id}', #{get_options(options).to_json}); + #{editor_id}K.create('##{dom_id}', #{get_options(options).to_json}).loadPlugin('paste'); });" end end @@ -101,4 +101,4 @@ module RailsKindeditor @template.send("kindeditor", @object_name, method, objectify_options(options)) end end -end \ No newline at end of file +end diff --git a/public/assets/kindeditor/plugins/paste/paste.js b/public/assets/kindeditor/plugins/paste/paste.js new file mode 100644 index 000000000..0f63ce18c --- /dev/null +++ b/public/assets/kindeditor/plugins/paste/paste.js @@ -0,0 +1,37 @@ +KindEditor.plugin('paste', function(K) { + var editor = this, + name = 'paste'; + var contentWindow = document.getElementsByTagName('iframe')[0].contentWindow; + contentWindow.document.getElementsByTagName('body')[0].onpaste = function(event) { + // use event.originalEvent.clipboard for newer chrome versions + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + console.log(JSON.stringify(items)); // will give you the mime types + // find pasted image among pasted items + var blob = null; + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + blob = items[i].getAsFile(); + } + } + // load image if there is a pasted image + if (blob !== null) { + var reader = new FileReader(); + reader.onload = function(event) { + console.log(event.target.result); // data url! + var data = new FormData(); + data.append("imgFile", blob, "imageFilename.png"); + $.ajax({ + url: '/kindeditor/upload?dir=image', + contentType: false, + type: 'POST', + data: data, + processData: false, + success: function(data) { + editor.exec('insertimage', JSON.parse(data).url); + } + }); + }; + reader.readAsDataURL(blob); + } + } +}); diff --git a/public/javascripts/paste.js b/public/javascripts/paste.js new file mode 100644 index 000000000..961a29acb --- /dev/null +++ b/public/javascripts/paste.js @@ -0,0 +1,292 @@ +// Generated by CoffeeScript 1.9.0 + +/* +paste.js is an interface to read data ( text / image ) from clipboard in different browsers. It also contains several hacks. + +https://github.com/layerssss/paste.js + */ + +(function() { + var $, Paste, createHiddenEditable, dataURLtoBlob; + + $ = window.jQuery; + + $.paste = function(pasteContainer) { + var pm; + if (typeof console !== "undefined" && console !== null) { + console.log("DEPRECATED: This method is deprecated. Please use $.fn.pastableNonInputable() instead."); + } + pm = Paste.mountNonInputable(pasteContainer); + return pm._container; + }; + + $.fn.pastableNonInputable = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountNonInputable(el); + } + return this; + }; + + $.fn.pastableTextarea = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountTextarea(el); + } + return this; + }; + + $.fn.pastableContenteditable = function() { + var el, _i, _len; + for (_i = 0, _len = this.length; _i < _len; _i++) { + el = this[_i]; + Paste.mountContenteditable(el); + } + return this; + }; + + dataURLtoBlob = function(dataURL, sliceSize) { + var b64Data, byteArray, byteArrays, byteCharacters, byteNumbers, contentType, i, m, offset, slice, _ref; + if (sliceSize == null) { + sliceSize = 512; + } + if (!(m = dataURL.match(/^data\:([^\;]+)\;base64\,(.+)$/))) { + return null; + } + _ref = m, m = _ref[0], contentType = _ref[1], b64Data = _ref[2]; + byteCharacters = atob(b64Data); + byteArrays = []; + offset = 0; + while (offset < byteCharacters.length) { + slice = byteCharacters.slice(offset, offset + sliceSize); + byteNumbers = new Array(slice.length); + i = 0; + while (i < slice.length) { + byteNumbers[i] = slice.charCodeAt(i); + i++; + } + byteArray = new Uint8Array(byteNumbers); + byteArrays.push(byteArray); + offset += sliceSize; + } + return new Blob(byteArrays, { + type: contentType + }); + }; + + createHiddenEditable = function() { + return $(document.createElement('div')).attr('contenteditable', true).css({ + width: 1, + height: 1, + position: 'fixed', + left: -100, + overflow: 'hidden' + }); + }; + + Paste = (function() { + Paste.prototype._target = null; + + Paste.prototype._container = null; + + Paste.mountNonInputable = function(nonInputable) { + var paste; + paste = new Paste(createHiddenEditable().appendTo(nonInputable), nonInputable); + $(nonInputable).on('click', (function(_this) { + return function() { + return paste._container.focus(); + }; + })(this)); + paste._container.on('focus', (function(_this) { + return function() { + return $(nonInputable).addClass('pastable-focus'); + }; + })(this)); + return paste._container.on('blur', (function(_this) { + return function() { + return $(nonInputable).removeClass('pastable-focus'); + }; + })(this)); + }; + + Paste.mountTextarea = function(textarea) { + var ctlDown, paste; + if (-1 !== navigator.userAgent.toLowerCase().indexOf('chrome')) { + return this.mountContenteditable(textarea); + } + paste = new Paste(createHiddenEditable().insertBefore(textarea), textarea); + ctlDown = false; + $(textarea).on('keyup', function(ev) { + var _ref; + if ((_ref = ev.keyCode) === 17 || _ref === 224) { + return ctlDown = false; + } + }); + $(textarea).on('keydown', function(ev) { + var _ref; + if ((_ref = ev.keyCode) === 17 || _ref === 224) { + ctlDown = true; + } + if (ctlDown && ev.keyCode === 86) { + return paste._container.focus(); + } + }); + $(paste._target).on('pasteImage', (function(_this) { + return function() { + return $(textarea).focus(); + }; + })(this)); + $(paste._target).on('pasteText', (function(_this) { + return function() { + return $(textarea).focus(); + }; + })(this)); + $(textarea).on('focus', (function(_this) { + return function() { + return $(textarea).addClass('pastable-focus'); + }; + })(this)); + return $(textarea).on('blur', (function(_this) { + return function() { + return $(textarea).removeClass('pastable-focus'); + }; + })(this)); + }; + + Paste.mountContenteditable = function(contenteditable) { + var paste; + paste = new Paste(contenteditable, contenteditable); + $(contenteditable).on('focus', (function(_this) { + return function() { + return $(contenteditable).addClass('pastable-focus'); + }; + })(this)); + return $(contenteditable).on('blur', (function(_this) { + return function() { + return $(contenteditable).removeClass('pastable-focus'); + }; + })(this)); + }; + + function Paste(_at__container, _at__target) { + this._container = _at__container; + this._target = _at__target; + this._container = $(this._container); + this._target = $(this._target).addClass('pastable'); + this._container.on('paste', (function(_this) { + return function(ev) { + var clipboardData, file, item, reader, text, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3, _results; + if (((_ref = ev.originalEvent) != null ? _ref.clipboardData : void 0) != null) { + clipboardData = ev.originalEvent.clipboardData; + if (clipboardData.items) { + _ref1 = clipboardData.items; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + item = _ref1[_i]; + if (item.type.match(/^image\//)) { + reader = new FileReader(); + reader.onload = function(event) { + return _this._handleImage(event.target.result); + }; + reader.readAsDataURL(item.getAsFile()); + } + if (item.type === 'text/plain') { + item.getAsString(function(string) { + return _this._target.trigger('pasteText', { + text: string + }); + }); + } + } + } else { + if (-1 !== Array.prototype.indexOf.call(clipboardData.types, 'text/plain')) { + text = clipboardData.getData('Text'); + _this._target.trigger('pasteText', { + text: text + }); + } + _this._checkImagesInContainer(function(src) { + return _this._handleImage(src); + }); + } + } + if (clipboardData = window.clipboardData) { + if ((_ref2 = (text = clipboardData.getData('Text'))) != null ? _ref2.length : void 0) { + return _this._target.trigger('pasteText', { + text: text + }); + } else { + _ref3 = clipboardData.files; + _results = []; + for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { + file = _ref3[_j]; + _this._handleImage(URL.createObjectURL(file)); + _results.push(_this._checkImagesInContainer(function() {})); + } + return _results; + } + } + }; + })(this)); + } + + Paste.prototype._handleImage = function(src) { + var loader; + loader = new Image(); + loader.onload = (function(_this) { + return function() { + var blob, canvas, ctx, dataURL; + canvas = document.createElement('canvas'); + canvas.width = loader.width; + canvas.height = loader.height; + ctx = canvas.getContext('2d'); + ctx.drawImage(loader, 0, 0, canvas.width, canvas.height); + dataURL = null; + try { + dataURL = canvas.toDataURL('image/png'); + blob = dataURLtoBlob(dataURL); + } catch (_error) {} + if (dataURL) { + return _this._target.trigger('pasteImage', { + blob: blob, + dataURL: dataURL, + width: loader.width, + height: loader.height + }); + } + }; + })(this); + return loader.src = src; + }; + + Paste.prototype._checkImagesInContainer = function(cb) { + var img, timespan, _i, _len, _ref; + timespan = Math.floor(1000 * Math.random()); + _ref = this._container.find('img'); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + img = _ref[_i]; + img["_paste_marked_" + timespan] = true; + } + return setTimeout((function(_this) { + return function() { + var _j, _len1, _ref1, _results; + _ref1 = _this._container.find('img'); + _results = []; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + img = _ref1[_j]; + if (!img["_paste_marked_" + timespan]) { + cb(img.src); + } + _results.push($(img).remove()); + } + return _results; + }; + })(this), 1); + }; + + return Paste; + + })(); + +}).call(this); From 559b5ce7ab7d8f7684c856eb4b3c4a4032e30ac6 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 8 May 2015 10:02:14 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E6=89=93=E5=BC=80=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E5=9C=A8=E6=96=B0=E7=9A=84=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/issues/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index f1b5a319d..30bd06b9a 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -12,7 +12,7 @@ <%= link_to issue.author.name, user_path(issue.author), :class => "problem_name c_orange fl" %> <%= l(:label_post_on_issue) %>(<%= "#{raw column_content[2]}" %>):
- <%=link_to "#{column_content[4]}#{get_issue_typevalue(column_content[1])}".html_safe, issue_path(issue.id), :class => "problem_tit_a break_word" %> + <%=link_to "#{column_content[4]}#{get_issue_typevalue(column_content[1])}".html_safe, issue_path(issue.id), :class => "problem_tit_a break_word",:target => "_blank" %>

From 34dbde442d099734a99434d85bc48bcc0770b10b Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 8 May 2015 14:23:57 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/boards/_course_show.html.erb | 210 +++++++------------------ 1 file changed, 53 insertions(+), 157 deletions(-) diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index c55bb8336..e4db6bef1 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -1,26 +1,28 @@ - +

-

- <% if User.current.language == "zh"%> - <%= h @board.name %> - <% else %> - <%= l(:project_module_boards) %> - <% end %> - -

- <%= l(:label_message_new) %> -
+

<%= l(:label_board_plural) %>

- -
-
-
- -
+ <% if !User.current.logged?%>
@@ -29,150 +31,44 @@
<% end %> -

讨论区共有<%= @topic_count %>个帖子

- <% if @topics.any? %> - <% @topics.each do |topic| %> -
- <%= link_to image_tag(url_to_avatar(topic.author), :width=>"42",:height=>"42"), user_path(topic.author),:class =>'talkmain_pic fl' %> -
- <% author = topic.author.to_s + ":" %> - <%= link_to author, user_path(topic.author), :class =>"talkmain_name fl " %> - -

  <%= h(topic.subject) %>

- <% if topic.editable_by?(User.current) %> - <%= l(:button_edit) %> - <% end %> - <% if topic.sticky? %> - <%= l(:label_board_sticky)%> - <% end %> - <%= link_to( - l(:button_delete), - {:controller =>'messages',:action => 'destroy', :id => topic.id, :board_id => topic.board_id, :is_board=>'true'}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'talk_edit fr', - :style => ' margin-right: 10px;' - ) if topic.destroyable_by?(User.current) %> - - -
-

-

- <%= topic.content %> -
- - - - -

- <%= l(:label_activity_time)%>:  <%= format_time topic.created_on %> -
- <%= toggle_link l(:button_reply), "reply" + topic.id.to_s, :focus => 'message_content',:class => ' c_dblue fr' %> - -
-
-
- -
-
- <% reply = Message.new(:subject => "RE: #{@message.subject}")%> - <% if !topic.locked? && authorize_for('messages', 'reply') %> - -
- - <% end %> - <% replies_all = topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC").offset(2). - all %> - <% replies_show = topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC").limit(2). - all %> - <% unless replies_show.empty? %> - <% reply_count = 0 %> -
-
    - <% replies_show.each do |message| %> - -
  • - <%= link_to image_tag(url_to_avatar(message.author), :width => '34',:height => '34'), user_path(message.author), :class =>'Msg_pic' %> -
    - <%= link_to_user_header message.author,false,:class => 'fl c_orange ' %> -
    -

    <%= textAreailizable message,:content,:attachments => message.attachments %>

    - -
    - <%= format_time(message.created_on) %> - <%= link_to( - - l(:button_delete), - {:controller => 'messages', :action => 'destroy', :id => message.id, :board_id => message.board_id, :is_board => 'true'}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :title => l(:button_delete), - :class => ' c_dblue fr' - ) if message.course_destroyable_by?(User.current) %> -
    -
    - -
  • - <% end %> -
-
- - <%if replies_all.first %> - - <% end %> +
+

+ <%= l(:label_totle) %> + <%= @topic_count %> + <%= l(:label_course_momes_count) %> +

+ <%= link_to l(:label_message_new), + new_board_message_path(@board), + :class => 'problem_new_btn fl c_dorange' if User.current.logged? %> +
+
+<% if @topics.any? %> + <% @topics.each do |topic| %> +
+ <%= link_to image_tag(url_to_avatar(topic.author), :width=>"32",:height=>"32"), user_path(topic.author),:class => 'problem_pic talk_pic fl' %> +
+ <%= link_to h(topic.subject), board_message_path(@board, topic),title: topic.subject.to_s,:class => "problem_tit fl fb c_dblue" %> + <% if topic.sticky? %> + 置顶 <% end %> +
+

由<%= link_to topic.author,user_path(topic.author),:class => "problem_name" %>添加于<%= format_time(topic.created_on) %>

- <% end %> - <% else %> -

<%= l(:label_no_data) %>

- <% end %> + <%=link_to (l(:label_reply) + topic.replies_count.to_s), board_message_path(@board, topic),:class => "talk_btn fr c_white" %> + +
+
+ <% end %> +<% else %> +

+ <%= l(:label_no_data) %> +

+<% end %> <%# other_formats_links do |f| %> - <%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> +<%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <%# end %> <% html_title @board.name %> From 05c26aceb64de08f7f7ae0fc77cf03c4972b07e1 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 8 May 2015 14:27:59 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=B0=E8=B4=B4?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_courses.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 8361c3874..2a26ff59f 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -133,7 +133,7 @@ \ No newline at end of file +
+ + + diff --git a/app/views/avatar/upload.js.erb b/app/views/avatar/upload.js.erb index a7a341f10..b39e308ec 100644 --- a/app/views/avatar/upload.js.erb +++ b/app/views/avatar/upload.js.erb @@ -1,4 +1,4 @@ var imgSpan = $('#avatar_image'); -imgSpan.attr({"src":'<%= @urlfile.to_s << "?" << Time.now.to_s%>'}); +imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'}); diff --git a/lib/tasks/avatar.rake b/lib/tasks/avatar.rake new file mode 100644 index 000000000..9fe4f34bb --- /dev/null +++ b/lib/tasks/avatar.rake @@ -0,0 +1,11 @@ +desc "compress and backup avatar" +task :compress_avatar => :environment do + path = File.join(Rails.root, "public/images/avatars/User") + Dir.foreach(path) do |f| + if f.to_s =~ /^\d+$/ + puts f + image = Trustie::Utils::Image.new(File.join(path,f), true) + image.compress(300) + end + end +end diff --git a/lib/trustie.rb b/lib/trustie.rb index ff70d118c..b6cec3c86 100644 --- a/lib/trustie.rb +++ b/lib/trustie.rb @@ -1 +1,2 @@ -require 'trustie/utils' \ No newline at end of file +require 'trustie/utils' +require 'trustie/utils/image' diff --git a/lib/trustie/utils.rb b/lib/trustie/utils.rb index 7d0b2a272..45e5f0028 100644 --- a/lib/trustie/utils.rb +++ b/lib/trustie/utils.rb @@ -17,4 +17,4 @@ end if __FILE__ == $0 puts Trustie::Utils.digest('/Users/guange/Downloads/QQ_V4.0.2.dmg') -end \ No newline at end of file +end diff --git a/lib/trustie/utils/image.rb b/lib/trustie/utils/image.rb new file mode 100644 index 000000000..849c155ee --- /dev/null +++ b/lib/trustie/utils/image.rb @@ -0,0 +1,35 @@ +#coding=utf-8 + +module Trustie + module Utils + class Image + def initialize(file, bak) + @file = file + @bak = bak + end + + def compress(size=300) + backup if @bak + begin + f = Magick::ImageList.new(@file) + if f.format != 'GIF' + width = size + if f[0].columns > width + proportion = (width/f[0].columns.to_f) + height = (f[0].rows*proportion) + f.resize_to_fill!(width,height.to_i) + f.write(@file) + end + end + rescue Exception => e + logger.error "[Error] compress : ===> #{e}" + end + end + + def backup + FileUtils.cp @file, "#{@file}.bak" + end + + end + end +end diff --git a/public/javascripts/avatars.js b/public/javascripts/avatars.js index 3d8420dc0..a8f10edf0 100644 --- a/public/javascripts/avatars.js +++ b/public/javascripts/avatars.js @@ -190,6 +190,9 @@ function dragOutHandler(e) { } function setupFileDrop() { + $('#avatar_image').on('click', function(){ + console.log("click"); + }); if (window.File && window.FileList && window.ProgressEvent && window.FormData) { $.event.fixHooks.drop = { props: [ 'dataTransfer' ] }; From 89ea9ddc7bc5c2ed89908617f7dbef9f669d5a2d Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 8 May 2015 14:41:57 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=AE=A8=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E4=BB=A3=E7=A0=81=E8=BF=98=E5=8E=9F=20=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/boards/_project_show.html.erb | 233 +++--------------- .../layouts/_base_development_group.html.erb | 2 +- app/views/layouts/_base_friend_group.html.erb | 2 +- .../layouts/_base_research_team.html.erb | 2 +- app/views/messages/_form_project.html.erb | 2 +- 5 files changed, 42 insertions(+), 199 deletions(-) diff --git a/app/views/boards/_project_show.html.erb b/app/views/boards/_project_show.html.erb index d0fd6215a..af568bbff 100644 --- a/app/views/boards/_project_show.html.erb +++ b/app/views/boards/_project_show.html.erb @@ -1,186 +1,59 @@ -
-

+
+

<% if User.current.language == "zh"%> <%= h @board.name %> <% else %> <%= l(:project_module_boards) %> <% end %> -

- <%= l(:label_message_new) %> -
<% if !User.current.logged? %>
- <%= l(:label_user_login_project_board) %> - <%= link_to l(:label_user_login_new), signin_path, :class => "c_blue ml5" %> + <%= l(:label_user_login_project_board) %> + <%= link_to l(:label_user_login_new), signin_path, :class => "c_blue ml5" %>
<% end %> - -
-
-
-
    - <%= render :partial => 'project_new_topic' %> -
-
- - -

讨论区共有<%= @topic_count %>个帖子

-<% if @topics.any? %> - <% @topics.each do |topic| %> -
- <%= link_to image_tag(url_to_avatar(topic.author), :width=>"42",:height=>"42"), user_path(topic.author),:class =>'talkmain_pic fl' %> -
- <% author = topic.author.to_s + ":" %> - <%= link_to author, user_path(topic.author), :class =>"talkmain_name fl " %> - -

  <%= h(topic.subject) %>

- <% if topic.editable_by?(User.current) %> - <%= l(:button_edit) %> - <% end %> - <% if topic.sticky? %> - <%= l(:label_board_sticky)%> - <% end %> - <%= link_to( - l(:button_delete), - {:controller =>'messages',:action => 'destroy', :id => topic.id, :board_id => topic.board_id, :is_board=>'true'}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'talk_edit fr', - :style => ' margin-right: 10px;' - ) if topic.destroyable_by?(User.current) %> - - -
- -

- <%= topic.content %> -

-

- - - - - -

- - - - <%= l(:label_activity_time)%>:  <%= format_time topic.created_on %> -
- <%= toggle_link l(:button_reply), "reply" + topic.id.to_s, :focus => 'message_content',:class => ' c_dblue fr' %> - -
-
- -
-
    - <%= render :partial => 'edit',locals: {:topic => topic} %> -
-
-
- <% reply = Message.new(:subject => "RE: #{@message.subject}")%> - <% if !topic.locked? && authorize_for('messages', 'reply') %> - -
- - <% end %> - <% replies_all = topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC").offset(2). - all %> - <% replies_show = topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC").limit(2). - all %> - <% unless replies_show.empty? %> - <% reply_count = 0 %> -
-
    - <% replies_show.each do |message| %> - -
  • - <%= link_to image_tag(url_to_avatar(message.author), :width => '34',:height => '34'), user_path(message.author), :class =>'Msg_pic' %> -
    - <%= link_to_user_header message.author,false,:class => 'fl c_orange ' %> -
    -

    <%= textAreailizable message,:content,:attachments => message.attachments %>

    - -
    - <%= format_time(message.created_on) %> - <%= link_to( - - l(:button_delete), - {:controller => 'messages', :action => 'destroy', :id => message.id, :board_id => message.board_id, :is_board => 'true'}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :title => l(:button_delete), - :class => ' c_dblue fr' - ) if message.course_destroyable_by?(User.current) %> -
    -
    - -
  • - <% end %> -
-
- - <%if replies_all.first %> - - <% end %> - <% end %> -
- <% end %> - <% else %> -

<%= l(:label_no_data) %>

+ +
+
<%= l(:label_project_board_count , :count => @topic_count)%>
+ <% if @project.enabled_modules.where("name = 'boards'").count > 0 && User.current.member_of?(@project) %> + <%= link_to l(:project_module_boards_post), new_board_message_path(@board), + :class => 'problem_new_btn fl c_dorange', + :onclick => 'showAndScrollTo("add-message", "message_subject"); return false;' if User.current.logged? %> <% end %> +
+
+ +<% if @topics.any? %> + <% @topics.each do |topic| %> +
+ <%= link_to image_tag(url_to_avatar(topic.author), :width=>"32",:height=>"32"), user_path(topic.author),:class => 'problem_pic talk_pic fl' %> +
+ <%= link_to h(topic.subject), board_message_path(@board, topic), title:topic.subject.to_s, :class =>"problem_tit fl" %> + <% if topic.sticky? %> + <%= l(:label_board_sticky)%> + <% end %> +
+ <%= l(:label_post_by)%><%= link_to topic.author, user_path(topic.author), :class =>"problem_name" %> +  <%= l(:label_post_by_time)%><%= format_time topic.created_on %> +
+ <%= link_to (l(:label_short_reply) + " "+topic.replies_count.to_s), board_message_path(@board, topic), :class => "talk_btn fr c_white" %> +
+
+ <% end %> +<% else %> +

<%= l(:label_no_data) %>

+<% end %>
    - <%= pagination_links_full @topic_pages, @topic_count, :per_page_links => false, :remote => false, :flag => true %> -
- + <%= pagination_links_full @topic_pages, @topic_count, :per_page_links => false, :remote => false, :flag => true %> + + <%# other_formats_links do |f| %> - <%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> +<%#= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <%# end %> <% html_title @board.name %> @@ -188,33 +61,3 @@ <% content_for :header_tags do %> <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@project}: #{@board}") %> <% end %> -
- \ No newline at end of file diff --git a/app/views/layouts/_base_development_group.html.erb b/app/views/layouts/_base_development_group.html.erb index 891fa9d94..24f975f66 100644 --- a/app/views/layouts/_base_development_group.html.erb +++ b/app/views/layouts/_base_development_group.html.erb @@ -23,7 +23,7 @@ (<%= @project.boards.first.topics.count %>) <% end %> <% if User.current.member_of?(@project) %> - <%= link_to "+"+l(:project_module_boards_post), project_boards_path(@project, :flag => true), :layout => 'base_projects', :class => "subnav_green ml105" %> + <%= link_to "+"+l(:project_module_boards_post), new_board_message_path(@project.boards.first), :layout => 'base_projects', :class => "subnav_green ml105" %> <% end %>

<% end%> diff --git a/app/views/layouts/_base_friend_group.html.erb b/app/views/layouts/_base_friend_group.html.erb index 71d375501..16ccc09e5 100644 --- a/app/views/layouts/_base_friend_group.html.erb +++ b/app/views/layouts/_base_friend_group.html.erb @@ -12,7 +12,7 @@ (<%= @project.boards.first.topics.count %>) <% end %> <% if User.current.member_of?(@project) %> - <%= link_to "+"+l(:project_module_boards_post), project_boards_path(@project, :flag => true), :layout => 'base_projects', :class => "subnav_green ml105" %> + <%= link_to "+"+l(:project_module_boards_post), new_board_message_path(@project.boards.first), :layout => 'base_projects', :class => "subnav_green ml105" %> <% end %>
<% end%> diff --git a/app/views/layouts/_base_research_team.html.erb b/app/views/layouts/_base_research_team.html.erb index 3f942bc40..a214e8c20 100644 --- a/app/views/layouts/_base_research_team.html.erb +++ b/app/views/layouts/_base_research_team.html.erb @@ -23,7 +23,7 @@ (<%= @project.boards.first.topics.count %>) <% end %> <% if User.current.member_of?(@project) %> - <%= link_to "+"+l(:project_module_boards_post), project_boards_path(@project, :flag => true), :layout => 'base_projects', :class => "subnav_green ml105" %> + <%= link_to "+"+l(:project_module_boards_post), new_board_message_path(@project.boards.first), :layout => 'base_projects', :class => "subnav_green ml105" %> <% end %> <% end%> diff --git a/app/views/messages/_form_project.html.erb b/app/views/messages/_form_project.html.erb index 8e72544b5..bf91b3517 100644 --- a/app/views/messages/_form_project.html.erb +++ b/app/views/messages/_form_project.html.erb @@ -10,7 +10,7 @@ <% end %>

-
  • +
  • <% unless replying %> <% if @message.safe_attribute? 'sticky' %> <%= f.check_box :sticky %> From ee051f6a376286263ddd412954ab8d12f8b1443c Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 8 May 2015 14:55:56 +0800 Subject: [PATCH 11/21] =?UTF-8?q?1=E3=80=81=E8=AF=BE=E7=A8=8B=E8=AE=A8?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E5=9B=9E=E5=A4=8D=E5=8F=96=E6=B6=88=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=202=E3=80=81=E8=AF=BE=E7=A8=8B=E8=AE=A8=E8=AE=BA?= =?UTF-8?q?=E5=8C=BA=E5=9B=9E=E5=A4=8D=E6=97=B6=E4=B8=8D=E7=8E=B0=E5=AE=9E?= =?UTF-8?q?=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/messages/_course_show.html.erb | 1 + app/views/messages/_form_course.html.erb | 9 +++++---- public/javascripts/course.js | 7 +++++++ public/stylesheets/courses.css | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/views/messages/_course_show.html.erb b/app/views/messages/_course_show.html.erb index 579b26d65..2095babd6 100644 --- a/app/views/messages/_course_show.html.erb +++ b/app/views/messages/_course_show.html.erb @@ -105,6 +105,7 @@ <%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message_form'} do |f| %> <%= render :partial => 'form_course', :locals => {:f => f, :replying => true} %> <%= link_to l(:button_submit),"javascript:void(0)",:onclick => 'course_board_submit_message_replay();' ,:class => "blue_btn fl c_white" ,:style=>"margin-left: 50px;"%> + <%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'course_board_canel_message_replay();', :class => "blue_btn grey_btn fl c_white" %> <% end %> <% end %> diff --git a/app/views/messages/_form_course.html.erb b/app/views/messages/_form_course.html.erb index 9324ea59e..6b66b0fba 100644 --- a/app/views/messages/_form_course.html.erb +++ b/app/views/messages/_form_course.html.erb @@ -1,15 +1,16 @@ <%= javascript_include_tag "/assets/kindeditor/kindeditor" %> <%= error_messages_for 'message' %> <% replying ||= false %> -<% extra_option = replying ? { readonly: true} : { maxlength: 200 } %> +<% extra_option = replying ? { hidden: "hidden"} : { maxlength: 200 } %>
  • - +
    <% if replying %> - <%= f.text_field :subject, { size: 60, id: "message_subject",:class=>"talk_input w585" }.merge(extra_option) %> +
    <%= f.text_field :subject, { size: 60, id: "message_subject",:class=>"talk_input w585 fl" }.merge(extra_option) %>
    <% else %> <%= f.text_field :subject, { size: 60, id: "message_subject", onkeyup: "regexSubject();",:class=>"talk_input w585" }.merge(extra_option) %> <% end %> +

  • @@ -26,7 +27,7 @@
  • -
    +