From 409021fc3153227102170b625549f9dcc9bf733a Mon Sep 17 00:00:00 2001 From: danny pham Date: Tue, 25 Nov 2014 22:36:18 -0800 Subject: [PATCH] removes extra spaces and reduces indentation in rb files --- app/admin/admin_user.rb | 36 ++--- app/admin/users.rb | 2 +- app/controllers/application_controller.rb | 36 ++--- app/controllers/users_controller.rb | 173 +++++++++++----------- app/mailers/user_mailer.rb | 12 +- app/models/admin_user.rb | 2 +- app/models/user.rb | 106 ++++++------- 7 files changed, 183 insertions(+), 184 deletions(-) diff --git a/app/admin/admin_user.rb b/app/admin/admin_user.rb index 3aac52f3e..337e34b90 100755 --- a/app/admin/admin_user.rb +++ b/app/admin/admin_user.rb @@ -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 diff --git a/app/admin/users.rb b/app/admin/users.rb index e611bbf3b..7747a6ff1 100755 --- a/app/admin/users.rb +++ b/app/admin/users.rb @@ -10,5 +10,5 @@ end actions :index, :show - + end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7516436c0..20f32ea81 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f38782be8..9a6d4ab47 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 3be0331c0..1d86c73ec 100755 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,10 +1,10 @@ class UserMailer < ActionMailer::Base - default from: "Harry's " + default from: "Harry's " - 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 diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb index 4a1624f4d..ad4b28863 100755 --- a/app/models/admin_user.rb +++ b/app/models/admin_user.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index de7532837..17e29ff1b 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,57 +1,57 @@ class User < ActiveRecord::Base - belongs_to :referrer, :class_name => "User", :foreign_key => "referrer_id" - has_many :referrals, :class_name => "User", :foreign_key => "referrer_id" - - attr_accessible :email - - validates :email, :uniqueness => true, :format => { :with => /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i, :message => "Invalid email format." } - validates :referral_code, :uniqueness => true - - before_create :create_referral_code - after_create :send_welcome_email - - REFERRAL_STEPS = [ - { - 'count' => 5, - "html" => "Shave
Cream", - "class" => "two", - "image" => ActionController::Base.helpers.asset_path("refer/cream-tooltip@2x.png") - }, - { - 'count' => 10, - "html" => "Truman Handle
w/ Blade", - "class" => "three", - "image" => ActionController::Base.helpers.asset_path("refer/truman@2x.png") - }, - { - 'count' => 25, - "html" => "Winston
Shave Set", - "class" => "four", - "image" => ActionController::Base.helpers.asset_path("refer/winston@2x.png") - }, - { - 'count' => 50, - "html" => "One Year
Free Blades", - "class" => "five", - "image" => ActionController::Base.helpers.asset_path("refer/blade-explain@2x.png") - } - ] - - private - - def create_referral_code - referral_code = SecureRandom.hex(5) - @collision = User.find_by_referral_code(referral_code) - - while !@collision.nil? - referral_code = SecureRandom.hex(5) - @collision = User.find_by_referral_code(referral_code) - end - - self.referral_code = referral_code + belongs_to :referrer, :class_name => "User", :foreign_key => "referrer_id" + has_many :referrals, :class_name => "User", :foreign_key => "referrer_id" + + attr_accessible :email + + validates :email, :uniqueness => true, :format => { :with => /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i, :message => "Invalid email format." } + validates :referral_code, :uniqueness => true + + before_create :create_referral_code + after_create :send_welcome_email + + REFERRAL_STEPS = [ + { + "count" => 5, + "html" => "Shave
Cream", + "class" => "two", + "image" => ActionController::Base.helpers.asset_path("refer/cream-tooltip@2x.png") + }, + { + "count" => 10, + "html" => "Truman Handle
w/ Blade", + "class" => "three", + "image" => ActionController::Base.helpers.asset_path("refer/truman@2x.png") + }, + { + "count" => 25, + "html" => "Winston
Shave Set", + "class" => "four", + "image" => ActionController::Base.helpers.asset_path("refer/winston@2x.png") + }, + { + "count" => 50, + "html" => "One Year
Free Blades", + "class" => "five", + "image" => ActionController::Base.helpers.asset_path("refer/blade-explain@2x.png") + } + ] + + private + + def create_referral_code + referral_code = SecureRandom.hex(5) + @collision = User.find_by_referral_code(referral_code) + + while !@collision.nil? + referral_code = SecureRandom.hex(5) + @collision = User.find_by_referral_code(referral_code) end - def send_welcome_email - UserMailer.delay.signup_email(self) - end + self.referral_code = referral_code + end + + def send_welcome_email + UserMailer.delay.signup_email(self) + end end