Skip to content

Instantly share code, notes, and snippets.

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 cacciatc/1086892 to your computer and use it in GitHub Desktop.
Save cacciatc/1086892 to your computer and use it in GitHub Desktop.
Fix: so a user can only use their own invite code
class UsersController < Clearance::UsersController
# Override and add in a check for invitation code
def create
@user = User.new params[:user]
invite_code = params[:invite_code]
@invite = Invite.find_redeemable(invite_code)
# Invite code is present, there is an associated invite, and it is the user's invite
if invite_code && @invite && @invite.email == @user.email
if @user.save
@invite.redeemed!
ClearanceMailer.deliver_confirmation @user
flash[:notice] = "You will receive an email within the next few minutes. " <<
"It contains instructions for confirming your account."
redirect_to url_after_create
else
render :action => "new"
end
else
flash.now[:notice] = "Sorry, that code is not redeemable"
render :action => "new"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment