Skip to content
This repository has been archived by the owner on Mar 21, 2019. It is now read-only.

If user exists redirect to refer-a-friend page #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class UsersController < ApplicationController
before_filter :skip_first_page, only: :new
before_filter :handle_ip, only: :create
before_action :user_exists, only: :create
before_action :skip_first_page, only: :new
before_action :handle_ip, only: :create

def new
@bodyId = 'home'
Expand All @@ -20,8 +21,7 @@ def create
@user.referrer = User.find_by_referral_code(ref_code) if ref_code

if @user.save
cookies[:h_email] = { value: @user.email }
redirect_to '/refer-a-friend'
set_cookie_and_redirect(@user.email)
else
logger.info("Error saving user with email, #{email}")
redirect_to root_path, alert: 'Something went wrong!'
Expand Down Expand Up @@ -52,6 +52,20 @@ def redirect

private

def set_cookie_and_redirect(email)
cookies[:h_email] = { value: email }
redirect_to '/refer-a-friend'
end

def user_exists
email = params[:user][:email].downcase
params[:user][:email] = email
user = User.find_by_email(email)
if not user.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there a truthy version of this? possibly user.exists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, while i'm not the maintainer, i'm sure it'd be appreciated if there was a unit test or two for this :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense thanks for the review, i would like someone with merging powers to let me know if they would be happy to merge this in before adding more code :)

set_cookie_and_redirect(user.email)
end
end

def skip_first_page
return if Rails.application.config.ended

Expand Down