From b711793d7ce468db39f3ebeeca1eafa54f3d7fd3 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 7 Jan 2015 11:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8A=A0=E5=85=A5=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 7 ++++--- app/controllers/courses_controller.rb | 4 +++- app/services/courses_service.rb | 11 ++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 79a5c215e..0ae3bba1d 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -90,13 +90,14 @@ module Mobile desc "加入课程" params do requires :token, type: String + requires :course_password, type: String end post ":id" do authenticate! cs = CoursesService.new - status = cs.join_course({"object_id" => params[:id]},current_user) - out = {status: status} - message = case status + status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user) + out = {status: status[:state]} + message = case status[:state] when 0; "加入成功" when 1; "密码错误" when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)" diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 19cca8e70..fa76bd0e5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -27,7 +27,9 @@ class CoursesController < ApplicationController def join if User.current.logged? cs = CoursesService.new - @state,course = cs.join_course params + join = cs.join_course params,User.current + @state = join[:state] + course = join[:course] #course = Course.find_by_id params[:object_id] #if course # if course_endTime_timeout? course diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index b9489be4e..23c25d302 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -217,20 +217,21 @@ class CoursesService #@state == 4 您加入的课程不存在 #@state == 5 您还未登录 #@state 其他 未知错误,请稍后再试 - def join_course params + def join_course params,current_user course = Course.find_by_id params[:object_id] + @state = 10 if course if course_endTime_timeout? course @state = 2 else - if User.current.member_of_course?(course) + if current_user.member_of_course?(course) @state = 3 else if params[:course_password] == course.password members = [] - members << Member.new(:role_ids => [10], :user_id => User.current.id) + members << Member.new(:role_ids => [10], :user_id => current_user.id) course.members << members - StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) + StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) @state = 0 else @state = 1 @@ -240,7 +241,7 @@ class CoursesService else @state = 4 end - [@state,course] + {:state => @state,:course => course} end #作业列表