From 892aa31ea9c4226a6cf878ca1be7f52d07eb0dbe Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 25 Sep 2023 11:29:44 +0800 Subject: [PATCH 1/4] check keywords --- app/controllers/accounts_controller.rb | 6 ++++++ config/routes.rb | 1 + 2 files changed, 7 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 320ca05e2..b6ac9987d 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -359,6 +359,12 @@ class AccountsController < ApplicationController Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate! render_ok end + + def check_keywords + text = params[:text]&.gsub(/\s+/, "") + tip_exception("无法使用以下关键词:#{text},请重新命名") if ReversedKeyword.check_exists?(text) + render_ok + end private diff --git a/config/routes.rb b/config/routes.rb index 7b6c4d8bc..cc10bd987 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -261,6 +261,7 @@ Rails.application.routes.draw do post :remote_password post :change_password post :check + post :check_keywords post :login_check post :simple_update end From 8d7c114b40b43b177db5dd59b0be0f8e91bfcdf8 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 25 Sep 2023 11:40:11 +0800 Subject: [PATCH 2/4] update check keywords --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index b6ac9987d..be91d8527 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -361,7 +361,7 @@ class AccountsController < ApplicationController end def check_keywords - text = params[:text]&.gsub(/\s+/, "") + text = params[:text].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') tip_exception("无法使用以下关键词:#{text},请重新命名") if ReversedKeyword.check_exists?(text) render_ok end From 6bd1eef14af6e6677972d10d92b23d4f1a9ab57f Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 25 Sep 2023 12:49:14 +0800 Subject: [PATCH 3/4] update check keyword response --- app/controllers/accounts_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index be91d8527..63918232a 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -362,8 +362,13 @@ class AccountsController < ApplicationController def check_keywords text = params[:text].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') - tip_exception("无法使用以下关键词:#{text},请重新命名") if ReversedKeyword.check_exists?(text) - render_ok + data = ReversedKeyword.check_exists?(text) + result = { + status: 0, + data: data, + message: data ? "" : "无法使用以下关键词:#{text},请重新命名" + } + render_ok(result) end private From 7664e2e4d31fbbcc01ebc3a09f007164a41fa4c3 Mon Sep 17 00:00:00 2001 From: chenjing <28122123@qq.com> Date: Mon, 25 Sep 2023 13:01:13 +0800 Subject: [PATCH 4/4] update response for checkkeyword --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 63918232a..ea26f1bd5 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -362,7 +362,7 @@ class AccountsController < ApplicationController def check_keywords text = params[:text].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') - data = ReversedKeyword.check_exists?(text) + data = ! ReversedKeyword.check_exists?(text) result = { status: 0, data: data,