Skip to content

Commit

Permalink
Changed /feeds to /subscriptions
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:hotsh/rstat.us

Conflicts:
	Gemfile.lock
  • Loading branch information
wilkie committed Mar 22, 2011
2 parents 7ca9565 + 91b73f8 commit 8fee4bb
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GEM
oa-oauth (= 0.2.0)
oa-openid (= 0.2.0)
opub (0.0.1)
ostatus (0.0.5)
ostatus (0.0.6)
nokogiri
oauth
tinyatom
Expand Down
6 changes: 2 additions & 4 deletions models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@ def self.create_from_hash(hsh, base_uri, user = nil)
:provider => hsh['provider']
)

unless a.save
redirect "/"
end

a.save
a.errors.each{|e| puts e.inspect }
a
end

Expand Down
3 changes: 3 additions & 0 deletions public/css/internal.css
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,9 @@ form#update-form #update-info.negative #update-count {
border-right: 1px solid #ddd;
margin-right: 40px;
}
#login #username, #login #password, #signup input[type="text"] {
width: 200px;
}
#login-other {
margin-top: 2em;
border-top: 1px solid #ddd;
Expand Down
9 changes: 8 additions & 1 deletion public/css/internal.less
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ form#update-form {
#login {
border-right: 1px solid #ddd;
margin-right: 40px;
#username, #password {
width: 200px;
}
}

#signup input[type="test"] {
width: 200px;
}

#login-other {
Expand All @@ -245,4 +252,4 @@ form#update-form {
.negative {
.button:hover, a.button:hover { color: #FFFFFF; background-position: 0 -121px; background-color: #D84743; border-color: #911D1B; }
color: red;
}
}
6 changes: 3 additions & 3 deletions public/css/update.css
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ body {
}
.avatar {
float: left;
width: 35px;
height: 35px;
width: 18px;
height: 18px;
padding-right: 1em;
}
.avatar img {
width: 35px;
width: 18px;
}
/* Footer */
#footer {
Expand Down
60 changes: 56 additions & 4 deletions rstatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,27 @@ class Rstatus < Sinatra::Base
get '/auth/:provider/callback' do
auth = request.env['omniauth.auth']
unless @auth = Authorization.find_from_hash(auth)
@auth = Authorization.create_from_hash(auth, uri("/"), current_user)
if User.first :username => auth['user_info']['nickname']
#we have a username conflict!

#let's store their oauth stuff so they don't have to re-login after
session[:oauth_token] = auth['credentials']['token']
session[:oauth_secret] = auth['credentials']['secret']

session[:uid] = auth['uid']
session[:provider] = auth['provider']
session[:name] = auth['user_info']['name']
session[:nickname] = auth['user_info']['nickname']
session[:website] = auth['user_info']['urls']['Website']
session[:description] = auth['user_info']['description']
session[:image] = auth['user_info']['image']

flash[:notice] = "Sorry, someone has that name."
redirect '/users/new'
return
else
@auth = Authorization.create_from_hash(auth, uri("/"), current_user)
end
end

session[:oauth_token] = auth['credentials']['token']
Expand All @@ -158,6 +178,38 @@ class Rstatus < Sinatra::Base
redirect '/'
end

get '/users/new' do
haml :"users/new"
end

post '/users' do
user = User.new params
if user.save
user.finalize("http://rstat.us") #uuuuuuuuugh

#this is really stupid.
auth = {}
auth['uid'] = session[:uid]
auth['provider'] = session[:provider]
auth['user_info'] = {}
auth['user_info']['name'] = session[:name]
auth['user_info']['nickname'] = session[:nickname]
auth['user_info']['urls'] = {}
auth['user_info']['urls']['Website'] = session[:website]
auth['user_info']['description'] = session[:description]
auth['user_info']['image'] = session[:image]

Authorization.create_from_hash(auth, uri("/"), user)

flash[:notice] = "Thanks! You're all signed up with #{user.username} for your username."
session[:user_id] = user.id
redirect '/'
else
flash[:notice] = "Oops! That username was taken. Pick another?"
redirect '/users/new'
end
end

get "/logout" do
session[:user_id] = nil
flash[:notice] = "You've been logged out."
Expand All @@ -178,9 +230,9 @@ class Rstatus < Sinatra::Base
feed.update_entries(request.body.read, request.url, request.env['HTTP_X_HUB_SIGNATURE'])
end

# Terrible
# unsubscribe from a feed
delete '/subscriptions/:id' do
require_login! :return => "/feeds/#{params[:id]}/unsubscribe"
require_login! :return => "/subscriptions/#{params[:id]}"

feed = Feed.first :id => params[:id]

Expand All @@ -201,7 +253,7 @@ class Rstatus < Sinatra::Base
redirect "/"
end

post "/feeds" do
post "/subscriptions" do
feed_url = params[:url]

f = current_user.follow! feed_url
Expand Down
15 changes: 15 additions & 0 deletions test/rstatus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,20 @@ def test_user_update_profile
assert_match page.body, /#{bio_text}/
end

def test_username_clash
existing_user = Factory(:user, :username => "taken")
new_user = Factory.build(:user, :username => 'taken')

old_count = User.count
log_in(new_user)
assert_match /users\/new/, page.current_url, "not on the new user page."
fill_in "username", :with => "nottaken"
click_button "Finish Signup"

assert_match /Thanks! You're all signed up with nottaken for your username./, page.body
assert_match /\//, page.current_url

end

end

2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def teardown
DatabaseCleaner.clean
end

def log_in(u, uid)
def log_in(u, uid = 12345)
OmniAuth.config.add_mock(:twitter, {
:uid => uid,
:user_info => {
Expand Down
2 changes: 1 addition & 1 deletion views/external_subscription.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
%img{:src=>"images/identica.png"}

#follow-form
%form{:action => "/feeds", :method => "POST"}
%form{:action => "/subscriptions", :method => "POST"}
%input{:type => "text", :name => "url"}
%input{:type => "submit", :value => "Follow"}
9 changes: 9 additions & 0 deletions views/users/new.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%h2 Pick a new username

%p Hey, we're sorry about this, but someone already has your username. Mind picking a new one?

%form{:action => "/users", :method => "POST"}
Username:
%input{:type => "text", :name => "username"}
%br/
%input{:type => "submit", :value => "Finish Signup"}

0 comments on commit 8fee4bb

Please sign in to comment.