class Oauth::QQController < Oauth::BaseController
  def create
    Rails.logger.info "---------收到qq登录回调-------------"
    Rails.logger.info "---------auth_hash: #{auth_hash['uid']}"
    new_user = false
    # 存在该用户
    open_user = OpenUsers::QQ.find_by(uid: auth_hash['uid'])

    if open_user.present? && open_user.user.present?
      successful_authentication(open_user.user)
    else
      if current_user.blank? || !current_user.logged?
        new_user = true
        set_session_unionid(auth_hash['uid'])
      else
        OpenUsers::QQ.create!(user: current_user, uid: auth_hash['uid'])
      end
    end

    render_ok(new_user: new_user)
  end
end
# class Oauth::QQController < Oauth::BaseController
#   def create
#     user, new_user = Oauth::CreateOrFindQqAccountService.call(current_user, auth_hash)
#
#     successful_authentication(user)
#
#     render_ok(new_user: new_user)
#   end
# end
