Sha256: e5668626fecb50a028ebb34b34abb0b5191aa8aec71e09fe75a3c9fc19627dec
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
# coding: utf-8 class ApplicationController < ActionController::Base protect_from_forgery # httpsリダイレクト before_filter :ssl_redirect if Rails.env.production? # 未ログインリダイレクト before_filter :authorize # セッション有効期限延長 before_filter :reset_session_expires private #--------------# # ssl_redirect # #--------------# # httpsへリダイレクト(Production環境のみ) def ssl_redirect unless request.env["HTTP_X_FORWARDED_PROTO"].to_s == "https" request.env["HTTP_X_FORWARDED_PROTO"] = "https" redirect_to request.url and return end end #-----------# # authorize # #-----------# # ログイン認証 def authorize # セッション/トップコントローラ以外で if params[:controller] != "sessions" and params[:controller] != "top" # 未ログインであればルートヘリダイレクト if session[:user_id].blank? redirect_to :root and return end end end #-----------------------# # reset_session_expires # #-----------------------# # セッション期限延長 def reset_session_expires request.session_options[:expire_after] = 2.weeks end #--------------# # current_user # #--------------# def current_user @current_user ||= User.where( id: session[:user_id] ).first end helper_method :current_user end
Version data entries
5 entries across 5 versions & 1 rubygems