commit
2009fd6b03
@ -0,0 +1,20 @@
|
|||||||
|
class Admins::CompetitionSettingsController < Admins::BaseController
|
||||||
|
def show
|
||||||
|
@competition = current_competition
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
Admins::SaveLaboratorySettingService.call(current_competition, form_params)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def current_competition
|
||||||
|
@_current_competition ||= Competition.find(params[:competition_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def form_params
|
||||||
|
params.permit(:identifier, :name, :nav_logo, :login_logo, :tab_logo, :footer, navbar: %i[name link hidden])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,34 @@
|
|||||||
|
class Weapps::BaseController < ApplicationController
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def require_wechat_login!
|
||||||
|
return if session_unionid.present?
|
||||||
|
|
||||||
|
render_error('请先进行微信授权')
|
||||||
|
end
|
||||||
|
|
||||||
|
def weapp_session_key
|
||||||
|
Wechat::Weapp.session_key(session_openid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_weapp_session_key(session_key)
|
||||||
|
Wechat::Weapp.write_session_key(session_openid, session_key)
|
||||||
|
end
|
||||||
|
|
||||||
|
def session_openid
|
||||||
|
session[:openid]
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_session_openid(openid)
|
||||||
|
session[:openid] = openid
|
||||||
|
end
|
||||||
|
|
||||||
|
def session_unionid
|
||||||
|
session[:unionid]
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_session_unionid(unionid)
|
||||||
|
session[:unionid] = unionid
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,24 @@
|
|||||||
|
class Weapps::CodeSessionsController < Weapps::BaseController
|
||||||
|
def create
|
||||||
|
return render_error('code不能为空') if params[:code].blank?
|
||||||
|
|
||||||
|
result = Wechat::Weapp.jscode2session(params[:code])
|
||||||
|
|
||||||
|
set_session_openid(result['openid'])
|
||||||
|
set_weapp_session_key(result['session_key']) # weapp session_key写入缓存 后续解密需要
|
||||||
|
|
||||||
|
# 已授权,绑定过账号
|
||||||
|
open_user = OpenUser::Wechat.find_by(uid: result['unionid'])
|
||||||
|
if open_user.present? && open_user.user
|
||||||
|
set_session_unionid(result['unionid'])
|
||||||
|
successful_authentication(open_user.user)
|
||||||
|
else
|
||||||
|
# 新用户
|
||||||
|
user_info = Wechat::Weapp.decrypt(result['session_key'], params[:encrypted_data], params[:iv])
|
||||||
|
|
||||||
|
set_session_unionid(user_info['unionId'])
|
||||||
|
end
|
||||||
|
|
||||||
|
render_ok(openid: result['openid'])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,12 @@
|
|||||||
|
class Weapps::HomesController < Weapps::BaseController
|
||||||
|
def show
|
||||||
|
# banner图
|
||||||
|
@images = PortalImage.where(status: true).order(position: :asc)
|
||||||
|
|
||||||
|
# 热门实训
|
||||||
|
@shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(4)
|
||||||
|
|
||||||
|
# 热门实践课程
|
||||||
|
@subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(4)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,24 @@
|
|||||||
|
class Weapps::SessionsController < Weapps::BaseController
|
||||||
|
before_action :require_wechat_login!
|
||||||
|
|
||||||
|
def create
|
||||||
|
return render_error('重复登录') if current_user.present? && current_user.logged?
|
||||||
|
|
||||||
|
user = User.try_to_login(params[:login], params[:password])
|
||||||
|
|
||||||
|
return render_error('错误的账号或密码') if user.blank?
|
||||||
|
return render_error('违反平台使用规范,账号已被锁定') if user.locked?
|
||||||
|
return render_error('错误的账号或密码') unless user.check_password?(params[:password].to_s)
|
||||||
|
|
||||||
|
if user.wechat_open_user && user.wechat_open_user.uid != session_unionid
|
||||||
|
render_error('该账号已被其它微信号绑定')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# 绑定微信号
|
||||||
|
OpenUsers::Wechat.create!(user: user, uid: session_unionid) if user.wechat_open_user.blank?
|
||||||
|
|
||||||
|
successful_authentication(user)
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
class Weapps::VerifiesController < Weapps::BaseController
|
||||||
|
before_action :require_wechat_login!
|
||||||
|
|
||||||
|
def create
|
||||||
|
valid = Wechat::Weapp.verify?(session_openid, params[:verify_string], params[:signature])
|
||||||
|
render_ok(valid: valid)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,30 @@
|
|||||||
|
<table class="table text-center shixun-settings-list-table">
|
||||||
|
<thead class="thead-light">
|
||||||
|
<th width="6%">序号</th>
|
||||||
|
<th width="14%" class="text-left">竞赛主标题</th>
|
||||||
|
<th width="10%">竞赛副标题</th>
|
||||||
|
<th width="8%">模式</th>
|
||||||
|
<th width="8%">报名人数</th>
|
||||||
|
<th width="8%">指导老师</th>
|
||||||
|
<th width="8%">参赛者</th>
|
||||||
|
<th width="14%">主题图片796*397</th>
|
||||||
|
<th width="8%">创建时间</th>
|
||||||
|
<th>
|
||||||
|
操作
|
||||||
|
</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if competitions.present? %>
|
||||||
|
<% competitions.each_with_index do |competition, index| %>
|
||||||
|
<tr id="competition-item-<%= competition.id %>">
|
||||||
|
<% page_no = list_index_no(@params_page.to_i, index) %>
|
||||||
|
<%= render partial: "admins/competitions/shared/td",locals: {competition: competition, page_no: page_no} %>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= render 'admins/shared/no_data_for_table' %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= render partial: 'admins/shared/paginate', locals: { objects: competitions } %>
|
@ -0,0 +1,27 @@
|
|||||||
|
<td><%= page_no %></td>
|
||||||
|
<td class="text-left">
|
||||||
|
<span><%= link_to competition.name, enroll_list_admins_competition_path(competition), :target => "_blank", :title => competition.name %></span>
|
||||||
|
</td>
|
||||||
|
<td><%= competition.sub_title %></td>
|
||||||
|
<td><%= competition.mode_type %></td>
|
||||||
|
<td><%= @member_count_map&.fetch(competition.id, 0) || competition.team_members.count %></td>
|
||||||
|
<td><%= competition.teacher_staff_num %></td>
|
||||||
|
<td><%= competition.member_staff_num %></td>
|
||||||
|
<td class="shixun-setting-image">
|
||||||
|
<% imageExists = File.exist?(disk_filename("Competition", competition.id)) %>
|
||||||
|
<% imageUrl = imageExists ? '/' + url_to_avatar(competition) + "?#{Time.now.to_i}" : '' %>
|
||||||
|
<%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image competition-image-#{competition.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: imageExists ? '' : 'display:none') %>
|
||||||
|
<%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-competition-image-action', data: { source_id: competition.id, source_type: 'Competition', toggle: 'modal', target: '.admin-upload-file-modal' } %>
|
||||||
|
</td>
|
||||||
|
<td><%= competition.created_at.strftime('%Y-%m-%d %H:%M') %></td>
|
||||||
|
<td class="action-container">
|
||||||
|
<%= link_to '配置', admins_competition_competition_setting_path(competition), class: 'action edit-action' %>
|
||||||
|
|
||||||
|
<% if !competition.status? && competition.published_at.blank? %>
|
||||||
|
<%= link_to '发布', publish_admins_competition_path(competition), class: 'action publish-action', method: :post, remote: true %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to '取消发布', unpublish_admins_competition_path(competition), class: 'action unpublish-action', method: :post, remote: true %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to competition.published? ? "下架" : "上架", online_switch_admins_competition_path(competition), class: 'action online-action', method: :post, remote: true %>
|
||||||
|
</td>
|
@ -0,0 +1,14 @@
|
|||||||
|
json.images do
|
||||||
|
json.array! @images do |image|
|
||||||
|
json.path image.link
|
||||||
|
json.image_url Util::FileManage.source_disk_file_url(image)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
json.shixuns do
|
||||||
|
json.partial! 'shixuns/shixun', locals: { shixuns: @shixuns }
|
||||||
|
end
|
||||||
|
|
||||||
|
json.subjects do
|
||||||
|
json.partial! 'subjects/subject', locals: { subjects: @subjects }
|
||||||
|
end
|
Loading…
Reference in new issue