dev_haigong
hjm 6 years ago
commit 33058789b0

@ -436,7 +436,15 @@ class AccountController < ApplicationController
# 注册完/绑定邮箱 后完善资料 # 注册完/绑定邮箱 后完善资料
def user_info def user_info
@user = User.current @user = User.current
#是否是Oschina过来的
@is_ecoder_user = @user.ecoder_user_id.to_i>0
#是否没设置过密码
@is_set_password = @user.hashed_password.present?
if request.get? if request.get?
# 如果是登录的请求进来,则需要判断登录名是否合法 # 如果是登录的请求进来,则需要判断登录名是否合法
if (@user.login =~ /(^(?=.*?[a-zA-Z]).*$)/).nil? || !(@user.login =~ /[@#\$%\^&\*\.]+/).nil? if (@user.login =~ /(^(?=.*?[a-zA-Z]).*$)/).nil? || !(@user.login =~ /[@#\$%\^&\*\.]+/).nil?
@login_error = true @login_error = true
@ -454,6 +462,22 @@ class AccountController < ApplicationController
apply_user.update_all(:status => 2) unless apply_user.blank? apply_user.update_all(:status => 2) unless apply_user.blank?
end end
if @is_ecoder_user && !@is_set_password
@user.password = params[:new_password]
@user.password_confirmation = params[:new_password_confirmation]
if @user.password.size<8
@password_len_error = true
render :user_info and return
end
if @user.password != @user.password_confirmation
@password_match_error = true
render :user_info and return
end
end
@user.lastname = params[:lastname] @user.lastname = params[:lastname]
@user.firstname = "" @user.firstname = ""
@user.show_realname = params[:hide_realname] ? 0 : 1 @user.show_realname = params[:hide_realname] ? 0 : 1
@ -525,6 +549,7 @@ class AccountController < ApplicationController
return return
else else
@user.login = lg @user.login = lg
logger.info "save user: #{@user.errors}"
end end
end end
end end

@ -38,8 +38,6 @@ class EcloudController < ApplicationController
ROOT_URl = 'http://localhost:3000' ROOT_URl = 'http://localhost:3000'
SERVER_URL = "https://221.176.54.92:9081/restful/services/" SERVER_URL = "https://221.176.54.92:9081/restful/services/"
## 签名 ## 签名
def sign(timestamp) def sign(timestamp)
Digest::MD5.hexdigest("client_id=#{CLIENT_ID}client_key=#{CLIENT_SECRET}timestamp=#{timestamp}").upcase Digest::MD5.hexdigest("client_id=#{CLIENT_ID}client_key=#{CLIENT_SECRET}timestamp=#{timestamp}").upcase
@ -174,39 +172,53 @@ class EcloudController < ApplicationController
end end
def ecloud_login_callback def ecloud_login_callback
#获取code
logger.info "oauth2 login_callback: #{params}"
raise "没有code" unless params[:code] unless params["test"] == 'true'
#获取code
logger.info "oauth2 login_callback: #{params}"
url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" + raise "没有code" unless params[:code]
"&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}"
res = post(url) url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" +
logger.info "oauth2 authorization resp: #{res}" "&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}"
body = decode(res) res = post(url)
#{"access_token":"21a80f20ff736b54aecd002b60210943","token_type":"bearer","expires_in":86400,"refresh_token":"be92e2c137a8c6dd22f0d8c4a622b3aeceb054087a95d293130f04ec60fd3e3f","scope":"user_info","created_at":1542684088} logger.info "oauth2 authorization resp: #{res}"
# {"access_token":"ae673b2d-88b4-46cc-aa74-0b031f24b76f","expires":6,"refresh_token":"7380cc67-a59c-4c21-9000-70e12a58d175","username":"15111030087@QW_er","uid":2147}
raise '登录失败' unless body["access_token"] body = decode(res)
#获取此用户信息 raise '登录失败' unless body["access_token"]
#获取此用户信息
res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}")
logger.info "oauth2 get user info: #{res}"
# {"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"}
else
res = '{"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"}'
end
# res = get("https://gitee.com/api/v5/user?access_token=#{body["access_token"]}")
res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}")
logger.info "oauth2 get user info: #{res}"
# 同步用户 # 同步用户
# info = decode(res) info = decode(res)
#
# user = User.find_by_oschina_user_id(info["id"]) user = User.find_by_ecoder_user_id(info["userid"])
# unless user unless user
# user = User.create_with_oschina!(info) #新建用户
# end user = User.create_with_ecoder!(info)
# end
# @current_user = user
self.logged_user = user
render :index
user = UserExtensions.where(:user_id => User.current.id).first
if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil?
redirect_to my_account_path
elsif user.identity == 3 && user.school_id.nil?
redirect_to my_account_path
else
redirect_to User.current
end
end end

@ -141,6 +141,10 @@ class MyController < ApplicationController
# Edit user's account # Edit user's account
def account def account
@user = params[:user_id].nil? ? User.current : User.find(params[:user_id]) @user = params[:user_id].nil? ? User.current : User.find(params[:user_id])
ue = @user.user_extensions ue = @user.user_extensions
if @user.lastname.blank? || ue.try(:identity).nil? || (ue.try(:identity) == 1 && ue.try(:student_id).blank?) || (ue.try(:identity) != 1 && ue.try(:technical_title).blank?) || ue.try(:gender).blank? || ue.try(:school_id).blank? if @user.lastname.blank? || ue.try(:identity).nil? || (ue.try(:identity) == 1 && ue.try(:student_id).blank?) || (ue.try(:identity) != 1 && ue.try(:technical_title).blank?) || ue.try(:gender).blank? || ue.try(:school_id).blank?
redirect_to user_info_path redirect_to user_info_path
@ -152,7 +156,8 @@ class MyController < ApplicationController
applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first
applied_message.update_attribute(:viewed, true) applied_message.update_attribute(:viewed, true)
end end
# @user = User.current
# 认证 # 认证
@trail_authentication = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization").order("created_at desc").first @trail_authentication = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization").order("created_at desc").first
if @trail_authentication && (@trail_authentication.status == 1 || @trail_authentication.status == 2) && !@trail_authentication.noticed if @trail_authentication && (@trail_authentication.status == 1 || @trail_authentication.status == 2) && !@trail_authentication.noticed

@ -2592,6 +2592,7 @@ class UsersController < ApplicationController
def user_info def user_info
end end
# 连续签到六天则每天累加10个金币 # 连续签到六天则每天累加10个金币

@ -1692,6 +1692,36 @@ class User < Principal
end end
end end
def self.create_with_ecoder!(info)
user = User.new
user.admin = false
user.login = "ecoder_" + info["mobile"]
user.phone = info["mobile"]
unless User.find_by_mail(info["email"])
user.mail = info["email"]
end
user.nickname = info["username"]
user.activate
user.last_login_on = Time.now
user.ecoder_user_id = info["userid"]
user.save!(:validate => false)
UserStatus.create!(:user_id => user.id, :changsets_count => 0, :watchers_count => 0)
ue = user.user_extensions ||= UserExtensions.new
ue.user_id = user.id
ue.save!
user
end
end end
class AnonymousUser < User class AnonymousUser < User

@ -88,15 +88,20 @@ class GamesService
# tpm_script_modified = (shixun.reset_time > myshixun.reset_time ? true : false) # 新结构脚本是实时传送的,所以不会影响 # tpm_script_modified = (shixun.reset_time > myshixun.reset_time ? true : false) # 新结构脚本是实时传送的,所以不会影响
# 区分评测过未评测过,未评测过按需求取数据 # 区分评测过未评测过,未评测过按需求取数据
if max_query_index > 0 sql =
qurey_test_sets = TestSet.find_by_sql("SELECT o.actual_output, o.out_put, o.result, o.test_set_position, o.query_index,t.is_public,t.input, t.output, g.id as game_id, c.id as challenge_id FROM outputs o,games g ,challenges c,test_sets t where if max_query_index > 0
g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and t.position =o.test_set_position order by o.query_index "SELECT o.actual_output, o.out_put, o.result, o.test_set_position, o.query_index,t.is_public,t.input,
") t.output, g.id as game_id, c.id as challenge_id
else FROM test_sets t, outputs o,games g ,challenges c
qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public,t.input, t.output,t.position FROM games g ,challenges c,test_sets t where WHERE g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id
g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id and t.challenge_id = c.id and t.position =o.test_set_position
") ORDER BY o.query_index"
end else
"SELECT t.is_public,t.input, t.output, t.position
FROM games g ,challenges c,test_sets t
WHERE g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id"
end
qurey_test_sets = TestSet.find_by_sql(sql)
# 测试集统计及处理 # 测试集统计及处理
unless qurey_test_sets.blank? unless qurey_test_sets.blank?

@ -39,6 +39,20 @@
</li> </li>
<% end %> <% end %>
<% if @is_ecoder_user && !@is_set_password %>
<li class="clearfix">
<label class="second-label fl"><span class="color-orange">* </span>密码:</label>
<input name="new_password" type="password" class="winput-240-40 fl" placeholder="请输入密码">
<p class="notice color-orange fl"><span id="new_password_hint" class="none"><i class="fa fa-exclamation-circle mt7 mr5 fl"></i>密码最小长度为8位</span></p>
</li>
<li class="clearfix">
<label class="second-label fl"><span class="color-orange">* </span>重复密码:</label>
<input name="new_password_confirmation" type="password" class="winput-240-40 fl" placeholder="请输入密码">
<p class="notice color-orange fl"><span id="new_password_confirmation_hint" class="none"><i class="fa fa-exclamation-circle mt7 mr5 fl"></i>两次密码不匹配</span></p>
</li>
<% end %>
<li class="<%= @user.show_realname ? 'none' : '' %> clearfix" id="nickname_li"> <li class="<%= @user.show_realname ? 'none' : '' %> clearfix" id="nickname_li">
<label class="second-label fl"><span class="color-orange">* </span>昵称:</label> <label class="second-label fl"><span class="color-orange">* </span>昵称:</label>
<input type="text" id="nickname" name="nickname" maxlength="20" value="<%= @user.nickname %>" class="winput-240-40 fl" placeholder="填写昵称"> <input type="text" id="nickname" name="nickname" maxlength="20" value="<%= @user.nickname %>" class="winput-240-40 fl" placeholder="填写昵称">

@ -0,0 +1,6 @@
class AddEcoderUserIdToUsers < ActiveRecord::Migration
def change
add_column :users, :ecoder_user_id, :integer, default: 0
add_index :users, :ecoder_user_id
end
end

@ -1,26 +1,71 @@
class MigrationShixunStudentWork < ActiveRecord::Migration class MigrationShixunStudentWork < ActiveRecord::Migration
def up def up
works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") ActiveRecord::Base.transaction do
works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, begin
:cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)")
works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil,
:cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil)
shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0")
shixun_works.each do |work| shixun_works.each do |work|
if work.homework_common && work.homework_common.homework_commons_shixuns.try(:shixun) shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun)
shixun = work.homework_common.homework_commons_shixuns.try(:shixun) user = work.user
if shixun.present? && user.present?
# 创建新的myshixun和games
# fork版本库如果用户没有同步则先同步用户
g = Gitlab.client
if user.gid.nil?
s = Trustie::Gitlab::Sync.new
s.sync_user(user)
end
gshixun = g.fork(shixun.gpid, user.gid)
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
code = down_generate_identifier("myshixun")
# 一般通过默认分支是否存在来判断一个项目是否fork成功
if gshixun.try(:id).present?
commit_id = g.commits(shixun.gpid).first.try(:id)
# educoder 加入到myshixun中
myshixun_admin_gid = User.where(:login => "educoder").first.try(:gid)
g.add_team_member(gshixun.id, myshixun_admin_gid, 40) # 40代表角色master
# 创建新的myshixun和games myshixun = Myshixun.create!(:shixun_id => shixun.id, :user_id => user.id, :identifier => code,
myshixun = nil :modify_time => shixun.modify_time, :reset_time => shixun.reset_time,
:onclick_time => Time.now, :gpid => gshixun.id,
:git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id)
work_score = work.final_score rep_url = Base64.urlsafe_encode64(gitlab_url shixun) # 注意educoder为默认给实训创建版本库的用户如果换成别的用户名字要相应的修改
work.homework_common.homework_challenge_settings.each do |setting| uri = "#{shixun_tomcat}/bridge/game/openGameInstance"
if work_score > 1 params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)}
myshixun.games.where(:challenge_id => setting.challenge_id).first.update_attributes(:status => 2) logger.info("openGameInstance params is #{params}")
work_score -= setting.score res = uri_exec uri, params
if (res && res['code'].to_i != 0)
raise("实训云平台繁忙繁忙等级83")
end
# 其它创建关卡等操作
challenges = shixun.challenges
# 之所以增加user_id是为了方便统计查询性能
challenges.each_with_index do |challenge, index|
status = (index == 0 ? 0 : 3)
code = down_generate_identifier("game")
Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id,
:open_time => Time.now, :identifier => code, :modify_time => challenge.modify_time)
end
work_score = work.final_score
work.homework_common.homework_challenge_settings.each do |setting|
if work_score > 1
games = myshixun.games.where(:challenge_id => setting.challenge_id).first
games.update_attributes(:status => 2, :end_time => Time.now, :final_score => setting.challenge.score)
work_score -= setting.score
end
end
work.update_column("myshixun_id", myshixun.id)
end
end end
end end
rescue Exception => e
work.update_column("myshixun_id", myshixun.id) puts ("###failed to exec shixun: current task id is #{e}")
g.delete_project(gshixun.id) if gshixun.try(:id).present?
raise ActiveRecord::Rollback
end end
end end
end end

@ -152,7 +152,7 @@ function changeDepValue(value, data) {
// 基本资料页面提交表单时,判断身份与单位是否合法 // 基本资料页面提交表单时,判断身份与单位是否合法
function my_account_form_submit() { function my_account_form_submit() {
if ($("#nickname").val().trim() == '') { if ($("#nickname").val().trim() === "") {
$("#nickname").focus(); $("#nickname").focus();
$("#nickname_hint").show(); $("#nickname_hint").show();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
@ -161,6 +161,8 @@ function my_account_form_submit() {
$("#nickname_hint").hide(); $("#nickname_hint").hide();
} }
//姓名不能为空 //姓名不能为空
if ($("#lastname").val().trim() == '') { if ($("#lastname").val().trim() == '') {
$("#lastname").focus(); $("#lastname").focus();

@ -1483,7 +1483,6 @@ function my_account_form_submit() {
if ($("input[name='lastname']").val().trim() == '') { if ($("input[name='lastname']").val().trim() == '') {
$("#lastname").focus(); $("#lastname").focus();
$("#lastname_hint").show(); $("#lastname_hint").show();
e.stopImmediatePropagation();
return; return;
} else { } else {
$("#lastname_hint").hide(); $("#lastname_hint").hide();
@ -1516,16 +1515,31 @@ function my_account_form_submit() {
if ($("#nickname").val().trim() == '') { if ($("#nickname").val().trim() == '') {
$("#nickname").focus(); $("#nickname").focus();
$("#nickname_hint").show(); $("#nickname_hint").show();
e.stopImmediatePropagation();
return; return;
} else { } else {
$("#nickname_hint").hide(); $("#nickname_hint").hide();
} }
} }
if($("input[name='new_password']").val().length<8){
$("#new_password").focus();
$("#new_password_hint").show();
return;
} else {
$("#new_password_hint").hide();
}
if($("input[name='new_password']").val() !== $("input[name='new_password_confirmation']").val() ){
$("#new_password_confirmation").focus();
$("#new_password_confirmation_hint").show();
return;
} else {
$("#new_password_confirmation_hint").hide();
}
if ($("#userIdentity").val() == -1) { if ($("#userIdentity").val() == -1) {
$("#identity_hint").show(); $("#identity_hint").show();
e.stopImmediatePropagation(); // 阻止事件冒泡
return; return;
} else{ } else{
$("#identity_hint").hide(); $("#identity_hint").hide();
@ -1533,7 +1547,6 @@ function my_account_form_submit() {
if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") { if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") {
$("#te_technical_hint").show(); $("#te_technical_hint").show();
e.stopImmediatePropagation();
return; return;
} else{ } else{
$("#te_technical_hint").hide(); $("#te_technical_hint").hide();
@ -1541,7 +1554,6 @@ function my_account_form_submit() {
if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") { if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") {
$("#pro_technical_hint").show(); $("#pro_technical_hint").show();
e.stopImmediatePropagation();
return; return;
} else{ } else{
$("#pro_technical_hint").hide(); $("#pro_technical_hint").hide();
@ -1554,7 +1566,6 @@ function my_account_form_submit() {
} else{ } else{
$("#student_id_hint").html('<i class="fa fa-minus-circle mt7 mr5 fl"></i>学号只能由数字和字母组成</span>').show(); $("#student_id_hint").html('<i class="fa fa-minus-circle mt7 mr5 fl"></i>学号只能由数字和字母组成</span>').show();
} }
e.stopImmediatePropagation();
return; return;
} else{ } else{
$("#student_id_hint").hide(); $("#student_id_hint").hide();

Loading…
Cancel
Save