Sha256: 967cbe9178c08d8263685d01db37589ffaafee20567c5dfcdee0ab2a6da2d2bb

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

module Invitation
  #
  # UserRegistration should be included by your user registration controller.
  #
  module UserRegistration
    extend ActiveSupport::Concern

    # Copy params[:invite_token] 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]
    #
    def set_invite_token
      @invite_token = params[:invite_token]
    end

    # 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.
    #
    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

    private

    def user_instance_variable
      name = Invitation.configuration.user_model_instance_var
      instance_variable_get(name)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
invitation-0.6.1 lib/invitation/user_registration.rb
invitation-0.6.0 lib/invitation/user_registration.rb
invitation-0.5.1 lib/invitation/user_registration.rb
invitation-0.5.0 lib/invitation/user_registration.rb
invitation-0.4.5 lib/invitation/user_registration.rb
invitation-0.4.4 lib/invitation/user_registration.rb
invitation-0.4.3 lib/invitation/user_registration.rb
invitation-0.4.2 lib/invitation/user_registration.rb
invitation-0.4.1 lib/invitation/user_registration.rb
invitation-0.4 lib/invitation/user_registration.rb
invitation-0.3 lib/invitation/user_registration.rb
invitation-0.2 lib/invitation/user_registration.rb