From eab4740743ba2df098a00a8f840458382137814c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 24 Jun 2019 09:38:38 +0800 Subject: [PATCH] trial apply api require logged --- app/controllers/concerns/render_helper.rb | 4 ++++ app/controllers/trial_applies_controller.rb | 7 +++++++ config/locales/en.yml | 3 ++- config/locales/zh-CN.yml | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) 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