-
+
+
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 2e9ac74c5..279e89f13 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -66,7 +66,7 @@ class AccountController < ApplicationController if @user.save @token.destroy flash[:notice] = l(:notice_account_password_updated) - redirect_to signin_path + redirect_to signin_url return end end @@ -92,7 +92,7 @@ class AccountController < ApplicationController Mailer.lost_password(token).deliver end flash[:notice] = l(:notice_account_lost_email_sent) - redirect_to signin_path + redirect_to signin_url return end end @@ -103,7 +103,7 @@ class AccountController < ApplicationController def register # @root_path="/home/pdl/redmine-2.3.2-0/apache2/" # - @cache_identityy = params[:identity]||"" #身份 + #@cache_identityy = params[:identity]||"" #身份 @cache_no = params[:no]||"" #学号 @cache_technical_title = params[:technical_title]||"" #教师职称 @cache_province = params[:province]||"" #省份 @@ -144,22 +144,7 @@ class AccountController < ApplicationController @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation] end - if(@cache_identityy == "") - if params[:identity] == "2" - @user.firstname = firstname_code - @user.lastname = lastname_code - end - flash.now[:error]= l(:label_identity)+l(:'activerecord.errors.messages.empty') - return - end - if(@cache_city == "") - if params[:identity] == "2" - @user.firstname = firstname_code - @user.lastname = lastname_code - end - flash.now[:error]= l(:label_location)+l(:'activerecord.errors.messages.empty') - return - end + case Setting.self_registration when '1' @@ -204,7 +189,7 @@ class AccountController < ApplicationController token.destroy flash[:notice] = l(:notice_account_activated) end - redirect_to signin_path + redirect_to signin_url end def valid_ajax @@ -234,6 +219,10 @@ class AccountController < ApplicationController render :json => req end + def email_valid + + end + private def authenticate_user @@ -245,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 @@ -255,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 @@ -302,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 @@ -315,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 + #redirect_to my_account_url #redirect_to User.current + end end end @@ -363,7 +357,7 @@ class AccountController < ApplicationController UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) Mailer.register(token).deliver flash[:notice] = l(:notice_account_register_done) - redirect_to signin_path + render action: 'email_valid', locals: {:mail => user.mail} else yield if block_given? end @@ -380,7 +374,7 @@ class AccountController < ApplicationController UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) self.logged_user = user flash[:notice] = l(:notice_account_activated) - redirect_to my_account_path + redirect_to my_account_url else yield if block_given? end @@ -402,6 +396,6 @@ class AccountController < ApplicationController def account_pending flash[:notice] = l(:notice_account_pending) - redirect_to signin_path + redirect_to signin_url end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cab5ada7c..32cfefa9d 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 78bfc75f0..29709519d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -75,6 +75,7 @@ class User < Principal has_many :homework_users has_many :homework_attaches, :through => :homework_users + has_many :homework_evaluations has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} @@ -167,7 +168,7 @@ class User < Principal LOGIN_LENGTH_LIMIT = 25 MAIL_LENGTH_LIMIT = 60 - validates_presence_of :login, :firstname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } + validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only @@ -198,13 +199,19 @@ class User < Principal } scope :sorted, lambda { order(*User.fields_for_order_statement)} - scope :like, lambda {|arg| + scope :like, lambda {|arg, type| if arg.blank? where(nil) else pattern = "%#{arg.to_s.strip.downcase}%" #where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) - where(" LOWER(login) LIKE :p ", :p => pattern) + if type == "0" + where(" LOWER(login) LIKE :p ", :p => pattern) + elsif type == "1" + where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern) + else + where(" LOWER(mail) LIKE :p ", :p => pattern) + end end } @@ -223,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 @@ -352,8 +364,11 @@ class User < Principal end end end - user.update_column(:last_login_on, Time.now) if user && !user.new_record? - user + if user && !user.new_record? + last_login_on = user.last_login_on.nil? ? '' : user.last_login_on.to_s + user.update_column(:last_login_on, Time.now) + end + [user, last_login_on] rescue => text raise text end diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index 20b0c5c04..4175282b3 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -20,13 +20,20 @@ } } - +
+ + ++ | + + | <%= text_field_tag 'username', params[:username], :tabindex => '1' , :value => "#{l(:label_login_prompt)}", :onfocus => "clearInfo('username','#{l(:label_login_prompt)}')", @@ -35,33 +42,48 @@ | |
- | <%= password_field_tag 'password', nil, :tabindex => '2' %> | ++ + | ++ <%= password_field_tag 'password', nil, :tabindex => '2' %> + |
- | <%= text_field_tag "openid_url", nil, :tabindex => '3' %> | ++ + | ++ <%= text_field_tag "openid_url", nil, :tabindex => '3' %> + |
<% if Setting.autologin? %> - + <% end %> | |||
- <% if Setting.lost_password? %> + + <% if Setting.lost_password? %> <%= link_to l(:label_password_lost), lost_password_path %> <% end %> - |
-
- <%= l(:label_identity) %> * | -- - | -- | - - -<% else %> -<%= text_field_tag :no, nil, :placeholder => "请输入学号" %> -<% end %> -
<%= f.text_field :login, :size => 25, :required => true %> - <%= l(:label_max_number) %>
- -<%= f.password_field :password, :size => 25, :required => true %> - <%= l(:text_caracters_minimum, :count => Setting.password_min_length) %>
- -<%= f.password_field :password_confirmation, :size => 25, :required => true %>
- <% end %> - - - -<%= f.text_field :mail, :required => true %>
- -- <%= "#{l(:label_mail_attention)} " %>
- -<%= f.select :language, lang_options_for_select, :required => true %>
- - - - - - --
- <%= l(:label_location) %> * - | -- - | -- - | -
-
<%= submit_tag l(:button_submit) %> | -
<%= f.text_field :identity_url %>
-<% end %> - - -<% @user.custom_field_values.select { |v| v.editable? || v.required? }.each do |value| %> -<%= custom_field_tag_with_label :user, value %>
-<% end %> -
+ <%= f.text_field :login, :required => true, :size => 25, :name => "login", :readonly => true, :style => 'border:1px solid #d3d3d3;'%>
+ <%= l(:label_max_number) %>
+
+
+ + +
+ + + <% end %> + + + + + + + + + + + + + + + + + + ++ <%= f.text_field :mail, :required => true %> +
+ ++ <%= f.select :language, :Chinese => :zh, :English => :en %> +
+ + + <% if !User.current.user_extensions.nil? %> + <% province = User.current.user_extensions.location %> + <% city = User.current.user_extensions.location_city %> + <% identity = User.current.user_extensions.identity %> + <% occupation1 = User.current.user_extensions.occupation %> + <% occupation = User.current.user_extensions.occupation %> + <% title = User.current.user_extensions.technical_title %> + <% language = User.current.language %> + <% else %> + <% province = "湖南省" %> + <% city = "长沙"%> + <% identity = ""%> + <% occupation1 = ""%> + <% title = "" %> + <% language = ""%> + <% end %> + + ++ + +
+ + + + ++ <%= f.text_field :identity_url %> +
+ <% end %> + + <% @user.custom_field_values.select(&:editable?).each do |value| %> +<%= custom_field_tag_with_label :user, value %>
+ <% end %> + <%= call_hook(:view_my_account, :user => @user, :form => f) %> ++ <%= render :partial => 'users/mail_notifications' %> +