2
votes

We'd like to have 3 different signin forms for our app:

  • the default signin form, takes them to their normal dashboard (as we do now)

  • a "foo" signin form that, if they use THAT form to sign in, takes them to a special purpose screen

  • a "bar" signin form that takes them to yet anogther special-purpose screen

I assume the right approach is to somehow

a) create a new route for /foo and /bar, probably directing both to the SAME signin method but in the route add a url parameter 'signin_type' telling us which "type" of signin form it is?

b) implement a custom RegistrationsController method(s) (what name?) to handle the signin form (we already have a custom new and create method for when they register, since our registration form needed a 'referral code' field added), and have the method look at the url parameter 'signin_type' to redirect the sign to either the normal, or foo, or bad

c) implement another method that handles the signin submit (is that a different method?) that looks at some special embedded form value to figur eout which signing form was used?

That's my best guess. If correct, it's how to do (b) and (c) that has me stumped. Any thoughts will be appreciated!

1

1 Answers

2
votes

I think you may be trying to over engineer this. I would approach this with a single sign_in page, and just use conditional logic in overriding the after_sign_in_path_for(resource) method for the Devise controller. Not only will this be much easier to implement now, it will be a lot easier to maintain in the future. Simply add to your ApplicationController.rb:

protected

  def stored_location_for(resource)
    nil
  end

  def after_sign_in_path_for(resource)
    if condition_foo
      redirect_to foo_url
    elsif condition bar
      redirect_to bar_url
    else
      redirect_to dashboard_url
    end
  end

The first method overrides Devise's default location of root and sets it to nil, then the logic after that is pretty self explanatory. This should work for what you are wanting.