Sha256: 0e2e1119e93ed102b18fea49370f17ebb5072c499ff488820809d168fc26a3e8

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module Mtdevise

# class ApplicationController < ActionController::Base
	class ApplicationController < ::ApplicationController

		# Secirity and Filters
		protect_from_forgery with: :null_session
		before_action :check_subdomain

		# Omniauth
		def after_sign_in_path_for(resource)
			request.env['omniauth.origin'] || stored_location_for(resource) || mtdevise.accounts_path
		end

		# Helpers for Current Account and Users
		def current_user?(user)
			user == current_user
		end
		helper_method :current_user
		def current_account?(account)
			account == current_account
		end
		helper_method :current_account 

		# Devise Custom Layouts
		config.to_prepare do
			Devise::SessionsController.layout "mtdevise/accounts"
			Devise::RegistrationsController.layout proc{ |controller| user_signed_in? ? "application" : "mtdevise/accountsedit" }
			Devise::ConfirmationsController.layout "mtdevise/accounts"
			Devise::UnlocksController.layout "mtdevise/accounts"
			Devise::PasswordsController.layout "mtdevise/accounts"
		end

		private

		# Logged in redirect
		def redirect_logged_in_users_to_account_page
			redirect_to mtdevise.accounts_path if user_signed_in?
		end

		# Subdomain Checker
		def check_subdomain
			if request.subdomain.present? && Account.where(subdomain: request.subdomain).blank?
				redirect_to mtdevise.root_url(subdomain: false), notice: "Subdomain Doesn't Exist. Would you like to Register."
			end
		end

		# Resolve Layouts
		def layouts_rsolver
			case action_name
				when "index"
					"mtdevise/accountsindex"
				else
					"mtdevise/accounts"
			end
		end

	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mtdevise-1.7.8 app/controllers/mtdevise/application_controller.rb
mtdevise-1.7.5 app/controllers/mtdevise/application_controller.rb