|
|
@ -2,7 +2,22 @@ class HacksController < ApplicationController
|
|
|
|
before_action :require_login, except: [:index]
|
|
|
|
before_action :require_login, except: [:index]
|
|
|
|
before_action :require_teacher_identity, only: [:create, :edit, :update]
|
|
|
|
before_action :require_teacher_identity, only: [:create, :edit, :update]
|
|
|
|
before_action :require_auth_identity, only: [:update, :edit, :publish]
|
|
|
|
before_action :require_auth_identity, only: [:update, :edit, :publish]
|
|
|
|
before_action :find_hack, only: [:edit, :update]
|
|
|
|
before_action :find_hack, only: [:edit, :update, :publish, :start]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可
|
|
|
|
|
|
|
|
def start
|
|
|
|
|
|
|
|
user_hack = @hack.hack_user_lastest_codes.mine(current_user.id)
|
|
|
|
|
|
|
|
identifier =
|
|
|
|
|
|
|
|
if user_hack
|
|
|
|
|
|
|
|
user_hack.identifier
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
user_identifier = generate_identifier HackUserLastestCode, 12
|
|
|
|
|
|
|
|
user_code = {user_id: current_user.id, code: @hack.code, identifier: user_identifier}
|
|
|
|
|
|
|
|
@hack.hack_user_lastest_codes.create!(user_code)
|
|
|
|
|
|
|
|
user_identifier
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
render_ok({identifier: identifier})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 首页
|
|
|
|
# 首页
|
|
|
|
def index
|
|
|
|
def index
|
|
|
@ -56,7 +71,7 @@ class HacksController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
# 发布功能
|
|
|
|
# 发布功能
|
|
|
|
def publish
|
|
|
|
def publish
|
|
|
|
Hack.where(identifier: params[:identifiers]).update_all(publish_params.to_h.merge(status:1))
|
|
|
|
@hack.update_attribute(:status, 1)
|
|
|
|
render_ok
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +102,7 @@ class HacksController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def hack_params
|
|
|
|
def hack_params
|
|
|
|
params.require(:hack).permit(:name, :description)
|
|
|
|
params.require(:hack).permit(:name, :description, :difficult, :category, :open_or_not, :time_limit, :score)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def hack_sets_params
|
|
|
|
def hack_sets_params
|
|
|
|