diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index aedfc7407..279e89f13 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 @@ -302,16 +302,20 @@ class AccountController < ApplicationController call_hook(:controller_account_success_authentication_after, {:user => user }) code = /\d*/ - #根据home_url生产正则表达式 - eval("code = " + "/^" + home_url.gsub(/\//,"\\\/") + "\\\/*(welcome)?\\\/*(\\\/index\\\/*.*)?\$/") - if code=~params[:back_url] - redirect_to user_activities_path(user) - else - - #by young - #redirect_back_or_default my_page_path - redirect_back_or_default User.current - + #根据home_url生产正则表达式 + eval("code = " + "/^" + home_url.gsub(/\//,"\\\/") + "\\\/*(welcome)?\\\/*(\\\/index\\\/*.*)?\$/") + 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 + #redirect_to my_account_url + #redirect_to User.current + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 8e6f121b0..29709519d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -365,10 +365,10 @@ class User < Principal end end if user && !user.new_record? - #last_login_on = user.last_login_on.nil? ? '' : user.last_login_on.to_s + last_login_on = user.last_login_on.nil? ? '' : user.last_login_on.to_s user.update_column(:last_login_on, Time.now) end - user + [user, last_login_on] rescue => text raise text end diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 57e3e32b8..42f345d15 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -2,6 +2,14 @@ /* Redmine - project management software Copyright (C) 2006-2013 Jean-Philippe Lang */ +$(function() { + $.ajaxSetup({ + beforeSend: function ( xhr ) { + xhr.setRequestHeader("Accept", "text/javascript") + } + }) +} + function cleanArray (actual){ var newArray = new Array(); for (var i = 0; i< actual.length; i++){