weapp: add login check api

dev_sync_trustie
p31729568 5 years ago
parent a49a5dce08
commit 8a37633344

@ -11,6 +11,10 @@ class SchoolsController < ApplicationController
end end
def for_option 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
end end

@ -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

@ -854,6 +854,7 @@ Rails.application.routes.draw do
resource :register, only: [:create] resource :register, only: [:create]
resource :code_session, only: [:create] resource :code_session, only: [:create]
resource :verify, only: [:create] resource :verify, only: [:create]
resource :check_account, only: [:create]
resources :searchs, only: [:index] resources :searchs, only: [:index]
end end

Loading…
Cancel
Save