<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;The first thing to do is add the required methods in lib/authenticated_system.rb. This goes by the account_location default of using an Account model with a #username field for the subdomain name.&lt;/p&gt;
1. module AuthenticatedSystem
2. protected
3. # Example of integration with account_location plugin:
4. def account?
5. @account ||= Account.find_by_username(account_subdomain)
6. end
7.
8. # use this method in a before_filter like #login_required
9. def account_required
10. return true if account?
11. redirect_to(:controller =&amp;gt; &amp;#8216;/account&amp;#8217;, :action =&amp;gt; &amp;#8216;index&amp;#8217;) and return false
12. end
13. end
&lt;p&gt;html | txt&lt;/p&gt;
&lt;p&gt;Now, when logging in we need to record what domain the user has been authenticated on. You can do this by modifying the #current_user methods:&lt;/p&gt;
1. # still in AuthenticatedSystem&amp;#8230;
2. def logged_in?
3. # Only count the user as logged in if the subdomain matches
4. session[account_subdomain] == :authenticated &amp;amp;&amp;amp; current_user
5. end
6.
7. # Filter the available users to the current account.
8. # This assumes that Account has_many :users
9. def current_user
10. @current_user ||= session[:user] ? @account.users.find_by_id(session[:user]) : nil
11. end
12.
13. # Store the user id in the session, as well as the current sub domain.
14. def current_user=(new_user)
15. # Example of integration with account_location plugin:
16. session[account_subdomain] = new_user.nil? ? nil : :authenticated
17. session[:user] = new_user.nil? ? nil : new_user.id
18. @current_user = new_user
19. end
&lt;p&gt;html | txt&lt;/p&gt;
&lt;p&gt;Be sure to add #account? to the to the list of helper methods:&lt;/p&gt;
1. # The bottom of AuthenticatedSystem&amp;#8230;
2. def self.included(base)
3. base.send :helper_method, :current_user, :logged_in?, :account?
4. end</body>
  <created-at type="datetime">2008-10-24T03:38:10-07:00</created-at>
  <id type="integer">71688</id>
  <permalink>integrating-the-account_location-plugin-with-acts_as_authenticated</permalink>
  <repository-id type="integer">67186</repository-id>
  <title>Integrating the account_location plugin with acts_as_authenticated</title>
  <updated-at type="datetime">2008-10-24T03:38:10-07:00</updated-at>
  <user-id type="integer">30799</user-id>
</wiki>
