2012-06-23 06:19:03 +08:00
|
|
|
class ApplicationController < ActionController::Base
|
2016-08-12 14:57:18 +08:00
|
|
|
protect_from_forgery with: :exception
|
2014-03-31 12:18:40 +08:00
|
|
|
|
|
|
|
helper_method :format_time, :format_date
|
|
|
|
|
2014-04-01 08:28:21 +08:00
|
|
|
helper_method :admin_username
|
|
|
|
|
2014-03-31 12:18:40 +08:00
|
|
|
def format_time(time)
|
|
|
|
time.strftime("%Y-%m-%d %H:%M")
|
|
|
|
end
|
|
|
|
|
|
|
|
def format_date(time)
|
2014-03-31 14:10:54 +08:00
|
|
|
time.strftime("%Y.%m.%d")
|
2014-03-31 12:18:40 +08:00
|
|
|
end
|
2014-03-31 16:06:15 +08:00
|
|
|
|
|
|
|
protected
|
|
|
|
def authericate_user!
|
2014-04-01 08:28:21 +08:00
|
|
|
if ! session[:login]
|
2014-04-01 19:43:26 +08:00
|
|
|
flash[:error] = '请先登录后台管理'
|
2014-04-03 11:13:51 +08:00
|
|
|
cookies[:urlback] = request.original_url
|
2014-04-01 08:28:21 +08:00
|
|
|
redirect_to new_admin_session_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def admin_username
|
|
|
|
session[:login] && ENV['ADMIN_USER']
|
2014-03-31 16:06:15 +08:00
|
|
|
end
|
2012-06-23 06:19:03 +08:00
|
|
|
end
|