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