From 40dfc7d490ed6d8b0b1123af9152fe4b9622c09a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 23 Oct 2019 17:27:15 +0800 Subject: [PATCH 01/11] =?UTF-8?q?python=E6=96=87=E4=BB=B6=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 4e587513a..4b2e3f54f 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -264,11 +264,13 @@ class MyshixunsController < ApplicationController unless @hide_code || (@myshixun.shixun&.vnc_evaluate && params[:evaluate].present?) # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - content = if @myshixun.mirror_name.select {|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - params[:content].gsub(/\t/, ' ').gsub(/ /, ' ') # 这个不是空格,在windows机器上带来的问题 - else - params[:content] - end + + content = + if python_file?(path) + params[:content].gsub(/\t/, ' ').gsub(/ /, ' ') + else + params[:content] + end uid_logger_dubug("###11222333####{content}") uid_logger_dubug("###222333####{last_content}") @@ -374,4 +376,9 @@ class MyshixunsController < ApplicationController @repo_path = @myshixun.try(:repo_path) @path = params[:path] end + + def python_file?(path) + false if path.blank? + path.to_s.split(".").last.downcase == "py" + end end From e83ffc80719a8312b96787f5a56fa2c124f1cce0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 25 Oct 2019 09:32:28 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/competitions_controller.rb | 2 +- .../competition_settings/index.html.erb | 68 ++++++++++--------- ...1023103633_add_column_to_stage_sections.rb | 10 --- ...1025012950_add_column_to_stage_sections.rb | 8 +++ 4 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 db/migrate/20191023103633_add_column_to_stage_sections.rb create mode 100644 db/migrate/20191025012950_add_column_to_stage_sections.rb diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 009c3183f..2c3d00529 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -69,7 +69,7 @@ class Competitions::CompetitionsController < Competitions::BaseController end def update_md_content - tip_exception("标题和内容不能为空") if params[:name].blank? || params[:content].blank? + tip_exception("内容不能为空") if params[:content].blank? tip_exception("缺少competition_module_id") if params[:competition_module_id].blank? ActiveRecord::Base.transaction do com_module = current_competition.competition_modules.find_by!(id: params[:competition_module_id]) diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index c06dc0000..97784ef79 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -324,7 +324,7 @@
<% if @competition.competition_stages.count > 0 %> - <% @competition.competition_stages.each do |stage| %> + <% @competition.competition_stages.each_with_index do |stage, index| %> <%= form_tag(admins_competition_competition_stage_path(competition_id: @competition.id, id: stage.id), method: :put, class: 'stage_update_form flex-1', remote: true) do %>
@@ -345,42 +345,44 @@ 保存
-
-
- 第1阶段 -
-
- 有效时间: -
- -
- ~ -
- -
- 任务完成要求: -
- -
- / -
- -
- (总任务) - 成绩来源: -
- +
+ <% stage.competition_stage_sections.each_with_index do |section, j| %> +
+ 第<%= j + 1 %>阶段 +
+
+ 有效时间: +
+ <%= text_field_tag 'stage[][start_time]', section.start_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section_start_time form-control', placeholder: '有效开始时间' %> +
+ ~ +
+ <%= text_field_tag 'stage[][end_time]', section.end_time&.strftime('%Y-%m-%d %H:%M'), autocomplete: 'off', class: 'section_end_time form-control', placeholder: '有效结束时间' %> +
+ 任务完成要求: +
+ +
+ / +
+ +
+ (总任务) + 成绩来源: +
+ +
+
-
-
- + 删除 -
+
+ <% end %>
<% end %> diff --git a/db/migrate/20191023103633_add_column_to_stage_sections.rb b/db/migrate/20191023103633_add_column_to_stage_sections.rb deleted file mode 100644 index baa1754fa..000000000 --- a/db/migrate/20191023103633_add_column_to_stage_sections.rb +++ /dev/null @@ -1,10 +0,0 @@ -class AddColumnToStageSections < ActiveRecord::Migration[5.2] - def change - def change - add_column :competition_stage_sections, :mission_count, :integer, default: 0 - add_column :competition_stage_sections, :score_source, :integer, default: 0 - - add_column :competition_entries, :shixun_identifier, :string - end - end -end diff --git a/db/migrate/20191025012950_add_column_to_stage_sections.rb b/db/migrate/20191025012950_add_column_to_stage_sections.rb new file mode 100644 index 000000000..5eb96aea9 --- /dev/null +++ b/db/migrate/20191025012950_add_column_to_stage_sections.rb @@ -0,0 +1,8 @@ +class AddColumnToStageSections < ActiveRecord::Migration[5.2] + def change + add_column :competition_stage_sections, :mission_count, :integer, default: 0 + add_column :competition_stage_sections, :score_source, :integer, default: 0 + + add_column :competition_entries, :shixun_identifier, :string + end +end From b59cfd52e8a59237892b8cf1998700beb3cfe8c5 Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Fri, 25 Oct 2019 09:53:18 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=B8=BB=E5=8A=9E=E6=96=B9=E5=92=8C?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/competition_settings/index.js | 13 +++++++++ .../admins/competition_settings.scss | 27 +++++++++++++++++++ app/assets/stylesheets/common.scss | 1 + .../competition_settings/index.html.erb | 23 ++++++++++++++-- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js index cc56c8641..6568ab43f 100644 --- a/app/assets/javascripts/admins/competition_settings/index.js +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -107,6 +107,19 @@ $(document).on('turbolinks:load', function(){ } }); +//添加主办方或者开放范围 +function addSponsor(item){ + var html=''; + $(item).parents(".sponsorPanel").append(html); +} +//删除 +function del_sponsor(item){ + $(item).parents(".sponsor_label").remove(); +} $(function () { //MD编辑 diff --git a/app/assets/stylesheets/admins/competition_settings.scss b/app/assets/stylesheets/admins/competition_settings.scss index 690cc2207..cef12cae3 100644 --- a/app/assets/stylesheets/admins/competition_settings.scss +++ b/app/assets/stylesheets/admins/competition_settings.scss @@ -40,6 +40,33 @@ line-height: 20px; } + .sponsor_label{ + border:1px solid #4CACFF; + border-radius: 5px; + background-color: rgba(76,172,255,0.3); + color: #333; + padding:0px 4px; + height: 30px; + line-height: 30px; + float: left; + margin: 4px 5px; + + span{ + display: block; + float: left; + height: 28px; + line-height: 28px; + margin-right: 5px; + } + + a{ + font-size: 18px; + float: left; + height: 28px; + line-height: 28px; + } + } + .large_panel{ padding:0px 15px; diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 90cdef268..19df03619 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -29,6 +29,7 @@ input.form-control { .flex-1 { flex: 1; } +.fl{float: left} .no_padding{padding: 0px!important;} .font-12 { font-size: 12px !important; } .font-14 { font-size: 14px !important; } diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 34a326dee..580b9b585 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -93,12 +93,31 @@
-
+
主办方
-
+
+ + + +
+
+
+
+ 开放范围 +
+
+ + +
From 11df2d33362c24d0be218c083990647f941c7a75 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 25 Oct 2019 09:55:18 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/competitions/competitions/common_header.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/competitions/competitions/common_header.json.jbuilder b/app/views/competitions/competitions/common_header.json.jbuilder index 0ecf6cfd5..2a1e0a92d 100644 --- a/app/views/competitions/competitions/common_header.json.jbuilder +++ b/app/views/competitions/competitions/common_header.json.jbuilder @@ -21,6 +21,7 @@ json.stages if @competition.mode == 2 json.course_id @competition.competition_mode_setting&.course_id + json.invite_code @competition.competition_mode_setting&.course&.invite_code json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course) end From 380f2a62d7ebb0108ad1459a53270d87ede1fab8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 25 Oct 2019 09:58:26 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/competition_module.rb | 2 +- app/views/competitions/competition_modules/show.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/competition_module.rb b/app/models/competition_module.rb index 3fdab6b37..3b1bfddda 100644 --- a/app/models/competition_module.rb +++ b/app/models/competition_module.rb @@ -3,7 +3,7 @@ class CompetitionModule < ApplicationRecord belongs_to :competition - has_one :competition_module_md_content, dependent: :destroy + has_many :competition_module_md_contents, dependent: :destroy def module_url result_url = url.present? ? url : case module_type diff --git a/app/views/competitions/competition_modules/show.json.jbuilder b/app/views/competitions/competition_modules/show.json.jbuilder index 116934ee8..14c3c0f57 100644 --- a/app/views/competitions/competition_modules/show.json.jbuilder +++ b/app/views/competitions/competition_modules/show.json.jbuilder @@ -1,6 +1,6 @@ json.extract! @module, :id, :name, :position, :url -md = @module.competition_module_md_content +md = @module.competition_module_md_contents.take if md.present? json.md_id md.id json.md_name md.name From 86c1c370be4ab05d8bf36cbc17830318c7df5106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 25 Oct 2019 10:01:19 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=A4=B4=E9=83=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Competitioncommon/CompetitionCommon.js | 64 +++++++++++++++++-- .../CompetitionContentsMd.js | 1 - 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js index a83f799fb..40bf83f5e 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js @@ -60,6 +60,22 @@ class CompetitionCommon extends Component{ }).catch((error) => { console.log(error) }) + + // console.log("调用了GetenrollmentAPI"); + const zul = `/competitions/${this.props.match.params.identifier}/competition_staff.json`; + axios.get((zul)).then((result) => { + if (result) { + if (result.data) { + + this.setState({ + signupdata:result.data + }) + + } + } + }).catch((error) => { + //// //////console.log(error); + }) } getrightdatas=(e)=>{ @@ -80,7 +96,7 @@ class CompetitionCommon extends Component{ }) } getrightdata=(id,typeid,module_url,has_url)=>{ - console.log(id,typeid,module_url,has_url) + this.setState({ module_id:id, module_type:typeid @@ -122,10 +138,47 @@ class CompetitionCommon extends Component{ } + gotocourse=(url)=>{ + if(this.props.checkIfLogin()===false){ + this.props.showLoginDialog() + return + } + if(this.props.checkIfProfileCompleted()===false){ + this.props.showProfileCompleteDialog() + return + } + if(url===undefined){ + let {data,signupdata}=this.state; + + if(signupdata.enrolled===true){ + this.props.history.replace(`/courses/${data.course_id}`); + }else{ + if(data.member_of_course===true){ + this.props.history.replace(`/courses/${data.course_id}`); + }else{ + // 以学生身份调用加入课堂 进入课堂首页 + let url="/courses/apply_to_join_course.json" + axios.post(url, { + invite_code:data.invite_code, + student:1 + } + ).then((response) => { + if(response.data.status===0){ + this.props.history.replace(`/courses/${data.course_id}`); + } + }) + } + + } + }else{ + this.props.history.replace(url); + } + + } render() { let {data,bannerdata,module_type,Competitionedittype,mdContentdata}=this.state; - console.log(module_type) + return ( data===undefined?"":
@@ -204,10 +257,9 @@ class CompetitionCommon extends Component{ : - } + data.competition_status==="progressing"?:""} {data&&data.enroll_end_time===null?"":`报名截止时间:${data&&data.enroll_end_time}`} diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js index f5043f187..8a1bd9fd6 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js @@ -100,7 +100,6 @@ class CompetitionContentsMd extends Component{ md_content_id:this.props.mdContentdata.md_id, competition_module_id:this.props.mdContentdata.id, content:mdContnet, - name:"编辑", attachment_ids:attachment_ids } ).then((response) => { From 3542fbc875b7f880183da6a848c85a7da9b3ef72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 25 Oct 2019 10:02:41 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/competitions/Competitioncommon/CompetitionCommon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js index 40bf83f5e..2fcdfb524 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js @@ -227,7 +227,7 @@ class CompetitionCommon extends Component{
{data.competition_status==="nearly_published"?"--":data&&data.visits_count}
-
{data.competition_status==="nearly_published"?"--":data&&data.member_count}
+
this.gotocourse(`/newcompetitions/${this.props.match.params.identifier}/enroll`)}>{data.competition_status==="nearly_published"?"--":data&&data.member_count}
From 625c7fd7b592e7befd178ec842e1eb88a40e6231 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 25 Oct 2019 10:16:57 +0800 Subject: [PATCH 08/11] weapp: add register code api && competition: add membets count result --- .../competition_teams_controller.rb | 1 + .../weapps/register_codes_controller.rb | 24 +++++++++++++++++++ .../competition_teams/index.json.jbuilder | 1 + config/routes.rb | 1 + 4 files changed, 27 insertions(+) create mode 100644 app/controllers/weapps/register_codes_controller.rb diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index f20c87b0d..8b69f1872 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -121,6 +121,7 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController @all_count = teams.count @all_teams = paginate(teams.includes(:user, users: { user_extension: :school })) + @all_member_count = current_competition.team_members.count end def user_competition_teams diff --git a/app/controllers/weapps/register_codes_controller.rb b/app/controllers/weapps/register_codes_controller.rb new file mode 100644 index 000000000..ff29101d2 --- /dev/null +++ b/app/controllers/weapps/register_codes_controller.rb @@ -0,0 +1,24 @@ +class Weapps::RegisterCodesController < Weapps::BaseController + before_action :require_wechat_login! + + def create + login = params[:login].to_s.strip + if login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ + user = User.find_by(mail: login) + return render_error('该邮箱已注册') if user.present? + elsif login =~ /^1\d{10}$/ + user = User.find_by(phone: params[:login]) + return render_error('该手机号已注册') if user.present? + else + return render_error('请输入正确的邮箱或手机号') + end + + code = %W(0 1 2 3 4 5 6 7 8 9) + verification_code = code.sample(6).join + send_type = login =~ /^1\d{10}$/ ? 1 : 8 + # 记录验证码 + check_verification_code(verification_code, send_type, login) + + render_ok + end +end \ No newline at end of file diff --git a/app/views/competitions/competition_teams/index.json.jbuilder b/app/views/competitions/competition_teams/index.json.jbuilder index 3e5dc4d16..f1f01b76a 100644 --- a/app/views/competitions/competition_teams/index.json.jbuilder +++ b/app/views/competitions/competition_teams/index.json.jbuilder @@ -1,4 +1,5 @@ json.count @all_count +json.members_count @all_member_count json.personal @personal json.competition_name @competition.name json.competition_teams do diff --git a/config/routes.rb b/config/routes.rb index 8bad9a889..d71f9a4fa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -852,6 +852,7 @@ Rails.application.routes.draw do resource :home, only: [:show] resource :session, only: [:create] resource :register, only: [:create] + resource :register_code, only: [:create] resource :code_session, only: [:create] resource :verify, only: [:create] resource :check_account, only: [:create] From e9e9ba9d69367842759bd4eafb309efda0d2c78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 25 Oct 2019 10:30:26 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Competitioncommon/CompetitionCommon.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js index 2fcdfb524..3991277fb 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js @@ -60,22 +60,23 @@ class CompetitionCommon extends Component{ }).catch((error) => { console.log(error) }) + //console.log(this.props) + if(this.props.user&&this.props.user.login!= ""){ + + const zul = `/competitions/${this.props.match.params.identifier}/competition_staff.json`; + axios.get((zul)).then((result) => { + if (result) { + if (result.data) { + this.setState({ + signupdata:result.data + }) + } + } + }).catch((error) => { + //console.log(error); + }) + } - // console.log("调用了GetenrollmentAPI"); - const zul = `/competitions/${this.props.match.params.identifier}/competition_staff.json`; - axios.get((zul)).then((result) => { - if (result) { - if (result.data) { - - this.setState({ - signupdata:result.data - }) - - } - } - }).catch((error) => { - //// //////console.log(error); - }) } getrightdatas=(e)=>{ @@ -258,7 +259,7 @@ class CompetitionCommon extends Component{ 已结束 : data.competition_status==="progressing"?:""} {data&&data.enroll_end_time===null?"":`报名截止时间:${data&&data.enroll_end_time}`} From 146001a0703a86dc8f581e1a89ebf065f2f2b822 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 25 Oct 2019 10:31:45 +0800 Subject: [PATCH 10/11] weapp: verification code api --- .../weapps/register_codes_controller.rb | 24 --------- .../weapps/verification_codes_controller.rb | 52 +++++++++++++++++++ config/routes.rb | 2 +- 3 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 app/controllers/weapps/register_codes_controller.rb create mode 100644 app/controllers/weapps/verification_codes_controller.rb diff --git a/app/controllers/weapps/register_codes_controller.rb b/app/controllers/weapps/register_codes_controller.rb deleted file mode 100644 index ff29101d2..000000000 --- a/app/controllers/weapps/register_codes_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -class Weapps::RegisterCodesController < Weapps::BaseController - before_action :require_wechat_login! - - def create - login = params[:login].to_s.strip - if login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ - user = User.find_by(mail: login) - return render_error('该邮箱已注册') if user.present? - elsif login =~ /^1\d{10}$/ - user = User.find_by(phone: params[:login]) - return render_error('该手机号已注册') if user.present? - else - return render_error('请输入正确的邮箱或手机号') - end - - code = %W(0 1 2 3 4 5 6 7 8 9) - verification_code = code.sample(6).join - send_type = login =~ /^1\d{10}$/ ? 1 : 8 - # 记录验证码 - check_verification_code(verification_code, send_type, login) - - render_ok - end -end \ No newline at end of file diff --git a/app/controllers/weapps/verification_codes_controller.rb b/app/controllers/weapps/verification_codes_controller.rb new file mode 100644 index 000000000..f23474b43 --- /dev/null +++ b/app/controllers/weapps/verification_codes_controller.rb @@ -0,0 +1,52 @@ +class Weapps::VerificationCodesController < Weapps::BaseController + before_action :require_wechat_login! + + def create + params[:type] == 'register' ? check_can_register : check_can_reset_password + end + + private + + def check_can_register + login = params[:login].to_s.strip + if login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ + user = User.find_by(mail: login) + return render_error('该邮箱已注册') if user.present? + elsif login =~ /^1\d{10}$/ + user = User.find_by(phone: params[:login]) + return render_error('该手机号已注册') if user.present? + else + return render_error('请输入正确的邮箱或手机号') + end + + code = %W(0 1 2 3 4 5 6 7 8 9) + verification_code = code.sample(6).join + send_type = login =~ /^1\d{10}$/ ? 1 : 8 + # 记录验证码 + check_verification_code(verification_code, send_type, login) + + render_ok + end + + def check_can_reset_password + login = params[:login].to_s.strip + if login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ + user = User.find_by(mail: login) + return render_error('该邮箱尚未注册') if user.blank? + elsif login =~ /^1\d{10}$/ + user = User.find_by(phone: login) + return render_error('该手机号尚未注册') if user.blank? + else + user = User.find_by(login: login) + return render_error('该账号尚未注册') if user.blank? + end + + code = %W(0 1 2 3 4 5 6 7 8 9) + verification_code = code.sample(6).join + send_type = login =~ /^1\d{10}$/ ? 2 : 3 + # 记录验证码 + check_verification_code(verification_code, send_type, login) + + render_ok + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d71f9a4fa..10bcb0f74 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -852,7 +852,7 @@ Rails.application.routes.draw do resource :home, only: [:show] resource :session, only: [:create] resource :register, only: [:create] - resource :register_code, only: [:create] + resource :verification_code, only: [:create] resource :code_session, only: [:create] resource :verify, only: [:create] resource :check_account, only: [:create] From ba393a97aa724314b9ea143355d8ad4409b5e019 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 25 Oct 2019 10:34:35 +0800 Subject: [PATCH 11/11] weapp: fix --- app/controllers/weapps/verification_codes_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/weapps/verification_codes_controller.rb b/app/controllers/weapps/verification_codes_controller.rb index f23474b43..7590c49f7 100644 --- a/app/controllers/weapps/verification_codes_controller.rb +++ b/app/controllers/weapps/verification_codes_controller.rb @@ -37,8 +37,7 @@ class Weapps::VerificationCodesController < Weapps::BaseController user = User.find_by(phone: login) return render_error('该手机号尚未注册') if user.blank? else - user = User.find_by(login: login) - return render_error('该账号尚未注册') if user.blank? + return render_error('请输入正确的邮箱或手机号') end code = %W(0 1 2 3 4 5 6 7 8 9)