<commit_before>class SerialsController < ApplicationController
  skip_before_action :logged_in_admin, only: [:scan, :build_serial]

  def scan
    user = User.find_by(cell: params["cell"])
    serial = Serial.find_by(serial_no: params["serial_no"])

    if user && serial
      serial.update_attribute(:phone, params["cell"], :open_id, user.open_id, :user_id, user.id)
      user.update_attribute(:score, (user.score + 20 if user.score) || 20)
      render json: {:return => "1", :desc => "绑定成功"}, status: 200
    else
      render json: {:return => "0", :desc => "绑定失败"}, status: 422
    end
  end

  def build_serial
    serial = Serial.create(serial_no: params["serial_no"], phone: params["cell"])
    if serial
      render json: {:return => "1", :desc => "绑定成功", :cell => serial.phone, :datetime => created_at}, status: 200
    else
      render json: {:return => "0", :desc => "未绑定"}, status: 422
    end
  end

  def scan_old
    user = User.find_by(openid: params["openid"])
    serial = Serial.find_by(serial_no: params["serial_no"])
    # if serial
    #   if serial.open_id == params["openid"].to_s<commit_msg>update api<commit_after>class SerialsController < ApplicationController
  skip_before_action :logged_in_admin, only: [:scan, :build_serial]

  def scan
    user = User.find_by(cell: params["cell"])
    serial = Serial.find_by(serial_no: params["serial_no"])

    if user && serial
      serial.update_attribute(:phone, params["cell"], :open_id, user.open_id, :user_id, user.id)
      user.update_attribute(:score, (user.score + 20 if user.score) || 20)
      render json: {:return => "1", :desc => "绑定成功"}, status: 200
    else
      render json: {:return => "0", :desc => "绑定失败"}, status: 422
    end
  end

  def build_serial
    serial = Serial.find_by(serial_no: params["serial_no"])
    if serial.nil?
      serial = Serial.create(serial_no: params["serial_no"], phone: params["cell"])
    end
    if serial
      render json: {:return => "1", :desc => "绑定成功", :cell => serial.phone, :datetime => serial.created_at}, status: 200
    else
      render json: {:return => "0", :desc => "未绑定"}, status: 422
    end
  end

  def scan_old
    user = User.find_by(openid: params["openid"])
    serial = Serial.find_by(serial_no: params["serial_no"])
    # if serial
    #   if serial.open_id == params["openid"].to_s
{'fraction_non_alphanumeric': 0.15674518201284796, 'fraction_numerical': 0.017130620985010708, 'mean_word_length': 3.6907630522088355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3502709', 'n_tokens_mistral': 822, 'n_tokens_neox': 791, 'n_words': 196}