From b209ee12507ddf04f65f469694c05360896b1741 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 Oct 2025 15:57:12 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=94=A8=E6=88=B7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=98=BE=E7=A4=BAtoken=E5=92=8C=E6=90=BA=E5=B8=A6token?= =?UTF-8?q?=E8=AF=B7=E6=B1=82api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/user_tokens_controller.rb | 10 ++++++++++ config/routes/api.rb | 1 + .../20251031043136_add_user_index_gitea_token.rb | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 app/controllers/api/v1/user_tokens_controller.rb create mode 100644 db/migrate/20251031043136_add_user_index_gitea_token.rb diff --git a/app/controllers/api/v1/user_tokens_controller.rb b/app/controllers/api/v1/user_tokens_controller.rb new file mode 100644 index 000000000..84c110a28 --- /dev/null +++ b/app/controllers/api/v1/user_tokens_controller.rb @@ -0,0 +1,10 @@ +class Api::V1::UserTokensController < Api::V1::BaseController + include AesCryptHelper + before_action :require_login + + def show + password = decrypt(params[:password]) rescue params[:password].to_s + tip_exception("密码不正确") unless current_user.check_password?(password) + render_ok({access_token: current_user.gitea_token}) + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 8d113fd68..aa059c1ac 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -76,6 +76,7 @@ defaults format: :json do collection do post :check_user_id post :check_user_login + get 'access_token', to: 'user_tokens#show' end end diff --git a/db/migrate/20251031043136_add_user_index_gitea_token.rb b/db/migrate/20251031043136_add_user_index_gitea_token.rb new file mode 100644 index 000000000..23adf5209 --- /dev/null +++ b/db/migrate/20251031043136_add_user_index_gitea_token.rb @@ -0,0 +1,5 @@ +class AddUserIndexGiteaToken < ActiveRecord::Migration[5.2] + def change + add_index :users, :gitea_token + end +end \ No newline at end of file