Module: Plutonium::Invites::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/plutonium/invites/controller.rb
Overview
Controller provides the invitation acceptance flow for controllers.
This concern handles:
-
Showing the invitation landing page
-
Accepting invitations for logged-in users
-
Signup flow for new users
-
Cookie management for pending invitations
Instance Method Summary collapse
-
#accept ⇒ Object
POST /invitations/:token/accept.
-
#show ⇒ Object
GET /invitations/:token.
-
#signup ⇒ Object
GET/POST /invitations/:token/signup.
Instance Method Details
#accept ⇒ Object
POST /invitations/:token/accept
Accepts the invitation for the currently logged-in user.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/plutonium/invites/controller.rb', line 71 def accept return unless (@invite = load_and_validate_invite(params[:token])) unless current_user redirect_to invitation_path(token: params[:token]), alert: "Please sign in to accept this invitation" return end @invite.accept_for_user!(current_user) .delete(:pending_invitation) redirect_to after_accept_path, notice: "Invitation accepted! Welcome to #{@invite.entity.to_label}!" rescue ActiveRecord::RecordInvalid => e @error_title = "Acceptance Error" @error_message = e.record.errors..join(", ") render :error, status: :forbidden end |
#show ⇒ Object
GET /invitations/:token
Shows the invitation landing page. If the user is logged in, shows the acceptance form. If not, shows signup/login options.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/plutonium/invites/controller.rb', line 45 def show return unless (@invite = load_and_validate_invite(params[:token])) # Store invitation token in cookie for later use .encrypted[:pending_invitation] = { value: params[:token], expires: 1.hour.from_now } if current_user begin @invite.validate_email_constraints!(current_user.email) render :show rescue ActiveRecord::RecordInvalid => e @error_title = "Email Validation Error" @error_message = e.record.errors..join(", ") render :error, status: :forbidden end else render :landing end end |
#signup ⇒ Object
GET/POST /invitations/:token/signup
Handles new user signup directly from the invitation.
94 95 96 97 98 99 100 101 102 |
# File 'lib/plutonium/invites/controller.rb', line 94 def signup return unless (@invite = load_and_validate_invite(params[:token])) if request.post? handle_signup_submission else render :signup end end |