module Invitation::UserRegistration
UserRegistration
should be included by your user registration controller.
Public Instance Methods
process_invite_token(new_user = nil)
click to toggle source
Check for an invitation token and process the invite. If an invitation is found, the user claims the invite.
Use this only when creating a new user. Invoke manually or from an after_action:
after_action :process_invite, only: [:create]
Invoke with new_user, or set an instance variable with the standard 'underscore' name of your user model class. For example, if your user model is UserProfile, this method will check for @user_profile.
# File lib/invitation/user_registration.rb, line 29 def process_invite_token(new_user = nil) new_user = user_instance_variable if new_user.nil? token = params[:invite_token] new_user.claim_invite token if !token.nil? && !new_user.nil? end
set_invite_token()
click to toggle source
Copy params to @invite_token. Your user registration form needs to include :invite_token, this method is the controller half of the glue.
Use this in your user registration controller in a before_action for the new action.
before_action :set_token, only: [:new]
# File lib/invitation/user_registration.rb, line 15 def set_invite_token @invite_token = params[:invite_token] end
Private Instance Methods
user_instance_variable()
click to toggle source
# File lib/invitation/user_registration.rb, line 37 def user_instance_variable name = Invitation.configuration.user_model_instance_var instance_variable_get(name) end