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