On Thu, Jul 8, 2010 at 11:43 AM, Pete <[email protected]> wrote:
> I am wondering how to manipulate hobo's login procedure -
>
> I have set a before filter, and created a method in my
> ApplicationController, which will limit users depending on IP address/
> location.
>
> This works, as if the location is not acceptable I just redirect back
> to the logout action.
>
> But ideally, rather than logging the user out - I would like to just
> prevent logging in (once the application has recognised the users
> login credentials) and then show my flash message - it seems if I
> redirect to logout, the default logout message is shown, rather than
> my flash error message.
>
> This is my method:
>
> def check_location
>
>
> @ipAddress = request.remote_ip.to_s
>
> if current_user.administrator? && @ipAddress != "196.255.255.255"
> flash[:error] = "You cannot have access from your current location."
> redirect_to :controller => "users", :action => "logout"
>
> end
>
> end
>
> If this is not possible, It would be perfectly fine, just to be able
> to override the logout flash message with my own - just to present the
> user with more information. But i am unsure of how to do this - the
> logout message seems to take priority?

The simplest way to do this is probably in the login action itself.
Here's a sample (in UsersController or equivalent):

def login
  hobo_login do
    if current_user.administrator? && @ipAddress != "196.255.255.255"
      flash[:error] = "You cannot have access from your current location."
      self.current_user = nil
      redirect_to root_url
    end
  end
end

Basically, you can override what gets rendered from inside the block
passed to hobo_login; current_user will already be set, so if you need
to log the user out just set it to nil.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to