diff --git a/app/controllers/concerns/render_helper.rb b/app/controllers/concerns/render_helper.rb index 94ac351cd..5ea73e666 100644 --- a/app/controllers/concerns/render_helper.rb +++ b/app/controllers/concerns/render_helper.rb @@ -16,4 +16,8 @@ module RenderHelper render json: { status: 403, message: message } # render status: 403, json: { errors: errors } end + + def render_unauthorized(message = I18n.t('error.unauthorized')) + render json: { status: 401, message: message } + end end \ No newline at end of file diff --git a/app/controllers/trial_applies_controller.rb b/app/controllers/trial_applies_controller.rb index f8454e557..acfde75da 100644 --- a/app/controllers/trial_applies_controller.rb +++ b/app/controllers/trial_applies_controller.rb @@ -1,4 +1,5 @@ class TrialAppliesController < ApplicationController + before_action :require_user_login def create Users::ApplyTrailService.call(current_user, create_params) @@ -12,4 +13,10 @@ class TrialAppliesController < ApplicationController def create_params params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip) end + + def require_user_login + return if User.current.logged? + + render_unauthorized + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index bb1bb3934..257c83750 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,5 @@ en: error: record_not_found: Record not found - forbidden: Forbidden \ No newline at end of file + forbidden: Forbidden + unauthorized: Unauthorized \ No newline at end of file diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 99d5ac843..71cdb02e9 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -1,4 +1,5 @@ 'zh-CN': error: record_not_found: 您访问的页面不存在或已被删除 - forbidden: 您没有权限进行该操作 \ No newline at end of file + forbidden: 您没有权限进行该操作 + unauthorized: 未登录 \ No newline at end of file