From 70e8c4ebe733b75552440df7a577d2b1e9325b73 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 21 Nov 2014 19:11:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug<=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E7=94=A8=E6=88=B7=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E7=99=BB=E9=99=86=E9=83=BD=E5=BE=97=E8=BD=AC=E5=88=B0=E3=80=8A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99=E3=80=8B=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?>=20Signed-off-by:=20alan=20<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/account_controller.rb | 15 ++++++++++----- app/controllers/application_controller.rb | 2 +- app/models/user.rb | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 2c4929019..b5975e452 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -234,7 +234,7 @@ class AccountController < ApplicationController end def password_authentication - user = User.try_to_login(params[:username], params[:password]) + user, last_login_on = User.try_to_login(params[:username], params[:password]) if user.nil? invalid_credentials @@ -244,7 +244,7 @@ class AccountController < ApplicationController onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id }) else # Valid user - successful_authentication(user) + successful_authentication(user, last_login_on) end end @@ -291,7 +291,7 @@ class AccountController < ApplicationController end end - def successful_authentication(user) + def successful_authentication(user, last_login_on) logger.info "Successful authentication for '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}" # Valid user self.logged_user = user @@ -304,13 +304,18 @@ class AccountController < ApplicationController code = /\d*/ #根据home_url生产正则表达式 eval("code = " + "/^" + home_url.gsub(/\//,"\\\/") + "\\\/*(welcome)?\\\/*(\\\/index\\\/*.*)?\$/") - if code=~params[:back_url] + if code=~params[:back_url] && last_login_on != '' redirect_to user_activities_path(user) else + if last_login_on == '' + redirect_to my_account_url + else #by young #redirect_back_or_default my_page_path - redirect_back_or_default User.current + #sredirect_back_or_default User.current + redirect_to my_account_url #redirect_to User.current + end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 67948a8e1..d1465574f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -124,7 +124,7 @@ class ApplicationController < ActionController::Base else # HTTP Basic, either username/password or API key/random authenticate_with_http_basic do |username, password| - user = User.try_to_login(username, password) || User.find_by_api_key(username) + user = User.try_to_login(username, password)[0] || User.find_by_api_key(username) end end # Switch user if requested by an admin user diff --git a/app/models/user.rb b/app/models/user.rb index ff627763a..a9d73bd31 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -359,8 +359,9 @@ class User < Principal end end end + last_login_on = user.last_login_on.nil? ? '' : user.last_login_on.to_s user.update_column(:last_login_on, Time.now) if user && !user.new_record? - user + [user, last_login_on] rescue => text raise text end From 0049f921b94d7ddb2359e63664837b86dc28827e Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Sat, 22 Nov 2014 09:51:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug=E3=80=8A=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=89=88--=E8=AF=BE=E7=A8=8B/=E9=A1=B9=E7=9B=AE--?= =?UTF-8?q?=E9=85=8D=E7=BD=AE--=E6=88=90=E5=91=98=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=EF=BC=9A=E5=A6=82=E5=9B=BE=EF=BC=8C=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E5=90=84=E7=94=A8=E6=88=B7=E7=9A=84=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=85=A8=E9=83=A8=E4=B8=BA=E7=A9=BA=E4=BA=86=E3=80=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: alan <547533434@qq.com> --- app/models/user.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a9d73bd31..fe6222359 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -230,7 +230,12 @@ class User < Principal #选择项目成员时显示的用户信息文字 def userInfo - info=self.nickname + ' (' + self.realname + ')'; + if self.realname.gsub(' ','') == "" || self.realname.nil? + info = self.nickname; + else + info=self.nickname + ' (' + self.realname + ')'; + end + info end ###添加留言 fq