journalduhacker/app/controllers/signup_controller.rb
2018-10-20 12:18:23 +02:00

69 lines
1.7 KiB
Ruby

class SignupController < ApplicationController
before_filter :require_logged_in_user, :only => :invite
def index
if @user
flash[:error] = I18n.t 'controllers.signup_controller.signedup'
return redirect_to "/"
end
@title = "Signup"
end
def invite
@title = I18n.t 'controllers.signup_controller.signuptitle'
end
def invited
if @user
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
return redirect_to "/"
end
if !(@invitation = Invitation.where(:code => params[:invitation_code].to_s).first)
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
return redirect_to "/signup"
end
@title = "Signup"
@new_user = User.new
@new_user.email = @invitation.email
render :action => "invited"
end
def signup
if !(@invitation = Invitation.where(:code => params[:invitation_code].to_s).first)
flash[:error] = I18n.t 'controllers.signup_controller.invalidinv'
return redirect_to "/signup"
end
@title = "Signup"
@new_user = User.new(user_params)
@new_user.invited_by_user_id = @invitation.user_id
if @new_user.save
@invitation.destroy
session[:u] = @new_user.session_token
flash[:success] = I18n.t 'controllers.signup_controller.flashsuccesssignupcontroller'
Countinual.count!("#{Rails.application.shortname}.users.created", "+1")
Countinual.count!("#{Rails.application.shortname}.users.total",
User.count)
return redirect_to "/signup/invite"
else
render :action => "invited"
end
end
private
def user_params
params.require(:user).permit(
:username, :email, :password, :password_confirmation, :about,
)
end
end