From c24d9bc943551d523aff204403aac343075d21ab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 14 Feb 2020 20:03:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=A7=A3?= =?UTF-8?q?=E9=99=A4=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weapps/unbind_accounts_controller.rb | 15 +++++++++++++++ .../weapps/unbind_accounts/show.json.jbuilder | 1 + config/routes.rb | 1 + 3 files changed, 17 insertions(+) create mode 100644 app/controllers/weapps/unbind_accounts_controller.rb create mode 100644 app/views/weapps/unbind_accounts/show.json.jbuilder diff --git a/app/controllers/weapps/unbind_accounts_controller.rb b/app/controllers/weapps/unbind_accounts_controller.rb new file mode 100644 index 000000000..551308a6c --- /dev/null +++ b/app/controllers/weapps/unbind_accounts_controller.rb @@ -0,0 +1,15 @@ +class Weapps::UnbindAccountsController < Weapps::BaseController + before_action :require_login + + def show + @user = current_user + end + + def destroy + open_user = OpenUsers::Wechat.find_by!(user_id: current_user.id) + open_user.destroy! + UserAction.create(action_id: current_user.id, action_type: "UnbindWechat", user_id: current_user.id, :ip => request.remote_ip) + logout_user + render_ok + end +end \ No newline at end of file diff --git a/app/views/weapps/unbind_accounts/show.json.jbuilder b/app/views/weapps/unbind_accounts/show.json.jbuilder new file mode 100644 index 000000000..057823247 --- /dev/null +++ b/app/views/weapps/unbind_accounts/show.json.jbuilder @@ -0,0 +1 @@ +json.user_account @user.phone.present? ? @user.phone : @user.mail diff --git a/config/routes.rb b/config/routes.rb index 971c1859f..9f1ff0f1a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1019,6 +1019,7 @@ Rails.application.routes.draw do resource :code_session, only: [:create] resource :verify, only: [:create] resource :check_account, only: [:create] + resource :unbind_accounts, only: [:show, :destroy] resources :searchs, only: [:index] resources :course_stickies, only: [:create] do From 8dfbe577ad5fbdfd6ad26b8af1681a9bef0ab873 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 14 Feb 2020 20:07:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=A7=A3?= =?UTF-8?q?=E9=99=A4=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/unbind_accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/weapps/unbind_accounts_controller.rb b/app/controllers/weapps/unbind_accounts_controller.rb index 551308a6c..4698108e3 100644 --- a/app/controllers/weapps/unbind_accounts_controller.rb +++ b/app/controllers/weapps/unbind_accounts_controller.rb @@ -7,7 +7,7 @@ class Weapps::UnbindAccountsController < Weapps::BaseController def destroy open_user = OpenUsers::Wechat.find_by!(user_id: current_user.id) - open_user.destroy! + open_user.update!(user_id: nil) UserAction.create(action_id: current_user.id, action_type: "UnbindWechat", user_id: current_user.id, :ip => request.remote_ip) logout_user render_ok