Skip to content

Instantly share code, notes, and snippets.

@tf
Created November 12, 2015 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tf/7dc139988642f4979c23 to your computer and use it in GitHub Desktop.
Save tf/7dc139988642f4979c23 to your computer and use it in GitHub Desktop.
InvitedUser for Devise > 3.0
<p><%= t('.salutation', first_name: @user.first_name, last_name: @user.last_name) %>,</p>
<p><%= t('.instruction') %></p>
<p><%= link_to main_app.edit_user_password_url(@user, :reset_password_token => @token),
main_app.edit_user_password_url(@user, :reset_password_token => @token) %></p>
<p><%= t('.ending') %></p>
<p><%= t('.greeting') %></p>
# Specialized User class containing invitation logic used by in the
# users admin.
class InvitedUser < User
before_create :prepare_invitation
after_create :send_invitation
def send_invitation!
prepare_invitation
self.save(:validate => false)
send_invitation
end
private
def generate_reset_password_token
raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
self.reset_password_token = enc
self.reset_password_sent_at = Time.now.utc
raw
end
def password_required?
false
end
def prepare_invitation
@token = generate_reset_password_token
end
def send_invitation
UserMailer.invitation('user_id' => id, 'password_token' => @token).deliver
end
end
@tf
Copy link
Author

tf commented Nov 12, 2015

Since Devise no longer stores the unencrypted reset token, we have to pass it explicitly to the mailer template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment