diff --git a/Gemfile b/Gemfile index 758ef59dd..e40c468aa 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' if RUBY_PLATFORM =~ /darwin/ - # gem "rmagick", "= 2.15.4" ## osx must be this version + gem "rmagick", "= 2.15.4" ## osx must be this version elsif RUBY_PLATFORM =~ /linux/ - # gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel + gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel end gem 'certified' gem 'net-ssh', '2.9.1' diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 202327685..76d3d248b 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -1,3 +1,4 @@ +#coding=utf-8 # Redmine - project management software # Copyright (C) 2006-2013 Jean-Philippe Lang # @@ -148,7 +149,7 @@ class AccountController < ApplicationController return end end - render :layout => 'static_base' + render :layout => 'login_bigdata' end end @@ -172,12 +173,17 @@ class AccountController < ApplicationController end else us = UsersService.new - @user = us.register user_params.merge(:should_confirmation_password => true) + @user = us.register user_params.merge(:should_confirmation_password => false) case Setting.self_registration when '1' #register_by_email_activation(@user) unless @user.new_record? - redirect_to account_email_valid_path(:mail => @user.mail, :user_id => @user.id) + if params[:user][:mail] + redirect_to account_email_valid_path(:mail => @user.mail, :user_id => @user.id) + else + self.logged_user = @user + redirect_to my_account_url(:tip=>1) + end # flash[:notice] = l(:notice_account_register_done) # render action: 'email_valid', locals: {:mail => @user.mail} end @@ -267,6 +273,13 @@ class AccountController < ApplicationController req[:message] = faker.errors[:login] end + if valid_attr.eql?('phone') + faker.phone = valid_value + faker.valid? + req[:valid] = faker.errors[:phone].blank? + req[:message] = "" + end + if valid_attr.eql?('mail') faker.mail = valid_value faker.valid? @@ -278,6 +291,135 @@ class AccountController < ApplicationController render :json => req end + # 手机号或邮箱是否已注册 + def valid_register_user + req = Hash.new(false) + req[:message] = '' + + valid_attr = params[:valid] + valid_value = params[:value] + + if valid_attr.eql?('phone') + user = User.where(:phone => valid_value).first + req[:valid] = !user.nil? + req[:message] = user.nil? ? "该手机号未注册" : "" + elsif valid_attr.eql?('mail') + user = User.where(:mail => valid_value).first + req[:valid] = !user.nil? + req[:message] = user.nil? ? "该邮箱未注册" : "" + end + + render :json => req + end + + # 验证码是否有效 + def valid_verification_code + req = Hash.new(false) + req[:valid] = false + type = params[:type].to_i + if type == 1 || type == 2 || params[:phone] =~ /^1\d{10}$/ + code = VerificationCode.where(:phone => params[:phone], :code => params[:code], :code_type => (params[:type].to_i != 1 && params[:type].to_i != 2) ? 2 : params[:type].to_i ).last + else + code = VerificationCode.where(:email => params[:phone], :code => params[:code], :code_type => 3).last + end + req[:valid] = !code.nil? && (Time.now.to_i - code.created_at.to_i) <= 10*60 + render :json => req + end + + # 发送验证码:type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 + def get_verification_code + code = %W(0 1 2 3 4 5 6 7 8 9) + type = params[:type].to_i + req = Hash.new(false) + req[:status] = 0 + if type == 1 + if User.where(:phone => params[:value]).count > 0 + req[:status] = 2 + else + begin + verification_code = code.sample(6).join + status = Trustie::Sms.send(mobile: params[:value], code: verification_code) + if status + VerificationCode.create(:phone => params[:value], :status => 1, :code_type => 1, :code => verification_code) + end + rescue => e + Rails.logger.error "发送验证码出错: #{e}" + end + req[:status] = 1 + end + else + if params[:value] =~ /^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ + if User.where(:mail => params[:value]).count == 0 + req[:status] = 2 + else + begin + verification_code = code.sample(6).join + user = User.where(:mail => params[:value]).first + token = Token.new(:user => user, :action => "recovery") + if token.save + Mailer.run.lost_password(token, verification_code) + VerificationCode.create(:email => params[:value], :status => 1, :code_type => 3, :code => verification_code) + end + rescue => e + Rails.logger.error "发送验证码出错: #{e}" + end + req[:status] = 3 + req[:link] = params[:value].split("@")[1] + end + elsif params[:value] =~ /^1\d{10}$/ + if User.where(:phone => params[:value]).count == 0 + req[:status] = 2 + else + begin + verification_code = code.sample(6).join + status = Trustie::Sms.send(mobile: params[:value], code: verification_code) + if status + VerificationCode.create(:phone => params[:value], :status => 1, :code_type => 2, :code => verification_code) + end + rescue => e + Rails.logger.error "发送验证码出错: #{e}" + end + req[:status] = 1 + end + else + req[:status] = 2 + end + + end + render :json => req + end + + def reset_psd + if request.get? + @user = User.where("phone = '#{params[:value]}' or mail = '#{params[:value]}'").first + if @user + respond_to do |format| + format.html { render :layout => "login_bigdata"} + end + else + redirect_to signin_path + return + end + else + @user = User.find params[:user] + if @user + @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] + if @user.save + Token.where(:user_id => @user, :action => "recovery").destroy_all + respond_to do |format| + format.js + end + else + redirect_to signin_path + return + end + else + redirect_to signin_path + return + end + end + end + def email_valid begin @mail_type = params[:mail].split("@")[1] @@ -286,7 +428,7 @@ class AccountController < ApplicationController return render_404 end respond_to do |format| - format.html { render :layout => "base_mail"} + format.html { render :layout => "login_bigdata"} format.js end end @@ -309,14 +451,13 @@ class AccountController < ApplicationController def change_email user = User.find params[:user_id].to_i user.update_attributes(:mail => params[:value]) - result = {:email => user.mail} + result = {:email => user.mail, :email_link => user.mail.split("@")[1]} render :json => result end def email_activation - end private @@ -456,7 +597,7 @@ class AccountController < ApplicationController logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}" # flash[:error] = l(:notice_account_invalid_creditentials_new) # render signin_path(:login=>true) - render :action => 'email_activation' + render :action => 'email_activation',:layout => 'login_bigdata' end # Register a user for email activation. diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 0199e4d90..8ad0dce79 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -475,7 +475,6 @@ class AdminController < ApplicationController else @limit = 15#per_page_option end - @status = params[:status] || 1 scope = User.logged.status(@status) scope = scope.like(params[:name],params[:search_by][:id]) if params[:name].present? @@ -483,8 +482,7 @@ class AdminController < ApplicationController @user_pages = Paginator.new @user_count, @limit, params['page'] @user_base_tag = params[:id] ? 'base_users':'base' - @users = scope.offset(@user_pages.offset).limit(@user_pages.per_page) - + @users = scope.order(sort_clause).offset(@user_pages.offset).limit(@user_pages.per_page).all respond_to do |format| format.html { @groups = Group.all.sort diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 9994e5a3c..50fddc18e 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -47,6 +47,8 @@ class AtController < ApplicationController find_topic(id) when 'JournalsForMessage' find_journals_for_message(id) + when 'Journal' + find_journal(id) when 'Principal' find_principal(id) when 'BlogComment' @@ -134,8 +136,14 @@ class AtController < ApplicationController #Message def find_message(id) message = Message.find(id) - at_persons = message.board.messages.map(&:author) - (at_persons || []) + (find_project(message.board.project_id)||[]) + if message.board.course_id.nil? + at_persons = message.board.messages.map(&:author) + (at_persons || []) + (find_project(message.board.project_id)||[]) + else + type = 'Course' + course_id = message.board.course_id + find_at_users(type, course_id) + end end #News @@ -159,6 +167,12 @@ class AtController < ApplicationController #Journal def find_journal(id) + journal = Journal.find id + if journal.journalized_type == 'Issue' + issue_id = journal.issue.id + find_at_users(journal.journalized_type, issue_id) + end + end #Document diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 6ebd9f340..a8ca180c5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -310,7 +310,8 @@ class AttachmentsController < ApplicationController @history.version = @old_history.nil? ? 1 : @old_history.version + 1 @history.save #历史记录保存完毕 #将最新保存的记录 数据替换到 需要修改的文件记录 - @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes") + @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time') + @status = @old_attachment.is_publish # 如果附件描述被修改,则保存附件 unless params[:description] == @attachment.description @old_attachment.description = params[:description] @@ -327,6 +328,14 @@ class AttachmentsController < ApplicationController end end + def update_attachment_publish_time + @attachment = Attachment.find params[:id] + @status = params[:status].to_i + if @status == 0 + @attachment.update_attributes(:is_publish => 1, :publish_time => Time.now) + end + end + # prams[:type] => history 历史版本 def destroy if params[:type] == "history" diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 8a383f6f9..22f0ad84d 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -31,6 +31,7 @@ class AvatarController < ApplicationController end end + size = @temp_file.size if @temp_file && (@temp_file.size > 0) if @temp_file.size > Setting.upload_avatar_max_size.to_i @status = 1 @@ -65,7 +66,11 @@ class AvatarController < ApplicationController end end - Trustie::Utils::Image.new(diskfile,true).compress(300) + if @source_type == 'Contest' + Trustie::Utils::Image.new(diskfile,true).compress(900) + else + Trustie::Utils::Image.new(diskfile,true).compress(300) + end @status = 0 @msg = '' else @@ -75,6 +80,15 @@ class AvatarController < ApplicationController end @temp_file = nil + sleep(3) + + unless File.size(diskfile) < size + logger.info("###############################################################sleep") + sleep(0.5) + end + + #@src_file = diskfile + respond_to do |format| format.json{ render :inline => {status: @status, message:@msg, url:"#{@urlfile.to_s}?#{Time.now.to_i}"}.to_json,:content_type => 'text/html' diff --git a/app/controllers/contestant_works_controller.rb b/app/controllers/contestant_works_controller.rb index a8e1582e0..5a2371133 100644 --- a/app/controllers/contestant_works_controller.rb +++ b/app/controllers/contestant_works_controller.rb @@ -15,7 +15,7 @@ class ContestantWorksController < ApplicationController def new #更新消息 - if @contestwork.work_status == 1 + #if @contestwork.work_status == 1 noEvaluation = @contestwork.contest_messages.where("user_id =? and viewed =?", User.current.id, 0) noEvaluation.update_all(:viewed => true) @@ -24,9 +24,9 @@ class ContestantWorksController < ApplicationController respond_to do |format| format.html{ render :layout => "base_contests"} end - else - render_403 - end + #else + # render_403 + #end end def index diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bf1b88b4c..5260cd766 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -627,13 +627,14 @@ class CoursesController < ApplicationController member = @course.members.find params[:member_id] student_role = member.member_roles.where("role_id = 10").first teacher_role = member.member_roles.where("role_id = 7 || role_id = 9").first + + joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) + joined.destroy_all if member && member.deletable? && student_role user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id) if user_admin.size > 0 user_admin.destroy_all end - joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id) - joined.destroy_all if member.member_roles.count > 1&& student_role && teacher_role student_role.destroy diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index adab61b01..5d968dc47 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -483,6 +483,7 @@ class ExerciseController < ApplicationController end end =end + @name,@select_group = params[:name].to_s.strip || "",params[:group] @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? if @is_teacher @all_exercises = @course.exercises.order("created_at desc") @@ -490,17 +491,53 @@ class ExerciseController < ApplicationController @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") end student_id = @course.student.blank? ? "(-1)" : "(" + @course.student.map{|student| student.student_id}.join(",") + ")" - @exercise_count = @exercise.exercise_users.where("commit_status = 1 and user_id in #{student_id}").count - if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time <= Time.now) - @exercise_users_list = @exercise.exercise_users.where("user_id in #{student_id}") - @show_all = true; - elsif !@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time > Time.now - @exercise_users_list = @exercise.exercise_users.where("user_id = ? and user_id in #{student_id}",User.current.id) + if @select_group + if @select_group == "0" + none_group_students = @course.members.select{ |member| member.course_group_id == 0 } + if none_group_students.empty? + student_in_group = '(0)' + else + student_in_group = '(' + none_group_students.map{ |member| member.user_id }.join(',') + ')' + end + elsif @select_group == "-1" + all_group_students = @course.members.select{ |member| member.course_group_id } + if all_group_students.empty? + student_in_group = '(0)' + else + student_in_group = '(' + all_group_students.map{ |member| member.user_id }.join(',') + ')' + end + else + course_group = CourseGroup.find_by_id(@select_group) + group_students = course_group.users + if group_students.empty? + student_in_group = '(0)' + else + student_in_group = '(' + group_students.map{ |user| user.id }.join(',') + ')' + end + end + if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time <= Time.now) + @exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id in #{student_id} and user_id in #{student_in_group}"), @name + @show_all = true; + elsif !@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time > Time.now + @exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id = ? and user_id in #{student_id} and user_id in #{student_in_group}",User.current.id), @name + else + @exercise_users_list = [] + end + else - @exercise_users_list = [] + if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time <= Time.now) + @exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id in #{student_id}"), @name + @show_all = true; + elsif !@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time > Time.now + @exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id = ? and user_id in #{student_id}",User.current.id), @name + else + @exercise_users_list = [] + end end + @exercise_count = @exercise.exercise_users.where("commit_status = 1 and user_id in #{student_id}").count @left_nav_type = 8 respond_to do |format| + format.js format.html format.xls { filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls" @@ -654,6 +691,10 @@ class ExerciseController < ApplicationController # 更新提交状态 cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first cur_exercise_user.update_attributes(:status => 1, :commit_status => 1) + if @exercise.time && @exercise.time != -1 + score = calculate_student_score(@exercise, User.current) + cur_exercise_user.update_attributes(:score => score) + end # 答题过程中需要统计完成量 #@uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @@ -889,6 +930,19 @@ class ExerciseController < ApplicationController xls_report.string end + #根据条件过滤作业结果 + def search_exercise_member exercises,name + if name == "" + select_exercises = exercises + else + name = name.downcase + select_exercises = exercises.select{ |exercise| + exercise.user[:login].to_s.downcase.include?(name) || exercise.user.user_extensions[:student_id].to_s.downcase.include?(name) || (exercise.user[:lastname].to_s.downcase + exercise.user[:firstname].to_s.downcase).include?(name) + } + end + select_exercises + end + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 def get_exercise_user exercise_id,user_id eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 0f5a55ab9..67008ba1c 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -121,7 +121,7 @@ class ForumsController < ApplicationController order = "" @order_str = "" if(params[:reorder_complex]) - order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" + order = "replies_count #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" @order_str = "reorder_complex="+params[:reorder_complex] elsif(params[:reorder_popu]) order = "replies_count #{params[:reorder_popu]}" @@ -166,16 +166,16 @@ class ForumsController < ApplicationController order = "" @order_str = "" if(params[:reorder_complex]) - order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" + order = "#{Memo.table_name}.sticky desc, last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" @order_str = "reorder_complex="+params[:reorder_complex] elsif(params[:reorder_popu]) - order = "replies_count #{params[:reorder_popu]}" + order = "#{Memo.table_name}.sticky desc, replies_count #{params[:reorder_popu]}" @order_str = "reorder_popu="+params[:reorder_popu] elsif(params[:reorder_time]) - order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}" + order = "#{Memo.table_name}.sticky desc, #{Memo.table_name}.updated_at #{params[:reorder_time]}" @order_str = "reorder_time="+params[:reorder_time] else - order = "#{Memo.table_name}.updated_at desc" + order = "#{Memo.table_name}.sticky desc, #{Memo.table_name}.updated_at desc" @order_str = "reorder_time=desc" end @memo = Memo.new(:forum => @forum) diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index cb6c1505b..1812e7cff 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -156,7 +156,7 @@ class HomeworkCommonController < ApplicationController eval_start = homework_detail_manual.evaluation_start if eval_start.nil? || (Time.parse(eval_start.to_s) <= @homework.end_time && homework_detail_manual.comment_status <= 1) - homework_detail_manual.evaluation_start = @homework.end_time + 7 + homework_detail_manual.evaluation_start = (@homework.end_time + 7*24*60*60).strftime("%Y-%m-%d") homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 end end diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 8e84f2659..eb31cf13f 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -50,6 +50,8 @@ class MemosController < ApplicationController @memo = Memo.new(params[:memo]) @memo.forum_id = @forum.id @memo.author_id = User.current.id + # 问吧置顶sticky:1 置顶;0不置顶 + @memo.sticky = params[:memo][:sticky].to_i if params[:memo][:parent_id] @memo.root_id = (Memo.find params[:memo][:parent_id]).root_id.nil? ? params[:memo][:parent_id].to_i : (Memo.find params[:memo][:parent_id]).root_id @@ -189,6 +191,14 @@ class MemosController < ApplicationController end end + #置顶功能 + def change_sticky + @memo.sticky ? @memo.update_attribute(:sticky, false) : @memo.update_attribute(:sticky, true) + respond_to do |format| + format.html { redirect_to forum_memo_path(@memo.forum, @memo) } + end + end + private def find_memo diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 4cdd82d72..07fdd026d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -57,6 +57,9 @@ class MessagesController < ApplicationController @replies = @replies[@page * @limit..@page * @limit + 9] @reply = Message.new(:subject => "RE: #{@message.subject}") if @course + #帖子消息状态更新 + course_messages = CourseMessage.where("user_id =? and course_message_type =? and course_message_id =? and course_id =? and viewed =?", User.current.id, 'Message', @topic.id, @course.id, 0) + course_messages.update_all(:viewed => true) #@replies = @topic.children. #includes(:author, :attachments, :praise_tread_cache, {:board => :project}). #reorder("#{Message.table_name}.created_on DESC"). @@ -64,6 +67,11 @@ class MessagesController < ApplicationController #offset(@reply_pages.offset). #all #@replies = paginateHelper messages_replies,10 + # 班级帖子回复消息设为已读 + @replies.each do |comment| + course_message = CourseMessage.where(:course_message_type => 'Message', :course_message_id => comment.id, :user_id => User.current.id, :viewed => 0) + course_message.update_all(:viewed => 1) + end @left_nav_type = 2 respond_to do |format| format.js @@ -71,6 +79,9 @@ class MessagesController < ApplicationController end #render :action => "show", :layout => "base_courses"#by young elsif @project + #帖子消息状态更新 + project_messages = ForgeMessage.where("user_id =? and forge_message_type =? and forge_message_id =? and project_id =? and viewed =?", User.current.id, 'Message', @topic.id, @project.id, 0) + project_messages.update_all(:viewed => true) #@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page # @replies = @topic.children. # includes(:author, :attachments, {:board => :project}). @@ -78,11 +89,25 @@ class MessagesController < ApplicationController # limit(@reply_pages.per_page). # offset(@reply_pages.offset). # all + # 项目帖子回复消息设为已读 + @replies.each do |comment| + project_message = ForgeMessage.where(:forge_message_type => 'Message', :forge_message_id => comment.id, :user_id => User.current.id, :viewed => 0) + project_message.update_all(:viewed => 1) + end respond_to do |format| format.js format.html {render :layout => 'base_projects'} end elsif @contest + #帖子消息状态更新 + contest_messages = ContestMessage.where("user_id =? and contest_message_type =? and contest_message_id =? and contest_id =? and viewed =?", User.current.id, 'Message', @topic.id, @contest.id, 0) + contest_messages.update_all(:viewed => true) + + # 竞赛帖子回复消息设为已读 + @replies.each do |comment| + contest_message = ContestMessage.where(:contest_message_type => 'Message', :contest_message_id => comment.id, :user_id => User.current.id, :viewed => 0) + contest_message.update_all(:viewed => 1) + end @left_nav_type = 4 respond_to do |format| format.js @@ -187,13 +212,15 @@ class MessagesController < ApplicationController # @reply.reply_id = params[:id] parent.children << @reply else - @quote = params[:quote][:quote] + #@quote = params[:quote][:quote] @reply = Message.new @reply.author = User.current @reply.board = @board + @reply.subject = @topic.subject + @reply.content = params[:content] @reply.safe_attributes = params[:reply] - @reply.content = @quote + @reply.content - @reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] + #@reply.content = @quote + @reply.content + #@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] @reply.root_id = @topic.id @topic.children << @reply # @reply.reply_id = params[:id] diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 14151cc1f..f486a5b9c 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -636,7 +636,7 @@ class OrganizationsController < ApplicationController end def apply_subdomain organization = Organization.find(params[:id]) - @applied_message_count = AppliedMessage.where(:applied_id => organization.id, :name => params[:domain].downcase, :status => 1).count + @applied_message_count = AppliedMessage.where(:applied_id => organization.id, :name => params[:domain].downcase, :status => 0).count # 如果申请过该名字,怎不能重复申请 if @applied_message_count > 0 @flag = 1 @@ -670,7 +670,7 @@ class OrganizationsController < ApplicationController end # 自己处理自己的消息则不需要另外发送消息 if User.current.id != @applied_message.applied_user_id - AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 2, :applied_user_id => User.current.id, :name => org_domain.downcase) + OrgMessage.create(:user_id => params[:user_id], :organization_id => organization_id, :message_type => 'AgreeApplySubdomain', :message_id => organization_id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) end @applied_message.status = 2 @applied_message.updated_at = Time.now @@ -696,7 +696,7 @@ class OrganizationsController < ApplicationController applied_messages.update_all(:status => 4, :viewed => true, :updated_at => Time.now) # 自己处理自己的消息则不需要另外发送消息 if User.current.id != @applied_message.applied_user_id - AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 4, :applied_user_id => User.current.id, :name => org_domain.downcase) + OrgMessage.create(:user_id => params[:user_id], :organization_id => organization_id, :message_type => 'DisagreeApplySubdomain', :message_id => organization_id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) end @applied_message.status = 4 @applied_message.updated_at = Time.now diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 61aa7e21a..79ef6faa0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -33,7 +33,8 @@ class ProjectsController < ApplicationController :view_homework_attaches,:join_project, :project_home, :training_execute, :training_task_status] before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] - before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] + before_filter :require_admin, :only => [ :copy, :unarchive, :calendar] + before_filter :require_admin_or_manager, :only => [ :destroy] before_filter :file @@ -211,6 +212,12 @@ class ProjectsController < ApplicationController @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] + if params[:course_id] + @course = Course.find params[:course_id] + elsif params[:contest_id] + @contest = Contest.find params[:contest_id] + end + render :layout => 'new_base' else redirect_to signin_url @@ -793,7 +800,7 @@ class ProjectsController < ApplicationController GITLABTYPE = "Repository::Gitlab" def archive if request.post? - if @project.archive && @project.gpid + if @project.destroy && @project.gpid # 删除版本库信息 begin g = Gitlab.client @@ -1103,36 +1110,52 @@ class ProjectsController < ApplicationController redirect_to project_url(@project) end + REP_TYPE = "Repository::Gitlab" # Delete @project def destroy - @project_to_destroy = @project - @project_to_destroy.destroy + ActiveRecord::Base.transaction do + g = Gitlab.client + g.delete_project(@project.gpid) + # 删除Trustie版本库记录 + repoisitory = Repository.where(:project_id => @project.id, :type => GITLABTYPE).first + repoisitory.delete + @project.update_column(:gpid, nil) + @project.update_column(:forked_from_project_id, nil) + @project_to_destroy = @project + @project_to_destroy.destroy + end respond_to do |format| - format.html { redirect_to admin_projects_url } - format.api { render_api_ok } + if params[:type] == "project" + format.html{redirect_to user_path(User.current)} + else + format.html{redirect_to admin_projects_url(:status => params[:status])} + end end # hide project in layout @project = nil end - REP_TYPE = "Repository::Gitlab" + # Delete @project's repository def destroy_repository if is_project_manager?(User.current.id, @project.id) @gitlab_repository = Repository.where(:project_id => @project, :type => REP_TYPE).first @is_true = params[:is_true] - if @is_true + unless @is_true.nil? begin g = Gitlab.client - g.delete_project(@project.gpid) - @gitlab_repository.destroy - @gitlab_repository = nil - scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first - @repository = Repository.factory(scm) - @repository.is_default = @project.repository.nil? - @project.update_attribute(:gpid, nil) + d_project = g.delete_project(@project.gpid) + if d_project + @gitlab_repository.destroy + @project.update_attribute(:gpid, nil) + @gitlab_repository = nil + end rescue Exception => e - puts e + if @gitlab_repository + @gitlab_repository.destroy + @project.update_attribute(:gpid, nil) + @gitlab_repository = nil + end end end else @@ -1294,6 +1317,13 @@ class ProjectsController < ApplicationController return projects end - #gcmend + def require_admin_or_manager + return unless require_login + if !(User.current.admin? || User.current.manager_of_project?(@project.id)) + render_403 + return false + end + true + end end diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index cd433a450..9ba631913 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -160,7 +160,7 @@ class StudentWorkController < ApplicationController student_work.name = params[:title] student_work.description = params[:src] - if @homework.end_time < Time.now.to_s + if !is_test && @homework.end_time < Time.now.to_s student_work.late_penalty = @homework.late_penalty else student_work.late_penalty = 0 @@ -954,6 +954,9 @@ class StudentWorkController < ApplicationController render_attachment_warning_if_needed(@new_score) if @new_score.save + if @work.re_commit && @new_score.reviewer_role != 3 + @work.re_commit = 0 + end if @homework.homework_type == 3 @is_group_leader = !@work.student_work_projects.empty? end @@ -1314,29 +1317,43 @@ class StudentWorkController < ApplicationController end def forbidden_anonymous_comment - @homework.update_column('anonymous_comment', @homework.anonymous_comment == 0 ? 1 : 0) homework_detail_manual = @homework.homework_detail_manual - homework_detail_programing = @homework.homework_detail_programing - if @homework.anonymous_comment == 1 - homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.4 : 1.0 - else - homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.3 : 0.6 - end - if @homework.homework_type == 2 && homework_detail_programing + if homework_detail_manual.comment_status != 0 + @homework.update_column('anonymous_comment', @homework.anonymous_comment == 0 ? 1 : 0) + homework_detail_programing = @homework.homework_detail_programing if @homework.anonymous_comment == 1 - homework_detail_programing.ta_proportion = 0.6 + homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.4 : 1.0 + @status = 1 else - homework_detail_programing.ta_proportion = 0.5 + if @homework.end_time < Time.now + homework_detail_manual.evaluation_start = (Time.now + 7*24*60*60).strftime("%Y-%m-%d") + homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 + @status = 2 + else + homework_detail_manual.evaluation_start = (@homework.end_time + 7*24*60*60).strftime("%Y-%m-%d") + homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 + @status = 3 + end + homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.3 : 0.6 end + if @homework.homework_type == 2 && homework_detail_programing + if @homework.anonymous_comment == 1 + homework_detail_programing.ta_proportion = 0.6 + else + homework_detail_programing.ta_proportion = 0.5 + end + end + homework_detail_manual.save + homework_detail_programing.save if homework_detail_programing + @homework.student_works.each do |student_work| + set_final_score @homework,student_work + student_work.save + end + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i + else + @status = 0 end - homework_detail_manual.save - homework_detail_programing.save if homework_detail_programing - @homework.student_works.each do |student_work| - set_final_score @homework,student_work - student_work.save - end - @user_activity_id = params[:user_activity_id].to_i - @hw_status = params[:hw_status].to_i end def revise_attachment @@ -1351,6 +1368,7 @@ class StudentWorkController < ApplicationController student_work = StudentWork.find attachment.container_id CourseMessage.create(:user_id => student_work.homework_common.user_id, :course_id => student_work.homework_common.course_id, :viewed => false,:course_message_id=>attachment.container_id,:course_message_type=>'StudentWork',:status=>2) end + @work.update_attributes(:re_commit => 1) respond_to do |format| format.js end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 41c62cf85..ddff55733 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1436,8 +1436,8 @@ class UsersController < ApplicationController end end - homework_detail_manual.evaluation_start = homework.end_time + 7 if homework.end_time - homework_detail_manual.evaluation_end = homework.end_time + 14 if homework.end_time + homework_detail_manual.evaluation_start = (homework.end_time + 7*24*60*60).strftime("%Y-%m-%d") if homework.end_time + homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 if homework.end_time homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 homework_detail_manual.absence_penalty = 0 homework.homework_detail_manual = homework_detail_manual @@ -2089,6 +2089,8 @@ class UsersController < ApplicationController def show if User.current == @user + # 点击小铃铛,更新点击时间 + update_onclick_time if params[:click_user_message] == 'true' # 全部设为已读 # 自己的主页显示消息 messages_all = MessageAll.where(:user_id => @user.id) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index ad5f5b9d4..fcbdb2921 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -202,6 +202,7 @@ class VersionsController < ApplicationController @is_setting = params[:is_setting] @is_create = params[:is_create] @is_index = params[:is_index] + @version_id = params[:id] end def update @@ -276,10 +277,11 @@ class VersionsController < ApplicationController end # 判断里程碑是否重名 + # 项目内的里程碑不能重名,项目之间的里程碑能重名 def judge_version_title begin version = Version.where(:name => params[:version_name], :project_id => @project.id).first - if version.blank? + if version.blank? || version.id == params[:version_id].to_i result = {:result => true} else result = {:result => false} diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index f2922891b..96cbf26c4 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -6,7 +6,7 @@ class ZipdownController < ApplicationController #检查权限 #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] ## 200M - MAX_DOWN_SIZE = 200 * 1024 * 1024 + MAX_DOWN_SIZE = 500 * 1024 * 1024 include ZipService @@ -32,7 +32,7 @@ class ZipdownController < ApplicationController def assort if params[:obj_class] == "Bid" bid = Bid.find params[:obj_id] - render_403 if User.current.allowed_to?(:as_teacher,bid.courses.first) + #render_403 if User.current.allowed_to?(:as_teacher,bid.courses.first) zipfile = checkfileSize(bid.homeworks) { zip_bid bid } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c207b827d..c8272746e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -95,6 +95,10 @@ module ApplicationHelper Output.where(:game_id => game).count end + def shixun_final_score myshixun + Game.find_by_sql("SELECT sum(final_score) as score FROM `games` where myshixun_id='#{myshixun.id}';") + end + # def user_blogs_path(resource,parameters={}) # super # end @@ -2611,7 +2615,7 @@ module ApplicationHelper if attachment.container if attachment.container.class.to_s=="PhoneAppVersion" candown = true - elsif attachment.container.class.to_s != "HomeworkAttach" && attachment.container.class.to_s != "StudentWork" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project + elsif attachment.container.class.to_s != "HomeworkAttach" && attachment.container.class.to_s != "StudentWork" && attachment.container.class.to_s != "ContestantWork" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project project = attachment.container.project candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) elsif attachment.container.is_a?(Project) @@ -2685,7 +2689,8 @@ module ApplicationHelper #如果学生作品被打分后修改,应该给老师提示 def send_message_to_teacher student_work if StudentWork === student_work - if student_work.student_works_scores.any? + if student_work.student_works_scores.where("reviewer_role != 3").any? + student_work.update_column('re_commit', 1) course = student_work.homework_common.course course.members.map(&:user_id).uniq.each do|user_id| if User.find(user_id).allowed_to?(:as_teacher, course) @@ -3298,7 +3303,7 @@ module ApplicationHelper def user_for_contest_work homework,is_contestant,work count = homework.contestant_works.has_committed.count if User.current.logged? - if User.current.member_of_contest?(homework.contest) + if User.current.member_of_contest?(homework.contest) || User.current.admin? if !is_contestant #老师显示作品数量 link_to "作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => "c_blue" else #学生显示提交作品、修改作品等按钮 @@ -3310,6 +3315,12 @@ module ApplicationHelper else link_to "提交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_blue' end + elsif work.nil? && homework.work_status > 1 + if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project + link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' + else + link_to "补交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_blue' + end else if homework.work_status == 1 && work.user_id == User.current.id link_to "修改作品(#{count})", edit_contestant_work_path(work.id),:class => 'c_blue' diff --git a/app/helpers/contestant_works_helper.rb b/app/helpers/contestant_works_helper.rb index 02059f6ed..583dfabf9 100644 --- a/app/helpers/contestant_works_helper.rb +++ b/app/helpers/contestant_works_helper.rb @@ -1,7 +1,7 @@ #encoding: utf-8 module ContestantWorksHelper - def get_status status + def get_contest_new_status status str = "" case status when 0 diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index afe16497b..89a9455f5 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -56,15 +56,19 @@ module StudentWorkHelper result end - def get_status status + def get_status status, re_commit str = "" - case status - when 0 - str = "未提交" - when 1 - str = "已提交" - when 2 - str = "迟交" + if re_commit + str = "重新提交" + else + case status + when 0 + str = "未提交" + when 1 + str = "已提交" + when 2 + str = "迟交" + end end str end diff --git a/app/models/biding_project.rb b/app/models/biding_project.rb index decf85812..d02bef2e3 100644 --- a/app/models/biding_project.rb +++ b/app/models/biding_project.rb @@ -3,7 +3,7 @@ class BidingProject < ActiveRecord::Base attr_accessible :bid_id, :project_id, :user_id, :description,:reward belongs_to :bid - belongs_to :project + # belongs_to :project belongs_to :user DESCRIPTION_LENGTH_LIMIT = 500 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 3323fb331..440eff661 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -111,8 +111,9 @@ class HomeworkCommon < ActiveRecord::Base #作业微信通知delay def send_homework_wechat_message_delay self.course.members.each do |m| - # if m.user_id != self.user_id - #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) + if m.user_id != self.user_id + self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) + end rolesids = [] m.roles.each do |role| rolesids << role.id diff --git a/app/models/mailer.rb b/app/models/mailer.rb index a03c35381..ddefd88e6 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -837,10 +837,11 @@ class Mailer < ActionMailer::Base :subject => l(:mail_subject_register, Setting.app_title) end - def lost_password(token) + def lost_password(token, code="111111") set_language_if_valid(token.user.language) + @login = token.user.try(:login) @token = token - @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value) + @code = code mail :to => token.user.mail, :subject => l(:mail_subject_lost_password, Setting.app_title) end diff --git a/app/models/news.rb b/app/models/news.rb index 1b091cf0d..21f663271 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -69,7 +69,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_course_activity, :add_author_as_watcher, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send, :act_as_contest_message + after_create :act_as_course_activity, :add_author_as_watcher, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score @@ -230,13 +230,13 @@ class News < ActiveRecord::Base end def act_as_contest_message - if self.contest_id - self.contest.contest_members.each do | m| - if m.user_id != self.author_id - self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false) - end - end - end + # if self.contest_id + # self.contest.contest_members.each do | m| + # if m.user_id != self.author_id + # self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false) + # end + # end + # end end def delay_news_send @@ -265,7 +265,7 @@ class News < ActiveRecord::Base vs = [] self.contest.contest_members.each do | m| if m.user_id != self.author_id - vs << {contest_message_type:'Contest',contest_message_id:self.id, :user_id => m.user_id, + vs << {contest_message_type:'News',contest_message_id:self.id, :user_id => m.user_id, :contest_id => self.contest_id, :viewed => false} if vs.size >= 30 diff --git a/app/models/project.rb b/app/models/project.rb index d5d2da038..d68be1f2d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -70,8 +70,8 @@ class Project < ActiveRecord::Base has_many :repositories, :dependent => :destroy, conditions: "hidden=false" has_many :changesets, :through => :repository #added by xianbo for delete biding_project - has_many :biding_projects, :dependent => :destroy - has_many :contesting_projects, :dependent => :destroy + # has_many :biding_projects, :dependent => :destroy + # has_many :contesting_projects, :dependent => :destroy has_many :softapplications, :through => :projecting_softapplications #ended by xianbo # added by fq diff --git a/app/models/student_work.rb b/app/models/student_work.rb index ffc369af0..9ea0e75eb 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,6 @@ #学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品 class StudentWork < ActiveRecord::Base - attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty, :re_commit belongs_to :homework_common belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 98d6d7b00..c5696385e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -247,7 +247,8 @@ class User < Principal LOGIN_LENGTH_LIMIT = 30 MAIL_LENGTH_LIMIT = 60 - validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } + #validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } + validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only @@ -405,7 +406,8 @@ class User < Principal end user = User.current onclick_time = user.onclick_time.onclick_time - course_count = CourseMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count + delete_courses = Course.where(:is_delete => 1).blank? ? "(-1)" : "(" + Course.where(:is_delete => 1).map(&:id).join(",") + ")" + course_count = CourseMessage.where("user_id =? and viewed =? and created_at >? and course_id not in #{delete_courses}", user.id, 0, onclick_time).count contest_count = ContestMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count @@ -536,6 +538,7 @@ class User < Principal end VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i + VALID_PHONE_REGEX = /^1\d{10}$/ # VALID_EMAIL_REGEX = /^[0-9a-zA-Z_-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)+$/ # Returns the user that matches provided login and password, or nil #登录,返回用户名与密码匹配的用户 @@ -547,6 +550,8 @@ class User < Principal return nil if login.empty? || password.empty? if (login =~ VALID_EMAIL_REGEX) user = find_by_mail(login) + elsif (login =~ VALID_PHONE_REGEX) + user = find_by_phone(login) else user = find_by_login(login) end @@ -780,6 +785,10 @@ class User < Principal where("LOWER(mail) = ?", mail.to_s.downcase).first end + def self.find_by_phone(phone) + where("phone = ?", phone).first + end + # Returns true if the default admin account can no longer be used def self.default_admin_account_changed? !User.active.find_by_login("admin").try(:check_password?, "admin") @@ -943,6 +952,15 @@ class User < Principal end end + def manager_of_project?(project_id) + @result = false + mem = Member.where("user_id = ? and project_id = ?", self.id, project_id) + unless mem.blank? + @result = mem.first.roles.to_s.include?("Manager") ? true : false + end + return @result + end + # 判断是否是竞赛的主办人 def admin_of_contest?(contest) if contest.nil? diff --git a/app/models/verification_code.rb b/app/models/verification_code.rb new file mode 100644 index 000000000..189bdbdeb --- /dev/null +++ b/app/models/verification_code.rb @@ -0,0 +1,5 @@ +class VerificationCode < ActiveRecord::Base + #status:发送状态 + #code_type:发送类型:1 手机注册 2 手机找回密码 3 邮箱找回密码 + attr_accessible :code, :code_type, :email, :phone, :status +end diff --git a/app/services/contests_service.rb b/app/services/contests_service.rb index b4bb1acde..143be7282 100644 --- a/app/services/contests_service.rb +++ b/app/services/contests_service.rb @@ -24,18 +24,34 @@ class ContestsService if params[:invite_code].present? role_ids = params[:role] - #如果已经发送过消息了,那么就要给个提示 - if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0 - @state = 7 - else - if role_ids.size == 1 - AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_ids[0], :status => 0) - else - role_ids.each do |role_id| - AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_id, :status => 0) - end + if role_ids.include?("15") + member = ContestMember.new(:user_id => current_user.id) + contest.contest_members << member + contest_member_roles = member.contest_member_roles + contest_member_roles << ContestMemberRole.new(:role_id => 15) + ContestantForContest.create(:student_id => current_user.id, :contest_id => contest.id) + + # 给管理员发消息 + admins = contest_managers contest + admins.each do |member| + course_join = ContestMessage.new(:user_id =>member.user_id, :contest_message_id=>current_user.id,:contest_id => contest.id,:contest_message_type=>"JoinContest", :content => role_ids, :viewed => false, :status => 2) + course_join.save + end + @state = 0 + else + #如果已经发送过消息了,那么就要给个提示 + if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :status => 0).count != 0 + @state = 7 + else + if role_ids.size == 1 + AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_ids[0], :status => 0) + else + role_ids.each do |role_id| + AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_id, :status => 0) + end + end + @state = 6 end - @state = 6 end else @state = 1 diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 494bf95fc..528fc24a0 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -10,14 +10,24 @@ class UsersService #参数约定 #成功返回注册后的User实例,失败直接抛异常 + # 生成邀请码 + CODES = %W(0 1 2 3 4 5 6 7 8 9) + def generate_user_login type + code = CODES.sample(8).join + code = type + code.to_s + return generate_user_login(type) if User.where(login: code).present? + code + end + def register(params) @user = User.new @user.admin = false @user.register - @user.login = params[:login] + @user.login = generate_user_login params[:mail] ? 'm' : (params[:phone] ? 'p' : 'w') @user.mail = params[:mail] - password = params[:password] - password_confirmation = params[:password_confirmation] + @user.phone = params[:phone] + password = params[:password] || params[:mail_password] + password_confirmation = params[:password] || params[:mail_password] should_confirmation_password = params[:should_confirmation_password] if !password.blank? && !password_confirmation.blank? && should_confirmation_password @user.password, @user.password_confirmation = password, password_confirmation @@ -26,13 +36,17 @@ class UsersService else @user.password = "" end - case Setting.self_registration - when '1' - @user = email_activation_register(@user) - when '3' - @user = automatically_register(@user) - else - @user = administrator_manually__register(@user) + if params[:mail] + case Setting.self_registration + when '1' + @user = email_activation_register(@user) + when '3' + @user = automatically_register(@user) + else + @user = administrator_manually__register(@user) + end + else + @user = automatically_register(@user) end if @user.id != nil ue = @user.user_extensions ||= UserExtensions.new diff --git a/app/views/account/_reset_psd_notice_box.html.erb b/app/views/account/_reset_psd_notice_box.html.erb new file mode 100644 index 000000000..3e3324b05 --- /dev/null +++ b/app/views/account/_reset_psd_notice_box.html.erb @@ -0,0 +1,12 @@ +
\ No newline at end of file diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb index 62f1e1fff..c7a7dfb79 100644 --- a/app/views/account/email_activation.html.erb +++ b/app/views/account/email_activation.html.erb @@ -1,90 +1,63 @@ -您的账号尚未激活,请先进入您的注册邮箱(<%= @user.mail %>),激活您的账号。
- - <%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %> -如果您尚未收到激活邮件,请按照以下步骤操作:
-+ <%= link_to '首页', home_path %> + | + <%= link_to "帮助中心", "#{Setting.protocol}://#{Setting.host_name}/forums/1/memos/1168" %> +
+注册成功! - 请在24小时内点击邮件中的链接来激活您的账号。
-请登录邮箱(<%= @user.mail %>)收取账号激活邮件。
点击邮件中的激活链接,方可使用该账号
-
- <%= l(:label_check_email)%> - <%= link_to "".html_safe, { :controller => 'account', :action => 'resendmail', :user => @user}, :remote => true, :method => 'get' %> -
-如果您一直收不到激活邮件,请按照以下步骤操作:
-+ <%= link_to '首页', home_path %> + | + <%= link_to "帮助中心", "#{Setting.protocol}://#{Setting.host_name}/forums/1/memos/1168" %> +
+"><%= h @message %>
- <% end %> -+ <%= link_to '首页', home_path %> + | + <%= link_to "帮助中心", "#{Setting.protocol}://#{Setting.host_name}/forums/1/memos/1168" %> +
+登录
+ + + + + + +没有账号? + 立即注册 +
+ + <%= form_tag(signin_path,:id=>'main_login_form',:method=>'post') do %> <%= back_url_hidden_field_tag %><%= flash.empty? || flash[:error].nil? ? "" : flash[:error].html_safe %>
+<%= flash.empty? || flash[:error].nil? ? "" : flash[:error].html_safe %>
通过注册邮箱链接重设密码
- - <%= text_field_tag 'mail', nil, :size => 40, :placeholder => '请输入注册邮箱',:class=>'NomalInput mb20'%> - <% if flash[:error] %> -<%= flash[:error]%>
- - <% elsif flash[:notice] %> -<%= flash[:notice]%>
- - <% end %> - - <% end %> + -