devise invitable for an api

772 views
Skip to first unread message

Brian Rossetti

unread,
Mar 23, 2015, 7:56:36 PM3/23/15
to plataforma...@googlegroups.com
Hey everyone, 

I am trying to implement an admin invitation system for an api that interacts with a front end site on another domain. I would like the accept invitation link to redirect to the front end at www.example.com, but I cant seem to figure out how to get devise invitable to change the link for the accept_invitation_url(@resource). My partner, managing the front end, would like to have the user redirected to his sign in page with the url and the temporary token passed in the url. Anytime I try to configure the action mailer config for host, i am getting errors. Is it even possible to point the accept_invitation_url at a completely separate domain that is making api calls to your server? If so, how might i go about this process?

I have read and about overriding the invitation controller, but noting I have found or tried has come up with a solution for this scenario. I can send the email, but the accept link always ends in a routing error.

any assitance would be greatly appreciated, let me know if i need to clarify anything to give you a better pictures, thanks again

Jason Fleetwood-Boldt

unread,
Mar 24, 2015, 11:01:28 AM3/24/15
to plataforma...@googlegroups.com
What errors?

Please paste code examples and the errors you are seeing.

Specifically, can you read and following the instructions here:


and let us know exactly what is not working when you follow those instructions. 




On Mar 23, 2015, at 7:56 PM, Brian Rossetti <bross...@gmail.com> wrote:

Anytime I try to configure the action mailer config for host, i am getting errors

Message has been deleted
Message has been deleted

Brian Rossetti

unread,
Mar 24, 2015, 1:54:34 PM3/24/15
to plataforma...@googlegroups.com
thanks for the reply, here is the code I have so far.

class InvitationsController < Devise::InvitationsController
  
  def create
    @from    = "no-r...@mywebsite.com"
    @subject = "you've been invited to #{www.mywebsite.com} by #{params[:company]}"
    @content = "test"

    @user = User.invite!(email: params[:user]) do |u|
      u.skip_invitation = true
    end

    NotificationMailer.invite_message(@user, @from, @subject, @content).deliver
    @user.invitation_sent_at = Time.now.utc # mark invitation as delivered

    if @user.errors.empty?
      flash[:notice] = "successfully sent invite to #{@user.email}"
      render json: @user #, :location => root_path
    else
      render :new
    end
  end


  def after_accept_path_for
  end
end



class NotificationMailer < ActionMailer::Base
  def invite_message(user, from, subject, content)
    @user = user
    @token = user.raw_invitation_token
    invitation_link = accept_user_invitation_url(:invitation_token => @token)

    mail(:from => from, :bcc => from, :to => @user.email, :subject => subject, template_path: 'mailers/notification_mailer') do |format|
      content = content.gsub('{{invitation_link}}', invitation_link)
      format.text do
        render :text => content
      end
    end
  end
end


invitaiton_instructions.html.erb:

<p><%= I18n.t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p>

<p><%= I18n.t("devise.mailer.invitation_instructions.someone_invited_you", url: "www.mypartnerswebsite.com" %></p>

<p><%= link_to I18n.t("devise.mailer.invitation_instructions.accept"), accept_invitation_url("www.mypartnerswebsite.com", :invitation_token => @token) %></p>

<p><%= I18n.t("devise.mailer.invitation_instructions.ignore").html_safe %></p>


I have filled in certain parts of the code with the issue at hand by labeling them "mywebsite.com" and "mypartnerswebsite.com". I have json only api endpoints set up that my partner hits form another domain address. The email's are set up on my end, and right now we are trying to configure admins to invite users through devise invitable. The problem is that whenever I try to override the accept_invitation_url and change it to "www.mypartnerswebsite.com", i cant seem to get it to work. I am trying to get the redirect on accepting the invite to look like this: 



after submitting an email address to my invitation controller, it attempts to reroute to GET "/users/sign_in" through my routes, so no real error response at this point, but I dont know how to get from here to redirecting to http://mypartnerswebsite.com/users/sign_in/. any ideas if this is possible and how to do it?

I have tried changing the host url in regards to the actionmailer views guide, but have been unable to get the correct response in order to redirect to www.mypartnerswebsite.com. thanks again for the response.

The idea was to have it redirect to his domain with the invitation token as the query params then he could send that and the user password to me to confirm the invitation, set up the password, and then I could send him back the authentication token.
Message has been deleted

Brian Rossetti

unread,
Mar 24, 2015, 4:14:28 PM3/24/15
to plataforma...@googlegroups.com

so i have made progress, looks like it was a simple fix, and my mistake for mistepping defining urls. in the invitation view, I just had to change:

<p><%= link_to I18n.t("devise.mailer.invitation_instructions.accept"), "www.mypartnerswebsite.com/invite?invite_token="placeholder".gsub('placeholder', :invitation_token => @token) %></p>

still waiting to get response from my partner on sending the invitation token through to the server. i also changed the notificaiton mailer:

class NotificationMailer < ActionMailer::Base
  def invite_message(user, from, subject, content)
    @user = user
    @token = user.raw_invitation_token
    invitation_link = accept_user_invitation_url(:invitation_token => @token)

    mail(:from => from, :bcc => from, :to => @user.email, :subject => subject, template_path: 'mailers/notification_mailer')
  end

Anjan Jagirdar

unread,
Oct 12, 2015, 9:56:08 AM10/12/15
to Devise
Where do you make this changes?
Reply all
Reply to author
Forward
0 new messages