From 0a5dd2f1ee0278f9a219d838d76501a1234c3e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 21 Oct 2022 09:42:21 +0800 Subject: [PATCH] =?UTF-8?q?ssh=E5=85=AC=E9=92=A5=E5=85=81=E8=AE=B8token?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/public_keys_controller.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 22895b114..7619a39e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -173,6 +173,14 @@ class ApplicationController < ActionController::Base tip_exception(401, "请登录后再操作") unless User.current.logged? end + def require_login_or_token + if params[:token].present? + user = User.try_to_autologin(params[:token]) + User.current = user + end + tip_exception(401, "请登录后再操作") unless User.current.logged? + end + def require_profile_completed tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed? end diff --git a/app/controllers/public_keys_controller.rb b/app/controllers/public_keys_controller.rb index 327e719cc..0e18e3e09 100644 --- a/app/controllers/public_keys_controller.rb +++ b/app/controllers/public_keys_controller.rb @@ -1,5 +1,5 @@ class PublicKeysController < ApplicationController - before_action :require_login + before_action :require_login_or_token before_action :find_public_key, only: [:destroy] def index