Skip to content

Commit 0ec515b

Browse files
committed
login and signup are working
1 parent 67f667e commit 0ec515b

14 files changed

Lines changed: 838 additions & 200 deletions

File tree

Gemfile

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1+
#The first part of any Gemfile is to list sources.
2+
#Most gems are located at rubygems.org
13
source "http://rubygems.org"
24

3-
gem "sinatra"
4-
gem "haml"
5+
#after that, we use the 'gem' statement to list what gems we want to use.
6+
#we can also add version requirements so that we get the exact version.
7+
8+
#see more at http://gembundler.com/
9+
10+
gem "sinatra", "~>1.1"
11+
gem "haml", "~>3.0.18"
12+
gem "mongo_mapper", "~>0.8.4"
13+
gem "rack-flash", "~>0.1.1"
14+
gem "rdiscount", "~>1.6.5"
15+
gem "i18n", "~>0.4.1"
16+
gem "bson_ext", "~>1.1"
17+
gem "pony", "~>1.0.1"
518
gem "sinatra-content-for"
19+
20+
group :test do
21+
gem "launchy", "~>0.3.7"
22+
gem "autotest", "~>4.3.2"
23+
gem "capybara", "~>0.3.9"
24+
gem "factory_girl", "~>1.3.2"
25+
gem "database_cleaner", "~>0.6.0"
26+
gem "rspec", "~>2.1.0"
27+
gem "webrat", "~>0.7.1"
28+
gem "steak", "~>1.0.0"
29+
30+
gem "ruby-debug"
31+
end
32+

Gemfile.lock

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,114 @@
11
GEM
22
remote: http://rubygems.org/
33
specs:
4+
activesupport (3.0.3)
5+
autotest (4.3.2)
6+
bson (1.1.2)
7+
bson_ext (1.1.2)
8+
capybara (0.3.9)
9+
culerity (>= 0.2.4)
10+
mime-types (>= 1.16)
11+
nokogiri (>= 1.3.3)
12+
rack (>= 1.0.0)
13+
rack-test (>= 0.5.4)
14+
selenium-webdriver (>= 0.0.3)
15+
childprocess (0.1.4)
16+
ffi (~> 0.6.3)
17+
columnize (0.3.2)
18+
configuration (1.2.0)
19+
culerity (0.2.12)
20+
database_cleaner (0.6.0)
21+
diff-lcs (1.1.2)
22+
factory_girl (1.3.2)
23+
ffi (0.6.3)
24+
rake (>= 0.8.7)
425
haml (3.0.25)
26+
i18n (0.4.2)
27+
jnunemaker-validatable (1.8.4)
28+
activesupport (>= 2.3.4)
29+
json_pure (1.4.6)
30+
launchy (0.3.7)
31+
configuration (>= 0.0.5)
32+
rake (>= 0.8.1)
33+
linecache (0.43)
34+
mail (2.2.10)
35+
activesupport (>= 2.3.6)
36+
i18n (~> 0.4.1)
37+
mime-types (~> 1.16)
38+
treetop (~> 1.4.8)
39+
mime-types (1.16)
40+
mongo (1.1.2)
41+
bson (>= 1.1.1)
42+
mongo_mapper (0.8.6)
43+
activesupport (>= 2.3.4)
44+
jnunemaker-validatable (~> 1.8.4)
45+
plucky (~> 0.3.6)
46+
nokogiri (1.4.4)
47+
plucky (0.3.6)
48+
mongo (~> 1.1)
49+
polyglot (0.3.1)
50+
pony (1.0.1)
51+
mail (> 2.0)
552
rack (1.2.1)
53+
rack-flash (0.1.1)
54+
rack
55+
rack-test (0.5.6)
56+
rack (>= 1.0)
57+
rake (0.8.7)
58+
rdiscount (1.6.5)
59+
rspec (2.1.0)
60+
rspec-core (~> 2.1.0)
61+
rspec-expectations (~> 2.1.0)
62+
rspec-mocks (~> 2.1.0)
63+
rspec-core (2.1.0)
64+
rspec-expectations (2.1.0)
65+
diff-lcs (~> 1.1.2)
66+
rspec-mocks (2.1.0)
67+
ruby-debug (0.10.4)
68+
columnize (>= 0.1)
69+
ruby-debug-base (~> 0.10.4.0)
70+
ruby-debug-base (0.10.4)
71+
linecache (>= 0.3)
72+
rubyzip (0.9.4)
73+
selenium-webdriver (0.1.0)
74+
childprocess (= 0.1.4)
75+
ffi (~> 0.6.3)
76+
json_pure
77+
rubyzip
678
sinatra (1.1.0)
779
rack (~> 1.1)
880
tilt (~> 1.1)
981
sinatra-content-for (0.2)
1082
sinatra
83+
steak (1.0.0)
84+
rspec
1185
tilt (1.1)
86+
treetop (1.4.9)
87+
polyglot (>= 0.3.1)
88+
webrat (0.7.2)
89+
nokogiri (>= 1.2.0)
90+
rack (>= 1.0)
91+
rack-test (>= 0.5.3)
1292

1393
PLATFORMS
1494
ruby
1595

1696
DEPENDENCIES
17-
haml
18-
sinatra
97+
autotest (~> 4.3.2)
98+
bson_ext (~> 1.1)
99+
capybara (~> 0.3.9)
100+
database_cleaner (~> 0.6.0)
101+
factory_girl (~> 1.3.2)
102+
haml (~> 3.0.18)
103+
i18n (~> 0.4.1)
104+
launchy (~> 0.3.7)
105+
mongo_mapper (~> 0.8.4)
106+
pony (~> 1.0.1)
107+
rack-flash (~> 0.1.1)
108+
rdiscount (~> 1.6.5)
109+
rspec (~> 2.1.0)
110+
ruby-debug
111+
sinatra (~> 1.1)
19112
sinatra-content-for
113+
steak (~> 1.0.0)
114+
webrat (~> 0.7.1)

app.rb

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,80 @@
11
#!/usr/bin/env ruby
22
# encoding: utf-8
33

4+
#first off, we need to include rubygems and sinatra
5+
require 'rubygems'
6+
7+
#this bundler stuff needed for heroku
8+
require 'bundler'
9+
Bundler.setup
10+
411
require 'sinatra'
12+
13+
#this lets us send emails
14+
require 'pony'
15+
16+
#haml gives us all of our templates
517
require 'haml'
6-
require 'sass'
18+
19+
#mongomapper connects us to our database
20+
require 'mongo_mapper'
21+
22+
#rack-flash gives us nice flash messages
23+
require 'rack-flash'
24+
25+
#rdiscount lets us write things using markdown
26+
require 'rdiscount'
27+
28+
#we need to set up a secret to encrypt our sessions with
29+
use Rack::Session::Cookie, :secret => 'h4ck3ty h4ck f0r gr347 g00d'
30+
31+
#we also have to let the world know we want to use flashes
32+
use Rack::Flash
33+
734
require 'sinatra/content_for'
835

9-
set :port, 9000
36+
require 'helpers'
37+
38+
#this makes Haml escape any html by default. See here: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options
39+
set :haml, :escape_html => true
40+
41+
#these configure blocks only run in one environment
42+
configure :test do
43+
PONY_VIA_OPTIONS = {}
44+
end
45+
46+
configure :development do
47+
PONY_VIA_OPTIONS = {}
48+
end
49+
50+
configure :production do
51+
52+
PONY_VIA_OPTIONS = {
53+
:address => "smtp.sendgrid.net",
54+
:port => "25",
55+
:authentication => :plain,
56+
:user_name => ENV['SENDGRID_USERNAME'],
57+
:password => ENV['SENDGRID_PASSWORD'],
58+
:domain => ENV['SENDGRID_DOMAIN']
59+
}
60+
61+
end
62+
63+
#for all environments,
64+
configure do
65+
if ENV['MONGOHQ_URL']
66+
MongoMapper.config = {ENV['RACK_ENV'] => {'uri' => ENV['MONGOHQ_URL']}}
67+
MongoMapper.database = ENV['MONGOHQ_DATABASE']
68+
MongoMapper.connect("production")
69+
else
70+
MongoMapper.connection = Mongo::Connection.new('localhost')
71+
MongoMapper.database = "hackety-development"
72+
end
73+
#require all of our models!
74+
require_directory "models"
75+
end
76+
77+
require_directory "controllers"
1078

1179
get '/' do
1280
haml :index
@@ -20,6 +88,6 @@
2088
haml :download
2189
end
2290

23-
get '/feed' do
24-
haml :feed
91+
get '/stream' do
92+
haml :stream
2593
end

controllers/hackers.rb

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#This is the 'hackers' controller. "Hackers" are what we call "Users" in HH.
2+
3+
# An individual Hacker's page
4+
get '/hackers/:name' do
5+
#find the hacker with the given name
6+
@hacker = Hacker.first(:username => params[:name])
7+
8+
#render the template
9+
haml :"hackers/show"
10+
end
11+
12+
#update a hacker's information
13+
post '/hackers/update' do
14+
#you have to be logged in to update your info
15+
require_login! :return => "/hackers/update"
16+
17+
#do they want to update their password
18+
unless params[:password].nil?
19+
if params[:password][:new] == params[:password][:confirm]
20+
current_user.password = params[:password][:new]
21+
current_user.save
22+
flash[:notice] = "Password updated!"
23+
else
24+
flash[:notice] = "Password confirmation didn't match!"
25+
end
26+
else
27+
current_user.update_attributes(:about => params[:hacker][:about])
28+
current_user.save
29+
flash[:notice] = "About information updated!"
30+
end
31+
32+
redirect "/hackers/#{current_user.username}"
33+
34+
end
35+
36+
#this lets you follow a Hacker
37+
get '/hackers/:name/follow' do
38+
#we have to be logged in to follow someone
39+
require_login! :return => "/hackers/#{params[:name]}/follow"
40+
41+
#find the hacker with the given name
42+
@hacker = Hacker.first(:username => params[:name])
43+
44+
#make sure we're not following them already
45+
if current_user.following? @hacker
46+
flash[:notice] = "You're already following #{params[:name]}."
47+
redirect "/hackers/#{current_user.username}"
48+
return
49+
end
50+
51+
#follow them!
52+
current_user.follow! @hacker
53+
54+
#set a message
55+
flash[:notice] = "Now following #{params[:name]}."
56+
57+
#redirect back to your page!
58+
redirect "/hackers/#{current_user.username}"
59+
60+
end
61+
62+
#this lets you unfollow a Hacker
63+
get '/hackers/:name/unfollow' do
64+
#we have to be logged in to unfollow someone
65+
require_login! :return => "/hackers/#{params[:name]}/unfollow"
66+
67+
#find the hacker with the given name
68+
@hacker = Hacker.first(:username => params[:name])
69+
70+
#make sure we're not following them already
71+
unless current_user.following? @hacker
72+
flash[:notice] = "You're already not following #{params[:name]}."
73+
redirect "/hackers/#{current_user.username}"
74+
return
75+
end
76+
77+
#unfollow them!
78+
current_user.unfollow! @hacker
79+
80+
#set a message
81+
flash[:notice] = "No longer following #{params[:name]}."
82+
83+
#redirect back to your page!
84+
redirect "/hackers/#{current_user.username}"
85+
86+
end
87+
88+
#this lets us see followers
89+
get '/hackers/:name/followers' do
90+
#find the hacker with the given name
91+
@hacker = Hacker.first(:username => params[:name])
92+
93+
#render our page
94+
haml :"hackers/followers"
95+
end
96+
97+
#this lets us see following
98+
get '/hackers/:name/following' do
99+
#find the hacker with the given name
100+
@hacker = Hacker.first(:username => params[:name])
101+
102+
#render our page
103+
haml :"hackers/following"
104+
end
105+

0 commit comments

Comments
 (0)