@ -642,6 +642,14 @@ class User < ApplicationRecord
login
end
def bind_open_user?(type)
case type
when 'wechat' then wechat_open_user.present?
when 'qq' then qq_open_user.present?
else false
protected
def validate_password_length
# 管理员的初始密码是5位
@ -17,6 +17,7 @@ class CreateBindUserService < ApplicationService
bind_user = User.try_to_login(params[:username], params[:password])
raise Error, '用户名或者密码错误' if bind_user.blank?
raise Error, '该账号已被绑定' if bind_user.bind_open_user?(params[:type].to_s)
ActiveRecord::Base.transaction do
open_user.user_id = bind_user.id