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
|
2016-11-26 13:58:51 +01:00
|
|
|
flash[:error] = I18n.t 'controllers.signup_controller.signedup'
|
2012-07-01 20:31:31 +02:00
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
|
|
|
@title = "Signup"
|
|
|
|
end
|
|
|
|
|
2015-07-24 07:33:04 +02:00
|
|
|
def invite
|
|
|
|
@title = "Pass Along an Invitation"
|
|
|
|
end
|
|
|
|
|
2012-07-01 20:31:31 +02:00
|
|
|
def invited
|
|
|
|
if @user
|
2016-11-26 13:58:51 +01:00
|
|
|
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
|
2012-07-01 20:31:31 +02:00
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
2013-12-24 04:20:06 +01:00
|
|
|
if !(@invitation = Invitation.where(:code => params[:invitation_code].to_s).first)
|
2016-11-26 13:58:51 +01:00
|
|
|
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
|
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
|
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-12-24 04:20:06 +01:00
|
|
|
if !(@invitation = Invitation.where(:code => params[:invitation_code].to_s).first)
|
2016-11-26 13:58:51 +01:00
|
|
|
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
|
2012-07-01 20:31:31 +02:00
|
|
|
return redirect_to "/signup"
|
|
|
|
end
|
|
|
|
|
2012-09-07 16:18:15 +02:00
|
|
|
@title = "Signup"
|
|
|
|
|
2014-02-02 21:41:38 +01:00
|
|
|
@new_user = User.new(user_params)
|
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")
|
2016-06-28 16:53:44 +02:00
|
|
|
Countinual.count!("#{Rails.application.shortname}.users.total",
|
|
|
|
User.count)
|
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
|
2014-02-02 21:41:38 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
def user_params
|
|
|
|
params.require(:user).permit(
|
|
|
|
:username, :email, :password, :password_confirmation, :about,
|
|
|
|
)
|
|
|
|
end
|
2012-06-17 03:15:46 +02:00
|
|
|
end
|