trial apply api require logged

dev_course
p31729568 6 years ago
parent b4557b17ac
commit eab4740743

@ -16,4 +16,8 @@ module RenderHelper
render json: { status: 403, message: message } render json: { status: 403, message: message }
# render status: 403, json: { errors: errors } # render status: 403, json: { errors: errors }
end end
def render_unauthorized(message = I18n.t('error.unauthorized'))
render json: { status: 401, message: message }
end
end end

@ -1,4 +1,5 @@
class TrialAppliesController < ApplicationController class TrialAppliesController < ApplicationController
before_action :require_user_login
def create def create
Users::ApplyTrailService.call(current_user, create_params) Users::ApplyTrailService.call(current_user, create_params)
@ -12,4 +13,10 @@ class TrialAppliesController < ApplicationController
def create_params def create_params
params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip) params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip)
end end
def require_user_login
return if User.current.logged?
render_unauthorized
end
end end

@ -1,4 +1,5 @@
en: en:
error: error:
record_not_found: Record not found record_not_found: Record not found
forbidden: Forbidden forbidden: Forbidden
unauthorized: Unauthorized

@ -1,4 +1,5 @@
'zh-CN': 'zh-CN':
error: error:
record_not_found: 您访问的页面不存在或已被删除 record_not_found: 您访问的页面不存在或已被删除
forbidden: 您没有权限进行该操作 forbidden: 您没有权限进行该操作
unauthorized: 未登录
Loading…
Cancel
Save