2012-07-01 20:31:31 +02:00
|
|
|
class InvitationsController < ApplicationController
|
2013-10-18 22:49:20 +02:00
|
|
|
before_filter :require_logged_in_user,
|
|
|
|
:except => [ :build, :create_by_request, :confirm_email ]
|
|
|
|
|
|
|
|
def build
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
@invitation_requests = InvitationRequest.where(:is_verified => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_email
|
2013-12-24 04:20:06 +01:00
|
|
|
if !(ir = InvitationRequest.where(:code => params[:code].to_s).first)
|
2013-10-18 22:49:20 +02:00
|
|
|
flash[:error] = "Invalid or expired invitation request"
|
|
|
|
return redirect_to "/invitations/request"
|
|
|
|
end
|
|
|
|
|
|
|
|
ir.is_verified = true
|
|
|
|
ir.save!
|
|
|
|
|
|
|
|
flash[:success] = "Your invitiation request has been validated and " <<
|
|
|
|
"will now be shown to other logged-in users."
|
|
|
|
return redirect_to "/invitations/request"
|
|
|
|
end
|
2012-07-01 20:31:31 +02:00
|
|
|
|
|
|
|
def create
|
|
|
|
i = Invitation.new
|
|
|
|
i.user_id = @user.id
|
|
|
|
i.email = params[:email]
|
|
|
|
i.memo = params[:memo]
|
2012-09-07 16:24:29 +02:00
|
|
|
|
|
|
|
begin
|
|
|
|
if i.save
|
|
|
|
i.send_email
|
|
|
|
flash[:success] = "Successfully e-mailed invitation to " <<
|
|
|
|
params[:email].to_s << "."
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
rescue
|
2012-07-01 20:31:31 +02:00
|
|
|
flash[:error] = "Could not send invitation, verify the e-mail " <<
|
|
|
|
"address is valid."
|
|
|
|
end
|
|
|
|
|
2013-02-22 21:52:22 +01:00
|
|
|
if params[:return_home]
|
|
|
|
return redirect_to "/"
|
|
|
|
else
|
|
|
|
return redirect_to "/settings"
|
|
|
|
end
|
2012-07-01 20:31:31 +02:00
|
|
|
end
|
2013-10-18 22:49:20 +02:00
|
|
|
|
|
|
|
def create_by_request
|
|
|
|
ir = InvitationRequest.new
|
|
|
|
ir.name = params[:name]
|
|
|
|
ir.email = params[:email]
|
|
|
|
ir.memo = params[:memo]
|
|
|
|
|
|
|
|
ir.ip_address = request.remote_ip
|
|
|
|
|
|
|
|
if ir.save
|
|
|
|
flash[:success] = "You have been e-mailed a confirmation to " <<
|
|
|
|
params[:email].to_s << "."
|
|
|
|
return redirect_to "/invitations/request"
|
|
|
|
else
|
|
|
|
render :action => :build
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_for_request
|
2013-12-24 04:20:06 +01:00
|
|
|
if !(ir = InvitationRequest.where(:code => params[:code].to_s).first)
|
2013-10-18 22:49:20 +02:00
|
|
|
flash[:error] = "Invalid or expired invitation request"
|
|
|
|
return redirect_to "/invitations"
|
|
|
|
end
|
|
|
|
|
2013-12-02 18:54:29 +01:00
|
|
|
if ir
|
2013-10-18 22:49:20 +02:00
|
|
|
i = Invitation.new
|
|
|
|
i.user_id = @user.id
|
|
|
|
i.email = ir.email
|
|
|
|
|
|
|
|
if i.save
|
|
|
|
i.send_email
|
|
|
|
ir.destroy
|
|
|
|
flash[:success] = "Successfully e-mailed invitation to " <<
|
|
|
|
ir.name.to_s << "."
|
|
|
|
end
|
|
|
|
|
|
|
|
return redirect_to "/invitations"
|
|
|
|
else
|
|
|
|
render :action => :build
|
|
|
|
end
|
|
|
|
end
|
2012-07-01 20:31:31 +02:00
|
|
|
end
|