diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index c631d56f..6e9daea1 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -140,7 +140,6 @@ module Mobile # Rails.logger.info("########### host is #{request.host}") if (Rails.env.development? && session[:user_id].blank?) || - (session[:user_id].blank? && request.host.include?("testbdweb")) || params[:action] == "privateGit" session[:user_id] = 12 #116 end diff --git a/app/api/mobile/apis/memos.rb b/app/api/mobile/apis/memos.rb index 98597f85..89412316 100644 --- a/app/api/mobile/apis/memos.rb +++ b/app/api/mobile/apis/memos.rb @@ -33,9 +33,9 @@ module Mobile if params[:edu] Rails.logger.info("####11111222##{@env['HTTP_X_REAL_IP']}") ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD) - unless ua - UserAgent.create(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) + ua = UserAgent.where(:ip => ip) + if ua.blank? + UserAgent.create!(:key => params[:edu].strip, :ip => ip, :type => UserAgent::AD) end end MemosService.new.show params, current_user diff --git a/app/api/mobile/entities/project_package.rb b/app/api/mobile/entities/project_package.rb index 278e9b85..50d4ff69 100644 --- a/app/api/mobile/entities/project_package.rb +++ b/app/api/mobile/entities/project_package.rb @@ -17,8 +17,8 @@ module Mobile expose :bidding_users_count, if: { type: :index } expose :min_price expose :max_price - expose :contact_name, if: ->(package, opts){ opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business? } - expose :contact_phone, if: ->(package, opts){ opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business? } + expose :contact_name, if: ->(package, opts){ opts[:user].present? && (opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business?) } + expose :contact_phone, if: ->(package, opts){ opts[:user].present? && (opts[:user].id == package.creator_id || opts[:user].admin? || opts[:user].business?) } expose :updated_at do |package, _| package.updated_at.strftime('%Y-%m-%d %H:%M:%S') @@ -65,6 +65,7 @@ module Mobile expose :operation, if: { type: :show } do |package, opts| user = opts[:user] + return {} if user.blank? is_creator = user.id == package.creator_id is_admin = user.admin? || user.business? diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 068996b0..d362cde3 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -377,6 +377,10 @@ class AccountController < ApplicationController else us = UsersService.new @user = us.register user_params.merge(:should_confirmation_password => false) + # 注册时,记录是否是引流用户 + ip = request.remote_ip + ua = UserAgent.find_by_id(:ip => ip) + ua.update_column(:type, UserAgent::REGISTER) if ua if !@user.new_record? self.logged_user = @user flash[:notice] = l(:notice_account_activated) diff --git a/app/controllers/competition_teams_controller.rb b/app/controllers/competition_teams_controller.rb index f180bc06..092426ef 100644 --- a/app/controllers/competition_teams_controller.rb +++ b/app/controllers/competition_teams_controller.rb @@ -348,10 +348,8 @@ class CompetitionTeamsController < ApplicationController def record_agent_user_action # 注册时,记录是否是引流用户 - ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD).take - if ua && UserAgent.where(:ip => ip, :type => UserAgent::COMPETITION).blank? - UserAgent.create(:key => ua.key, :ip => ip, :type => UserAgent::COMPETITION, :user_id => User.current.id) - end + ip = request.remote_ip + ua = UserAgent.find_by_id(:ip => ip) + ua.update_column(:type, UserAgent::COMPETITION) if ua end end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b4de6576..156ae951 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -28,6 +28,15 @@ class ManagementsController < ApplicationController render :json => {status: 1} end + def user_agents + @user_agents = UserAgent.where("user_agents.key is not null") + @agents_count = @user_agents.count + limit = 20 + @agents_pages = Paginator.new @agents_count, limit, params['page'] || 1 + @offset ||= @agents_pages.offset + @user_agents = paginateHelper @user_agents, limit + end + # 实训课程等级体系 def subject_level_system @levels = SubjectLevelSystem.all diff --git a/app/controllers/project_packages_controller.rb b/app/controllers/project_packages_controller.rb index fe2c1c13..6721c1c4 100644 --- a/app/controllers/project_packages_controller.rb +++ b/app/controllers/project_packages_controller.rb @@ -1,7 +1,7 @@ # encoding=utf-8 # For react class ProjectPackagesController < ApplicationController - before_filter :require_login, :except => [:index] + before_filter :require_login, :except => [:index, :show] include ApplicationHelper diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 17ce88c0..d60de29c 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -136,10 +136,6 @@ class UsersService ue = @user.user_extensions ||= UserExtensions.new ue.user_id = @user.id ue.save - # 注册时,记录是否是引流用户 - ip = @env['HTTP_X_REAL_IP'] - ua = UserAgent.where(:ip => ip, :type => UserAgent::AD).take - UserAgent.create(:key => ua.key, :ip => ip, :type => UserAgent::REGISTER, :user_id => @user.id) if ua end @user #img_url = url_to_avatar(@user) diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index f0fefec5..3392f099 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -145,6 +145,7 @@
diff --git a/app/views/managements/_user_agent_list.html.erb b/app/views/managements/_user_agent_list.html.erb new file mode 100644 index 00000000..43886c8d --- /dev/null +++ b/app/views/managements/_user_agent_list.html.erb @@ -0,0 +1,66 @@ +
ID | +代理人登录名 | +代理人姓名 | +学校 | +竞赛报名状态 | +ip | +ip | +负责人 | + + + <% @user_agents.each do |ua| %> + <% user = User.find_by_login(ua.key) %> + <% user_extension = user.extensions %> + <% school = user_extension.school %> +
---|---|---|---|---|---|---|
<%= ua.id %> | +<%= link_to ua.key, user_path(ua.key), :target => "_blank" %> | +<%= link_to user.try(:show_real_name), user_path(user), target:'_blank' %> | +<%= school.name %> | +<%= "--" %> | +<%= ua.ip %> | +<%= "理由" %> | +