2012-09-23 02:39:12 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2016-02-13 09:28:09 +00:00
|
|
|
include Pundit
|
2012-09-23 02:39:12 +00:00
|
|
|
protect_from_forgery
|
2015-11-03 14:22:53 +00:00
|
|
|
|
|
|
|
before_filter :get_invite_link
|
2016-02-19 01:23:39 +00:00
|
|
|
after_action :allow_embedding
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2014-01-29 03:46:58 +00:00
|
|
|
# this is for global login
|
|
|
|
include ContentHelper
|
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
helper_method :user
|
|
|
|
helper_method :authenticated?
|
2014-05-17 18:57:03 +00:00
|
|
|
helper_method :admin?
|
2012-09-23 02:39:12 +00:00
|
|
|
|
2014-10-07 21:46:09 +00:00
|
|
|
def after_sign_in_path_for(resource)
|
2015-12-20 10:36:57 +00:00
|
|
|
unsafe_uri = request.env["REQUEST_URI"]
|
2015-12-21 13:38:02 +00:00
|
|
|
if unsafe_uri.starts_with?('http') && !unsafe_uri.starts_with?('https')
|
2015-12-20 10:36:57 +00:00
|
|
|
protocol = 'http'
|
|
|
|
else
|
|
|
|
protocol = 'https'
|
|
|
|
end
|
|
|
|
sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => protocol)
|
2014-10-07 22:38:33 +00:00
|
|
|
|
2014-10-07 21:46:09 +00:00
|
|
|
if request.referer == sign_in_url
|
|
|
|
super
|
2014-10-07 22:38:33 +00:00
|
|
|
elsif params[:uv_login] == "1"
|
2014-10-07 22:49:14 +00:00
|
|
|
"http://support.metamaps.cc/login_success?sso=" + current_sso_token
|
2014-10-07 21:46:09 +00:00
|
|
|
else
|
|
|
|
stored_location_for(resource) || request.referer || root_path
|
2014-01-29 03:46:58 +00:00
|
|
|
end
|
|
|
|
end
|
2014-02-26 19:53:20 +00:00
|
|
|
|
2012-09-23 02:39:12 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def require_no_user
|
|
|
|
if authenticated?
|
2014-10-22 00:31:59 +00:00
|
|
|
redirect_to edit_user_path(user), notice: "You must be logged out."
|
2012-09-23 02:39:12 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_user
|
|
|
|
unless authenticated?
|
2014-10-22 00:31:59 +00:00
|
|
|
redirect_to new_user_session_path, notice: "You must be logged in."
|
2012-09-23 02:39:12 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2014-05-17 18:57:03 +00:00
|
|
|
|
|
|
|
def require_admin
|
2015-09-19 08:48:24 +00:00
|
|
|
unless authenticated? && admin?
|
2014-05-17 18:57:03 +00:00
|
|
|
redirect_to root_url, notice: "You need to be an admin for that."
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
|
|
|
|
def user
|
|
|
|
current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticated?
|
|
|
|
current_user
|
|
|
|
end
|
2014-05-17 18:57:03 +00:00
|
|
|
|
|
|
|
def admin?
|
2015-12-16 13:32:50 +00:00
|
|
|
authenticated? && current_user.admin
|
2014-05-17 18:57:03 +00:00
|
|
|
end
|
2015-11-03 14:22:53 +00:00
|
|
|
|
|
|
|
def get_invite_link
|
2016-02-19 10:09:46 +00:00
|
|
|
@invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : "")
|
2015-11-03 14:22:53 +00:00
|
|
|
end
|
2016-02-19 01:23:39 +00:00
|
|
|
|
|
|
|
def allow_embedding
|
|
|
|
#allow all
|
|
|
|
response.headers.except! 'X-Frame-Options'
|
|
|
|
# or allow a whitelist
|
|
|
|
# response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc'
|
|
|
|
end
|
2012-09-23 02:39:12 +00:00
|
|
|
end
|