2012-06-17 03:15:46 +02:00
|
|
|
class SignupController < ApplicationController
|
2013-02-25 18:13:44 +01:00
|
|
|
before_filter :require_logged_in_user, :only => :invite
|
|
|
|
|
2012-06-17 03:15:46 +02:00
|
|
|
def index
|
2012-07-01 20:31:31 +02:00
|
|
|
if @user
|
|
|
|
flash[:error] = "You are already signed up."
|
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
|
|
|
@title = "Signup"
|
|
|
|
end
|
|
|
|
|
|
|
|
def invited
|
|
|
|
if @user
|
|
|
|
flash[:error] = "You are already signed up."
|
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
2013-02-08 17:39:51 +01:00
|
|
|
if !(@invitation = Invitation.find_by_code(params[:invitation_code].to_s))
|
2012-07-01 20:31:31 +02:00
|
|
|
flash[:error] = "Invalid or expired invitation"
|
|
|
|
return redirect_to "/signup"
|
|
|
|
end
|
|
|
|
|
2012-09-07 16:18:15 +02:00
|
|
|
@title = "Signup"
|
|
|
|
|
2012-06-17 03:15:46 +02:00
|
|
|
@new_user = User.new
|
2012-09-03 18:44:29 +02:00
|
|
|
@new_user.email = @invitation.email
|
|
|
|
|
2012-07-01 20:31:31 +02:00
|
|
|
render :action => "invited"
|
2012-06-17 03:15:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def signup
|
2013-02-08 17:39:51 +01:00
|
|
|
if !(@invitation = Invitation.find_by_code(params[:invitation_code].to_s))
|
2012-07-04 05:31:42 +02:00
|
|
|
flash[:error] = "Invalid or expired invitation."
|
2012-07-01 20:31:31 +02:00
|
|
|
return redirect_to "/signup"
|
|
|
|
end
|
|
|
|
|
2012-09-07 16:18:15 +02:00
|
|
|
@title = "Signup"
|
|
|
|
|
2012-06-17 03:15:46 +02:00
|
|
|
@new_user = User.new(params[:user])
|
2012-07-01 20:31:31 +02:00
|
|
|
@new_user.invited_by_user_id = @invitation.user_id
|
2012-06-17 03:15:46 +02:00
|
|
|
|
|
|
|
if @new_user.save
|
2012-07-01 20:31:31 +02:00
|
|
|
@invitation.destroy
|
2012-06-30 23:44:12 +02:00
|
|
|
session[:u] = @new_user.session_token
|
2013-06-30 08:29:51 +02:00
|
|
|
flash[:success] = "Welcome to #{Rails.application.name}, " <<
|
|
|
|
"#{@new_user.username}!"
|
2012-08-12 17:47:27 +02:00
|
|
|
|
2013-06-30 08:29:51 +02:00
|
|
|
Countinual.count!("#{Rails.application.shortname}.users.created", "+1")
|
2012-08-12 17:47:27 +02:00
|
|
|
|
2013-02-25 18:13:44 +01:00
|
|
|
return redirect_to "/signup/invite"
|
2012-06-17 03:15:46 +02:00
|
|
|
else
|
2012-07-01 20:31:31 +02:00
|
|
|
render :action => "invited"
|
2012-06-17 03:15:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|