diff --git a/app/api/mobile/api.rb b/app/api/mobile/api.rb index 69bd4d44..6085d00f 100644 --- a/app/api/mobile/api.rb +++ b/app/api/mobile/api.rb @@ -109,11 +109,12 @@ module Mobile return uw.user if uw end - third_party_user_id = session[:third_party_user_id] - if third_party_user_id - c_user = UserSource.find_by_id(session[:third_party_user_id]) - return c_user.user if c_user - end + # third_party_user_id = session[:third_party_user_id] + # Rails.logger.info("#########third_party_user_id: #{third_party_user_id}") + # if third_party_user_id + # c_user = UserSource.find_by_id(session[:third_party_user_id]) + # return c_user.user if c_user + # end token = ApiKey.where(access_token: params[:token]).first if token && !token.expired? diff --git a/app/api/mobile/apis/cnmooc.rb b/app/api/mobile/apis/cnmooc.rb index d67a390d..7745cf8e 100644 --- a/app/api/mobile/apis/cnmooc.rb +++ b/app/api/mobile/apis/cnmooc.rb @@ -43,12 +43,21 @@ module Mobile requires :accessType, type: Integer, desc: "资源类型" end get "source_url" do - if session[:third_party_user_id].blank? - user = User.find(params[:userId]) - session[:third_party_user_id] = user.user_source.id + user = User.find_by_id(params[:userId]) + return {error: -1, messages: "用户不存在,请先创建用户"} unless user + token = Token.get_or_create_permanent_login_token(user) + cookie_options = { + :value => token.value, + :expires => 1.month.from_now, + :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), + :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), + :httponly => true + } + if Redmine::Configuration['cookie_domain'].present? + cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain']) end - - CnmoocsService.new.source_url(params) + cookies[Redmine::Configuration['autologin_cookie_name'].presence || 'autologin'] = cookie_options + CnmoocsService.new.source_url(params, token) end desc "远程登录" diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42dd6e1e..e44005a4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -193,6 +193,21 @@ class ApplicationController < ActionController::Base find_current_user end + def set_autologin_cookie(user) + token = Token.get_or_create_permanent_login_token(user) + cookie_options = { + :value => token.value, + :expires => 1.month.from_now, + :path => (Redmine::Configuration['autologin_cookie_path'] || '/'), + :secure => (Redmine::Configuration['autologin_cookie_secure'] ? true : false), + :httponly => true + } + if Redmine::Configuration['cookie_domain'].present? + cookie_options = cookie_options.merge(domain: Redmine::Configuration['cookie_domain']) + end + cookies[autologin_cookie_name] = cookie_options + end + def find_current_user user = nil unless api_request? @@ -207,9 +222,11 @@ class ApplicationController < ActionController::Base elsif session[:wechat_openid] uw = UserWechat.find_by_openid(session[:wechat_openid]) user = uw.user if uw - elsif session[:third_party_user_id] - c_user = UserSource.find_by_id(session[:third_party_user_id]) - user = c_user.user if c_user + elsif params[:authToken] + user = Token.find_by_value(params[:authToken]).user + #set_autologin_cookie(user) + #start_user_session(user) + session[:user_id] = user.id end end if user.nil? && Setting.rest_api_enabled? && accept_api_auth? @@ -335,6 +352,8 @@ class ApplicationController < ActionController::Base end def require_login + logger.info("#########login?: #{User.current.logged?}") + logger.info("#########get?: #{request.get?}") if !User.current.logged? # Extract only the basic url parameters on non-GET requests if request.get? diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index bf01ffb0..3322f1f2 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -16,6 +16,7 @@ class ChallengesController < ApplicationController #before_filter :find_shixun_language, :only => [:show, :new, :edit] before_filter :base_index, :only => [:index, :index_down, :index_up, :destroy] before_filter :view_allow, :only => [:show] + # before_filter :check_cnmooc, :only => [:index] include ApplicationHelper @@ -487,4 +488,12 @@ class ChallengesController < ApplicationController response.headers['content--type'] = 'text/javascript' request.format = 'js' end + + # def check_cnmooc + # if params[:authToken] + # user = User.find_by_id(session[:user_id]) + # set_autologin_cookie(user) + # end + # end + end diff --git a/app/controllers/colleges_controller.rb b/app/controllers/colleges_controller.rb index fff508a8..418015fd 100644 --- a/app/controllers/colleges_controller.rb +++ b/app/controllers/colleges_controller.rb @@ -50,7 +50,7 @@ class CollegesController < ApplicationController # Redo:这样做内存会卡死的 # user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id) # Redo:是否直接使用count会更好 - all_course_ids = Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("courses.id != 1309 and ue.school_id = #{@school.id}") + all_course_ids = Course.where("id != 1309 and is_delete = 0 and school_id = #{@school.id}") @courses_count = all_course_ids.size # Redo:对于量比较大的尽量不使用笛卡尔积 @@ -131,7 +131,7 @@ class CollegesController < ApplicationController (select count(m.id) from messages m inner join boards b on b.id=m.board_id and b.parent_id=0 where b.course_id=c.id group by c.id) as messages_count, c.tea_id, c.name, c.is_end, (SELECT MAX(created_at) FROM `course_activities` ca WHERE ca.course_id = c.id) AS update_time - FROM `courses` c WHERE (c.school_id = #{@school.id} and c.is_delete = 0)") + FROM `courses` c WHERE c.school_id = #{@school.id} and c.is_delete = 0") @courses.each do |course| course[:evaluating_count] = Output.find_by_sql("select sum(g.evaluate_count) as evaluating_count from games g inner join diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e87c7297..669cc58f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -577,7 +577,7 @@ class CoursesController < ApplicationController cha_member.member_roles.where("role_id = 10").first.destroy StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all end - @course.update_attributes(:tea_id => cha_member.user_id) + @course.update_attributes(:tea_id => cha_member.user_id, :school_id => cha_member.user.try(:user_extensions).try(:school_id)) man_member.member_roles.first.update_attributes(:role_id => 9) course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first course_act.update_column('user_id', cha_member.user_id) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 54b7ffe6..eb3c37c9 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -853,7 +853,7 @@ class ManagementsController < ApplicationController def evaluate_simple page = params[:page] - @recodes = EvaluateRecord.where("created_at > ?", Time.now - 10000.days).reorder("consume_time desc") + @recodes = EvaluateRecord.where("created_at > ?", Time.now - 1.days).reorder("consume_time desc") @recodes_count = @recodes.size @record_pages = Paginator.new @recodes_count, 20, page || 1 @offset ||= @record_pages.offset diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index f6854c7a..802bb8b9 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -1,10 +1,10 @@ # encoding: utf-8 class MyshixunsController < ApplicationController layout 'base_myshixun' - skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh, :code_runinng_message] - before_filter :require_login, :except => [:training_task_status, :close_webssh, :code_runinng_message] + skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh, :code_runinng_message, :vnc] + before_filter :require_login, :except => [:training_task_status, :close_webssh, :code_runinng_message, :vnc] before_filter :check_authentication, :except => [:training_task_status, :close_webssh, :mul_test_home, :mul_test_user, - :mul_test_myshixun, :mul_test_shixun, :mul_test_start, :code_runinng_message] + :mul_test_myshixun, :mul_test_shixun, :mul_test_start, :code_runinng_message, :vnc] before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh, :sync_reset_time, :destroy, :search_file_list, :vnc] DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) @@ -357,7 +357,8 @@ class MyshixunsController < ApplicationController host = Redmine::Configuration['tomcat_php'] begin uri = "#{shixun_tomcat}/bridge/vnc/getvnc" - params = {tpiID:@myshixun.id} + shixun = @myshixun.shixun + params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(shixun.mirror_repositories))}"} res = uri_exec uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 439c0e44..bf06b583 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -57,7 +57,7 @@ class Shixun < ActiveRecord::Base scope :visible, lambda{where(status: [2,3])} scope :min, lambda { select([:id, :name, :gpid, :modify_time, :reset_time, :language, :propaedeutics, :status, :identifier, :test_set_permission, :hide_code, :forbid_copy, :hidden, :webssh, :user_id, :code_hidden, - :task_pass, :exec_time, :multi_webssh]) } + :task_pass, :exec_time, :multi_webssh, :vnc]) } scope :published, lambda{where(status: 2)} scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } diff --git a/app/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 9ec02bfd..41705eb6 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -114,13 +114,12 @@ class CnmoocsService end - def source_url(params) - shixun = Shixun.find_by_identifier(params[:resouceId]) + def source_url(params, token) + shixun = Shixun.find_by_id(params[:resouceId]) if shixun.blank? return { error: -1, messages: '资源不存在' } end - - { error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}" } + { error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}/challenges?authToken=#{token.value}" } end def get_students_data params diff --git a/app/services/games_service.rb b/app/services/games_service.rb index e413c101..a53ee086 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -19,6 +19,7 @@ class GamesService shixun = Shixun.min.find(myshixun.shixun_id) unless ((myshixun.user_id == current_user.id || current_user.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) && (shixun.operable?)) || current_user.admin? + Rails.logger.info("######403???") return{:status => 403} end game_challenge = Challenge.min.find(game.challenge_id) @@ -74,7 +75,8 @@ class GamesService :challenge => game_challenge.try(:attributes), :game => game.try(:attributes), :shixun => shixun.try(:attributes), :record => record, :grade => grade, :prev_game => prev_game, :next_game => next_game, :username => username, :image_url => image_url, :user_url => user_url, :praise_count => praise_count, :user_praise => user_praise, :time_limit => time_limit, - :tomcat_url => Redmine::Configuration['tomcat_php'], :is_teacher => is_teacher, :power => power, :myshixun_manager => myshixun_manager} + :tomcat_url => Redmine::Configuration['tomcat_php'], :is_teacher => is_teacher, :power => power, :myshixun_manager => myshixun_manager, + :vnc => shixun.vnc} # 区分选择题和编程题,st:0编程题; if st == 0 diff --git a/app/views/managements/schools/_contrast_search_form.html.erb b/app/views/managements/schools/_contrast_search_form.html.erb index 4d24a810..9597a9c7 100644 --- a/app/views/managements/schools/_contrast_search_form.html.erb +++ b/app/views/managements/schools/_contrast_search_form.html.erb @@ -26,13 +26,10 @@
<%= sort_tag('新增教师', name: 'teacher_increase_count', path: school_data_grow_managements_path) %> | <%= sort_tag('新增学生', name: 'student_increase_count', path: school_data_grow_managements_path) %> | <%= sort_tag('新增课堂', name: 'course_increase_count', path: school_data_grow_managements_path) %> | -<%= sort_tag('新增实训', name: 'shixun_increase_count', path: school_data_grow_managements_path) %> | +<%= sort_tag('新增实训作业', name: 'shixun_increase_count', path: school_data_grow_managements_path) %> | <%= sort_tag('活跃用户', name: 'active_user_count', path: school_data_grow_managements_path) %> | diff --git a/app/views/shixuns/_form.html.erb b/app/views/shixuns/_form.html.erb index 53d38a63..337ecee2 100644 --- a/app/views/shixuns/_form.html.erb +++ b/app/views/shixuns/_form.html.erb @@ -156,7 +156,7 @@ - <% if Redmine::Configuration['gitlab_address'].include?("test") %> + <% if User.current.admin? %>
---|