Permalink
Browse files

more files

  • Loading branch information...
1 parent 0a065cc commit 442d4734e467e6e3c38e28e24a82d5c3c1b8134f @schneems committed Apr 26, 2011
Showing with 1,130 additions and 75 deletions.
  1. BIN .DS_Store
  2. +8 −0 Gemfile
  3. +15 −8 Gemfile.lock
  4. +24 −0 app/controllers/admin_sessions_controller.rb
  5. +53 −0 app/controllers/admins_controller.rb
  6. +6 −6 app/controllers/application_controller.rb
  7. +17 −0 app/controllers/friendships_controller.rb
  8. +16 −8 app/controllers/users_controller.rb
  9. +2 −0 app/helpers/admin_helper.rb
  10. +12 −0 app/models/admin.rb
  11. +2 −0 app/models/admin_session.rb
  12. +37 −8 app/models/friendship.rb
  13. +84 −2 app/models/user.rb
  14. +14 −0 app/views/admins/_admin.html.erb
  15. +7 −0 app/views/admins/_create_users.html.erb
  16. +5 −0 app/views/admins/_explain.html.erb
  17. +2 −0 app/views/admins/edit.html.erb
  18. +9 −0 app/views/admins/index.html.erb
  19. +2 −0 app/views/admins/new.html.erb
  20. +30 −0 app/views/admins/show.html.erb
  21. +9 −6 app/views/layouts/application.html.erb
  22. +22 −0 app/views/users/_show.html.erb
  23. +16 −9 app/views/users/_user.html.erb
  24. +1 −1 app/views/users/index.html.erb
  25. +16 −0 app/views/users/show.html.erb
  26. +15 −6 config/routes.rb
  27. +20 −0 db/migrate/20110424055910_create_admin.rb
  28. +15 −0 db/migrate/20110424063244_add_avatar_columns_to_user.rb
  29. +16 −1 db/schema.rb
  30. BIN public/.DS_Store
  31. BIN public/images/.DS_Store
  32. BIN public/images/cats/cat_cougar.jpeg
  33. BIN public/images/cats/cat_dog_fox.jpeg
  34. BIN public/images/cats/cat_hyena.jpeg
  35. BIN public/images/cats/cat_lion.jpeg
  36. BIN public/images/cats/cat_tiger.jpeg
  37. BIN public/images/cats/cat_white_tiger.jpeg
  38. BIN public/images/dogs/dog_beagle.jpeg
  39. BIN public/images/dogs/dog_cat_cat_dog.jpeg
  40. BIN public/images/dogs/dog_dachsund.jpeg
  41. BIN public/images/dogs/dog_husky.jpeg
  42. BIN public/images/dogs/dog_pomeranian.jpeg
  43. BIN public/images/dogs/dog_wolf.jpeg
  44. BIN public/images/ninjas/ninja sipper.jpg
  45. BIN public/images/ninjas/ninja_3.jpeg
  46. BIN public/images/ninjas/ninja_cat.jpeg
  47. BIN public/images/ninjas/ninja_dog.jpeg
  48. BIN public/images/ninjas/ninja_gaiden.jpeg
  49. BIN public/images/ninjas/ninja_girl.jpeg
  50. BIN public/images/ninjas/ninja_penguin.jpeg
  51. BIN public/images/ninjas/ninja_pirate.jpeg
  52. BIN public/images/ninjas/ninja_pirate_t_rex.jpeg
  53. BIN public/images/ninjas/ninja_shadow.jpeg
  54. BIN public/images/ninjas/ninja_turtle.jpeg
  55. BIN public/images/pirates/pirate_bay.jpeg
  56. BIN public/images/pirates/pirate_blackbeard.jpeg
  57. BIN public/images/pirates/pirate_cat.jpeg
  58. BIN public/images/pirates/pirate_dog.jpeg
  59. BIN public/images/pirates/pirate_fake.jpeg
  60. BIN public/images/pirates/pirate_morgan.jpeg
  61. BIN public/images/pirates/pirate_ninja.jpeg
  62. +614 −0 public/stylesheets/960.css
  63. +29 −20 public/stylesheets/pot_friends.css
  64. BIN public/system/avatars/36/medium/cat_cougar.jpeg
  65. BIN public/system/avatars/36/original/cat_cougar.jpeg
  66. BIN public/system/avatars/36/thumb/cat_cougar.jpeg
  67. BIN public/system/avatars/37/medium/cat_dog_fox.jpeg
  68. BIN public/system/avatars/37/original/cat_dog_fox.jpeg
  69. BIN public/system/avatars/37/thumb/cat_dog_fox.jpeg
  70. BIN public/system/avatars/38/medium/cat_hyena.jpeg
  71. BIN public/system/avatars/38/original/cat_hyena.jpeg
  72. BIN public/system/avatars/38/thumb/cat_hyena.jpeg
  73. BIN public/system/avatars/39/medium/cat_lion.jpeg
  74. BIN public/system/avatars/39/original/cat_lion.jpeg
  75. BIN public/system/avatars/39/thumb/cat_lion.jpeg
  76. BIN public/system/avatars/40/medium/cat_tiger.jpeg
  77. BIN public/system/avatars/40/original/cat_tiger.jpeg
  78. BIN public/system/avatars/40/thumb/cat_tiger.jpeg
  79. BIN public/system/avatars/41/medium/cat_white_tiger.jpeg
  80. BIN public/system/avatars/41/original/cat_white_tiger.jpeg
  81. BIN public/system/avatars/41/thumb/cat_white_tiger.jpeg
  82. BIN public/system/avatars/42/medium/dog_beagle.jpeg
  83. BIN public/system/avatars/42/original/dog_beagle.jpeg
  84. BIN public/system/avatars/42/thumb/dog_beagle.jpeg
  85. BIN public/system/avatars/43/medium/dog_cat_cat_dog.jpeg
  86. BIN public/system/avatars/43/original/dog_cat_cat_dog.jpeg
  87. BIN public/system/avatars/43/thumb/dog_cat_cat_dog.jpeg
  88. BIN public/system/avatars/44/medium/dog_dachsund.jpeg
  89. BIN public/system/avatars/44/original/dog_dachsund.jpeg
  90. BIN public/system/avatars/44/thumb/dog_dachsund.jpeg
  91. BIN public/system/avatars/45/medium/dog_husky.jpeg
  92. BIN public/system/avatars/45/original/dog_husky.jpeg
  93. BIN public/system/avatars/45/thumb/dog_husky.jpeg
  94. BIN public/system/avatars/46/medium/dog_pomeranian.jpeg
  95. BIN public/system/avatars/46/original/dog_pomeranian.jpeg
  96. BIN public/system/avatars/46/thumb/dog_pomeranian.jpeg
  97. BIN public/system/avatars/47/medium/dog_wolf.jpeg
  98. BIN public/system/avatars/47/original/dog_wolf.jpeg
  99. BIN public/system/avatars/47/thumb/dog_wolf.jpeg
  100. BIN public/system/avatars/48/medium/pirate_bay.jpeg
  101. BIN public/system/avatars/48/original/pirate_bay.jpeg
  102. BIN public/system/avatars/48/thumb/pirate_bay.jpeg
  103. BIN public/system/avatars/49/medium/pirate_blackbeard.jpeg
  104. BIN public/system/avatars/49/original/pirate_blackbeard.jpeg
  105. BIN public/system/avatars/49/thumb/pirate_blackbeard.jpeg
  106. BIN public/system/avatars/50/medium/pirate_cat.jpeg
  107. BIN public/system/avatars/50/original/pirate_cat.jpeg
  108. BIN public/system/avatars/50/thumb/pirate_cat.jpeg
  109. BIN public/system/avatars/51/medium/pirate_dog.jpeg
  110. BIN public/system/avatars/51/original/pirate_dog.jpeg
  111. BIN public/system/avatars/51/thumb/pirate_dog.jpeg
  112. BIN public/system/avatars/52/medium/pirate_fake.jpeg
  113. BIN public/system/avatars/52/original/pirate_fake.jpeg
  114. BIN public/system/avatars/52/thumb/pirate_fake.jpeg
  115. BIN public/system/avatars/53/medium/pirate_morgan.jpeg
  116. BIN public/system/avatars/53/original/pirate_morgan.jpeg
  117. BIN public/system/avatars/53/thumb/pirate_morgan.jpeg
  118. BIN public/system/avatars/54/medium/pirate_ninja.jpeg
  119. BIN public/system/avatars/54/original/pirate_ninja.jpeg
  120. BIN public/system/avatars/54/thumb/pirate_ninja.jpeg
  121. BIN public/system/avatars/55/medium/ninja_3.jpeg
  122. BIN public/system/avatars/55/original/ninja_3.jpeg
  123. BIN public/system/avatars/55/thumb/ninja_3.jpeg
  124. BIN public/system/avatars/56/medium/ninja_cat.jpeg
  125. BIN public/system/avatars/56/original/ninja_cat.jpeg
  126. BIN public/system/avatars/56/thumb/ninja_cat.jpeg
  127. BIN public/system/avatars/57/medium/ninja_dog.jpeg
  128. BIN public/system/avatars/57/original/ninja_dog.jpeg
  129. BIN public/system/avatars/57/thumb/ninja_dog.jpeg
  130. BIN public/system/avatars/58/medium/ninja_gaiden.jpeg
  131. BIN public/system/avatars/58/original/ninja_gaiden.jpeg
  132. BIN public/system/avatars/58/thumb/ninja_gaiden.jpeg
  133. BIN public/system/avatars/59/medium/ninja_girl.jpeg
  134. BIN public/system/avatars/59/original/ninja_girl.jpeg
  135. BIN public/system/avatars/59/thumb/ninja_girl.jpeg
  136. BIN public/system/avatars/60/medium/ninja_penguin.jpeg
  137. BIN public/system/avatars/60/original/ninja_penguin.jpeg
  138. BIN public/system/avatars/60/thumb/ninja_penguin.jpeg
  139. BIN public/system/avatars/61/medium/ninja_pirate.jpeg
  140. BIN public/system/avatars/61/original/ninja_pirate.jpeg
  141. BIN public/system/avatars/61/thumb/ninja_pirate.jpeg
  142. BIN public/system/avatars/62/medium/ninja_pirate_t_rex.jpeg
  143. BIN public/system/avatars/62/original/ninja_pirate_t_rex.jpeg
  144. BIN public/system/avatars/62/thumb/ninja_pirate_t_rex.jpeg
  145. BIN public/system/avatars/63/medium/ninja_shadow.jpeg
  146. BIN public/system/avatars/63/original/ninja_shadow.jpeg
  147. BIN public/system/avatars/63/thumb/ninja_shadow.jpeg
  148. BIN public/system/avatars/64/medium/ninja_turtle.jpeg
  149. BIN public/system/avatars/64/original/ninja_turtle.jpeg
  150. BIN public/system/avatars/64/thumb/ninja_turtle.jpeg
  151. +8 −0 test/functional/admin_controller_test.rb
  152. +4 −0 test/unit/helpers/admin_helper_test.rb
  153. BIN vendor/.DS_Store
View
BIN .DS_Store
Binary file not shown.
View
@@ -1,3 +1,4 @@
+# source "http://localhost:8808"
source 'http://rubygems.org'
gem 'rails', '3.0.5'
@@ -6,6 +7,13 @@ gem 'dynamic_form'
gem 'authlogic'
gem 'memcached'
gem 'redis', '1.0.6'
+gem "paperclip", "~> 2.3"
+gem "rmagick"
+gem "httparty"
+
+gem 'haml'
+
+# gem 'keytar', '0.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
@@ -32,23 +32,22 @@ GEM
authlogic (2.1.6)
activesupport
builder (2.1.2)
- capistrano (2.5.20)
- highline
+ capistrano (2.5.21)
highline
net-scp (>= 1.0.0)
- net-scp
- net-sftp
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
- net-ssh
- net-ssh-gateway
net-ssh-gateway (>= 1.0.0)
- dynamic_form (1.1.3)
+ crack (0.1.8)
+ dynamic_form (1.1.4)
erubis (2.6.6)
abstract (>= 1.0.0)
+ haml (3.1.1)
highline (1.6.1)
+ httparty (0.7.7)
+ crack (= 0.1.8)
i18n (0.5.0)
- mail (2.2.15)
+ mail (2.2.17)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -62,6 +61,9 @@ GEM
net-ssh (2.1.4)
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
+ paperclip (2.3.11)
+ activerecord (>= 2.3.0)
+ activesupport (>= 2.3.2)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
@@ -83,6 +85,7 @@ GEM
thor (~> 0.14.4)
rake (0.8.7)
redis (1.0.6)
+ rmagick (2.13.1)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
@@ -96,7 +99,11 @@ DEPENDENCIES
authlogic
capistrano
dynamic_form
+ haml
+ httparty
memcached
+ paperclip (~> 2.3)
rails (= 3.0.5)
redis (= 1.0.6)
+ rmagick
sqlite3
@@ -0,0 +1,24 @@
+class AdminSessionsController < ApplicationController
+ def new
+ @admin_session = AdminSession.new
+ end
+
+ def create
+ @admin_session = AdminSession.new(params[:user_session])
+ if @admin_session.save
+ flash[:notice] = "Successfully logged in."
+ redirect_to root_url
+ else
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ @admin_session = AdminSession.find
+ @admin_session.destroy
+ flash[:notice] = "Successfully logged out."
+ redirect_to root_url
+ end
+
+
+end
@@ -0,0 +1,53 @@
+class AdminsController < ApplicationController
+
+ def create_users
+ @user = User.new
+ @users = User.all
+ end
+
+
+
+ def edit
+ @admin = current_admin
+ end
+
+
+ def index
+ if current_admin.blank?
+ redirect_to new_admin_path, :notice => "Please Log In" and return true
+ end
+ end
+
+ def show
+
+ if current_admin.blank?
+ redirect_to new_admin_path, :notice => "Please Log In" and return true
+ end
+ @admin = current_admin
+ @user = @admin.users.new
+ @users = User.where(:admin_id => @admin.id)
+ end
+
+ def new
+ @admin = Admin.new
+ end
+
+ def create
+ @admin = Admin.new(params[:admin])
+ if @admin.save
+ notice = "Registration successful."
+ end
+ redirect_to admin_path(@admin), :notice => notice
+ end
+
+
+ def seed
+ return false if current_admin.blank? || (taxonomy = params[:taxonomy].downcase.to_s).blank?
+ Dir[Rails.root.join("public/images/#{taxonomy}/*.jpeg")].each do |file|
+ username = file.match(/([^\/]*)\.jpeg$/) && ($1).to_s
+ current_admin.users.create(:username => username, :avatar => open(file))
+ end
+ redirect_to admin_path(current_admin)
+ end
+
+end
@@ -1,15 +1,15 @@
class ApplicationController < ActionController::Base
protect_from_forgery
- helper_method :current_user
+ helper_method :current_admin
private
- def current_user_session
- return @current_user_session if defined?(@current_user_session)
- @current_user_session = UserSession.find
+ def current_admin_session
+ return @current_admin_session if defined?(@current_admin_session)
+ @current_admin_session = AdminSession.find
end
- def current_user
- @current_user = current_user_session && current_user_session.record
+ def current_admin
+ @current_admin = current_admin_session && current_admin_session.record
end
end
@@ -1,4 +1,21 @@
class FriendshipsController < ApplicationController
+
+ # used only for purposeses of demo, don't actually put this in your code
+ def create_arbitrary_friendship
+ user_1 = current_admin.users.find(params[:user_1])
+ user_2 = current_admin.users.find(params[:user_2])
+ Friendship.create_arbitrary_friendship(user_2, user_1 )
+ redirect_to :back, :notice => "#{user_1.username} now friends with #{user_2.username}"
+ end
+
+ # used only for purposeses of demo, don't actually put this in your code
+ def destroy_arbitrary_friendship
+ user_1 = current_admin.users.find(params[:user_1])
+ user_2 = current_admin.users.find(params[:user_2])
+ Friendship.destroy_arbitrary_friendship(user_2, user_1 )
+ puts "============================================================="
+ redirect_to :back, :notice => "#{user_1.username} totally hates #{user_2.username} and vice-versa, DE-FRIENDSHIP COMPLETE"
+ end
def accept_friendship
if Friendship.accept(current_user, User.get(params[:user_id])) # means that current user just acknowledged friend's request
@@ -1,28 +1,36 @@
class UsersController < ApplicationController
+
+ def show
+ @user = User.where(:id => params[:id]).first
+ puts
+ @users = current_admin.users.where("id not in (#{@user.not_potential_friend_ids.join(",")})")
+ end
+
+
def new
- @user = User.new
+ @user = User.new
end
def create
+ params[:user][:avatar] = StringIO.new(HTTParty.get(params[:url_for_avatar]).body) unless params[:url_for_avatar].blank?
+ params[:user][:admin_id] = current_admin.id unless current_admin.blank?
@user = User.new(params[:user])
if @user.save
- flash[:notice] = "Registration successful."
- redirect_to root_url
- else
- render :action => 'new'
- end
+ notice = "Registration successful."
+ end
+ redirect_to :back, :notice => notice
end
def index
@users = User.all
end
def edit
- @user = current_user
+ @user = User.where(:id => params[:id]).first
end
def update
- @user = current_user
+ @user = User.where(:id => params[:id]).first
if @user.update_attributes(params[:user])
flash[:notice] = "Successfully updated profile."
redirect_to root_url
@@ -0,0 +1,2 @@
+module AdminHelper
+end
View
@@ -0,0 +1,12 @@
+class Admin < ActiveRecord::Base
+ acts_as_authentic do |c|
+ c.require_password_confirmation = false
+ c.validate_password_field = false
+ c.validate_login_field = false
+ c.validate_email_field = false
+ end
+
+
+ has_many :users
+
+end
@@ -0,0 +1,2 @@
+class AdminSession < Authlogic::Session::Base
+end
View
@@ -1,32 +1,38 @@
class Friendship < ActiveRecord::Base
+ belongs_to :user_1, :class_name => "User"
+ belongs_to :user_2, :class_name => "User"
+ after_save :clear_cache
- def friends_or_requested_or_pending?(user_1, user_2)
+
+ def self.friends_or_requested_or_pending?(user_1, user_2)
return true if friends?(user_1, user_2)
return true if requested_or_pending?(user_1, user_2)
false
end
- def requested_or_pending?(user_1, user_2)
+ def self.requested_or_pending?(user_1, user_2)
# return requested?(user_1, user_2) || pending?(user_1, user_2)
return true if find_by_user_1_id_and_user_2_id_and_status(user_1, user_2, "pending")
return true if find_by_user_1_id_and_user_2_id_and_status(user_1, user_2, "requested")
false
end
- def friends?(user_1, user_2)
+ def self.friends?(user_1, user_2)
find_by_user_1_id_and_user_2_id_and_status(user_1, user_2, "accepted")
end
- def request(user_1, user_2)
+ def self.request(user_1, user_2)
return false if user_1 == user_2 || friends_or_requested_or_pending?(user_1, user_2)
transaction do
- create! :user_1 => user_1, :user_2 => user_2, :status => "pending", :notifications => true
- create! :user_1 => user_2, :user_2 => user_1, :status => "requested", :notifications => true
+ create! :user_1 => user_1, :user_2 => user_2, :status => "pending"
+ create! :user_1 => user_2, :user_2 => user_1, :status => "requested"
end
return true
end
- def accept(user_1, user_2, options = {})
+
+
+ def self.accept(user_1, user_2, options = {})
f1 = find_by_user_1_id_and_user_2_id_and_status(user_1, user_2, "requested")
f2 = find_by_user_1_id_and_user_2_id_and_status(user_2, user_1, "pending")
return false if f1.nil? or f2.nil?
@@ -37,7 +43,7 @@ def accept(user_1, user_2, options = {})
return true
end
- def reject(user_1, user_2)
+ def self.reject(user_1, user_2)
f1 = find_all_by_user_1_id_and_user_2_id(user_1, user_2)
f2 = find_all_by_user_1_id_and_user_2_id(user_2, user_1)
return false unless f1.any? && f2.any?
@@ -49,7 +55,30 @@ def reject(user_1, user_2)
end
+ # don't use in production app
+ def self.create_arbitrary_friendship(user_1, user_2)
+ return if user_1 == user_2
+ return true if find_by_user_1_id_and_user_2_id_and_status(user_1, user_2, "accepted") && find_by_user_1_id_and_user_2_id_and_status(user_2, user_1, "accepted")
+ transaction do
+ create! :user_1 => user_1, :user_2 => user_2, :status => "accepted"
+ create! :user_1 => user_2, :user_2 => user_1, :status => "accepted"
+ end
+ end
+ # don't use in production app
+ def self.destroy_arbitrary_friendship(user_1, user_2)
+ f1 = find_by_user_1_id_and_user_2_id(user_1, user_2)
+ f2 = find_by_user_1_id_and_user_2_id(user_2, user_1)
+ f1.clear_cache and f1.delete if f1.present?
+ f2.clear_cache and f2.delete if f2.present?
+ end
+
+
+
+ def clear_cache
+ CACHE.delete(User.friends_key(user_1_id)) rescue Memcached::NotFound
+ CACHE.delete(User.friends_key(user_2_id)) rescue Memcached::NotFound
+ end
end
Oops, something went wrong.

0 comments on commit 442d473

Please sign in to comment.