Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Authlogic authentication method
    primarykey
    data
    text
    <p>Within Authlogic, is there a way that I can add conditions to the authentication method? I know by using the <strong>find_by_login_method</strong> I can specify another method to use, but when I use this I need to pass another parameter since the <strong>find_by_login_method</strong> method only passes the parameter that is deemed the 'login_field'. </p> <p>What I need to do is check something that is an association of the authentic model.. Here is the method I want to use</p> <pre><code> # make sure that the user has access to the subdomain that they are # attempting to login to, subdomains are company names def self.find_by_email_and_company(email, company) user = User.find_by_email(email) companies = [] user.brands.each do |b| companies &lt;&lt; b.company.id end user &amp;&amp; companies.include?(company) end </code></pre> <p>But this fails due to the fact that only one parameter is sent to the find_by_email_and_company method.</p> <p>The company is actually the subdomain, so in order to get it here I am just placing it in a hidden field in the form (only way I could think to get it to the model)</p> <p>Is there a method I can override somehow..?</p> <p>Using the answer below I came up with the following that worked:</p> <blockquote> <p><strong>User Model (User.rb)</strong></p> </blockquote> <pre><code> def self.find_by_email_within_company(email) # find the user user = self.find_by_email(email) # no need to continue if the email address is invalid return false if user.nil? # collect the subdomains the provided user has access to company_subdomains = user.brands.map(&amp;:company).map(&amp;:subdomain) # verify that the user has access to the current subdomain company_subdomains.include?(Thread.current[:current_subdomain]) &amp;&amp; user end </code></pre> <blockquote> <p><strong>Application Controller</strong></p> </blockquote> <pre><code> before_filter :set_subdomain private def set_subdomain # helper that retreives the current subdomain get_company Thread.current[:current_subdomain] = @company.subdomain end </code></pre> <blockquote> <p><strong>User Session Model (UserSession.rb)</strong></p> </blockquote> <pre><code>find_by_login_method :find_by_email_within_company </code></pre> <p>I have read a few things about using Thread.current, and conflicting namespaces.. This is a great solution that worked for me but would love to hear any other suggestions before the bounty expires, otherwise, +100 to Jens Fahnenbruck :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload