Forked from mchung/clearance_users_controller_with_invite.rb
Created
July 16, 2011 22:56
-
-
Save cacciatc/1086892 to your computer and use it in GitHub Desktop.
Fix: so a user can only use their own invite code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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