diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index f0dd6dd75..c6265c274 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -11,6 +11,10 @@ class SchoolsController < ApplicationController end def for_option - render_ok(schools: School.select(:id, :name).as_json) + schools = School.all + keyword = params[:keyword].to_s.strip + schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword + + render_ok(schools: schools.select(:id, :name).as_json) end end diff --git a/app/controllers/weapps/check_accounts_controller.rb b/app/controllers/weapps/check_accounts_controller.rb new file mode 100644 index 000000000..429c165b3 --- /dev/null +++ b/app/controllers/weapps/check_accounts_controller.rb @@ -0,0 +1,38 @@ +class Weapps::CheckAccountsController < Weapps::BaseController + def create + params[:type] == 'register' ? check_can_register : check_can_bind + end + + private + + def check_can_bind + if params[: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: params[:login]) + return render_error('该邮箱尚未注册') if user.blank? + elsif params[:login] =~ /^1\d{10}$/ + user = User.find_by(phone: params[:login]) + return render_error('该手机号尚未注册') if user.blank? + else + user = User.find_by(login: params[:login]) + return render_error('该账号尚未注册') if user.blank? + end + + return render_error('该账号已经绑定') if user.wechat_open_user.present? + + render_ok + end + + def check_can_register + if params[: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: params[:login]) + return render_error('该邮箱已注册') if user.present? + elsif params[:login] =~ /^1\d{10}$/ + user = User.find_by(phone: params[:login]) + return render_error('该手机号已注册') if user.present? + else + return render_error('请输入正确的邮箱或手机号') + end + + render_ok + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2a731a595..49e8215ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -854,6 +854,7 @@ Rails.application.routes.draw do resource :register, only: [:create] resource :code_session, only: [:create] resource :verify, only: [:create] + resource :check_account, only: [:create] resources :searchs, only: [:index] end