78 lines
1.7 KiB
Ruby
78 lines
1.7 KiB
Ruby
class ContestsController < ApplicationController
|
|
|
|
before_filter :find_contest, :only => [:show]
|
|
before_filter :is_logged, :only => [:index, :new, :create]
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.js
|
|
format.html{render :layout => 'base_contests'}
|
|
end
|
|
end
|
|
|
|
def new
|
|
if User.current.login?
|
|
@contest = Contest.new
|
|
render :layout => 'new_base'
|
|
else
|
|
redirect_to signin_url
|
|
end
|
|
end
|
|
|
|
def create
|
|
@contest = Contest.new
|
|
@contest.name = params[:contest][:name]
|
|
params[:contest][:is_public] ? @contest.is_public = 1 : @contest.is_public = 0
|
|
@contest.user_id = User.current.id
|
|
if @contest && @contest.save
|
|
#unless User.current.admin?
|
|
member = ContestMember.new(:user_id => User.current.id)
|
|
|
|
@contest.contest_members << member
|
|
ContestMemberRole.create(:contest_member_id => member.id, :role_id => 13)
|
|
|
|
@contest.contest_acts << ContestActivity.new(:user_id => @contest.user_id,:contest_id => @contest.id)
|
|
respond_to do |format|
|
|
format.html {redirect_to contest_url(@contest)}
|
|
end
|
|
end
|
|
end
|
|
|
|
def join_contest
|
|
|
|
end
|
|
|
|
def join_contest_multi_role
|
|
if User.current.logged?
|
|
cs = ContestsService.new
|
|
@user = User.current
|
|
join = cs.join_contest_roles params,@user
|
|
@state = join[:state]
|
|
@contest = join[:contest]
|
|
else
|
|
@state = 5 #未登录
|
|
end
|
|
@object_id = @contest.id if @contest
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def find_contest
|
|
if params[:id].to_i < 780
|
|
render_403
|
|
return
|
|
end
|
|
@contest = Contest.find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
render_404
|
|
end
|
|
|
|
def is_logged
|
|
redirect_to signin_path unless User.current.logged?
|
|
end
|
|
|
|
end
|