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

Commit

Permalink
removes extra spaces and reduces indentation in rb files
Browse files Browse the repository at this point in the history
  • Loading branch information
phamdt committed Nov 26, 2014
1 parent cd09ac1 commit 409021f
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 184 deletions.
36 changes: 18 additions & 18 deletions app/admin/admin_user.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
ActiveAdmin.register AdminUser do
index do
column :email
column :current_sign_in_at
column :last_sign_in_at
column :sign_in_count
default_actions
end
ActiveAdmin.register AdminUser do
index do
column :email
column :current_sign_in_at
column :last_sign_in_at
column :sign_in_count
default_actions
end

filter :email
filter :email

form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
2 changes: 1 addition & 1 deletion app/admin/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
end

actions :index, :show

end
36 changes: 18 additions & 18 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class ApplicationController < ActionController::Base
protect_from_forgery
protect_from_forgery

before_filter :ref_to_cookie
before_filter :ref_to_cookie

def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile|webOS/
end
def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile|webOS/
end
end

protected
protected

def ref_to_cookie
if params[:ref] && !Rails.application.config.ended
if !User.find_by_referral_code(params[:ref]).nil?
cookies[:h_ref] = { :value => params[:ref], :expires => 1.week.from_now }
end
def ref_to_cookie
if params[:ref] && !Rails.application.config.ended
if !User.find_by_referral_code(params[:ref]).nil?
cookies[:h_ref] = { :value => params[:ref], :expires => 1.week.from_now }
end

if request.env["HTTP_USER_AGENT"] and !request.env["HTTP_USER_AGENT"].include?("facebookexternalhit/1.1")
redirect_to proc { url_for(params.except(:ref)) }
end
end
if request.env["HTTP_USER_AGENT"] and !request.env["HTTP_USER_AGENT"].include?("facebookexternalhit/1.1")
redirect_to proc { url_for(params.except(:ref)) }
end
end
end
end
173 changes: 86 additions & 87 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,104 +1,103 @@
class UsersController < ApplicationController
before_filter :skip_first_page, :only => :new
before_filter :skip_first_page, :only => :new

def new
@bodyId = 'home'
@is_mobile = mobile_device?
def new
@bodyId = 'home'
@is_mobile = mobile_device?

@user = User.new
@user = User.new

respond_to do |format|
format.html # new.html.erb
end
respond_to do |format|
format.html # new.html.erb
end
end

def create
# Get user to see if they have already signed up
@user = User.find_by_email(params[:user][:email]);

# If user doesnt exist, make them, and attach referrer
if @user.nil?

cur_ip = IpAddress.find_by_address(request.env['HTTP_X_FORWARDED_FOR'])

if !cur_ip
cur_ip = IpAddress.create(
:address => request.env['HTTP_X_FORWARDED_FOR'],
:count => 0
)
end

if cur_ip.count > 2
return redirect_to root_path
else
cur_ip.count = cur_ip.count + 1
cur_ip.save
end

@user = User.new(:email => params[:user][:email])

@referred_by = User.find_by_referral_code(cookies[:h_ref])

puts '------------'
puts @referred_by.email if @referred_by
puts params[:user][:email].inspect
puts request.env['HTTP_X_FORWARDED_FOR'].inspect
puts '------------'

if !@referred_by.nil?
@user.referrer = @referred_by
end

@user.save
end

# Send them over refer action
respond_to do |format|
if !@user.nil?
cookies[:h_email] = { :value => @user.email }
format.html { redirect_to '/refer-a-friend' }
else
format.html { redirect_to root_path, :alert => "Something went wrong!" }
end
end
end
def create
# Get user to see if they have already signed up
@user = User.find_by_email(params[:user][:email]);

def refer
email = cookies[:h_email]
# If user doesnt exist, make them, and attach referrer
if @user.nil?

@bodyId = 'refer'
@is_mobile = mobile_device?
cur_ip = IpAddress.find_by_address(request.env['HTTP_X_FORWARDED_FOR'])

@user = User.find_by_email(email)
if !cur_ip
cur_ip = IpAddress.create(
:address => request.env['HTTP_X_FORWARDED_FOR'],
:count => 0
)
end

respond_to do |format|
if !@user.nil?
format.html #refer.html.erb
else
format.html { redirect_to root_path, :alert => "Something went wrong!" }
end
end
end
if cur_ip.count > 2
return redirect_to root_path
else
cur_ip.count = cur_ip.count + 1
cur_ip.save
end

@user = User.new(:email => params[:user][:email])

@referred_by = User.find_by_referral_code(cookies[:h_ref])

def policy

end
puts '------------'
puts @referred_by.email if @referred_by
puts params[:user][:email].inspect
puts request.env['HTTP_X_FORWARDED_FOR'].inspect
puts '------------'

def redirect
redirect_to root_path, :status => 404
if !@referred_by.nil?
@user.referrer = @referred_by
end

@user.save
end

private

def skip_first_page
if !Rails.application.config.ended
email = cookies[:h_email]
if email and !User.find_by_email(email).nil?
redirect_to '/refer-a-friend'
else
cookies.delete :h_email
end
end
# Send them over refer action
respond_to do |format|
if !@user.nil?
cookies[:h_email] = { :value => @user.email }
format.html { redirect_to '/refer-a-friend' }
else
format.html { redirect_to root_path, :alert => "Something went wrong!" }
end
end
end

def refer
email = cookies[:h_email]

@bodyId = 'refer'
@is_mobile = mobile_device?

@user = User.find_by_email(email)

respond_to do |format|
if !@user.nil?
format.html #refer.html.erb
else
format.html { redirect_to root_path, :alert => "Something went wrong!" }
end
end
end

def policy

end

def redirect
redirect_to root_path, :status => 404
end

private

def skip_first_page
if !Rails.application.config.ended
email = cookies[:h_email]
if email and !User.find_by_email(email).nil?
redirect_to '/refer-a-friend'
else
cookies.delete :h_email
end
end
end
end
12 changes: 6 additions & 6 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class UserMailer < ActionMailer::Base
default from: "Harry's <[email protected]>"
default from: "Harry's <[email protected]>"

def signup_email(user)
@user = user
@twitter_message = "#Shaving is evolving. Excited for @harrys to launch."
def signup_email(user)
@user = user
@twitter_message = "#Shaving is evolving. Excited for @harrys to launch."

mail(:to => user.email, :subject => "Thanks for signing up!")
end
mail(:to => user.email, :subject => "Thanks for signing up!")
end
end
2 changes: 1 addition & 1 deletion app/models/admin_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
Expand Down
Loading

0 comments on commit 409021f

Please sign in to comment.